@@ -52,11 +52,62 @@ local function update_lightbulb(bufnr, row)
5252 inrender_buf = bufnr
5353end
5454
55+ local function severity_vim_to_lsp (severity )
56+ if type (severity ) == ' string' then
57+ severity = vim .diagnostic .severity [severity ]
58+ end
59+ return severity
60+ end
61+
62+ --- @param diagnostic vim.Diagnostic
63+ --- @return lsp.DiagnosticTag[] ?
64+ local function tags_vim_to_lsp (diagnostic )
65+ if not diagnostic ._tags then
66+ return
67+ end
68+
69+ local tags = {} --- @type lsp.DiagnosticTag[]
70+ if diagnostic ._tags .unnecessary then
71+ tags [# tags + 1 ] = vim .lsp .protocol .DiagnosticTag .Unnecessary
72+ end
73+ if diagnostic ._tags .deprecated then
74+ tags [# tags + 1 ] = vim .lsp .protocol .DiagnosticTag .Deprecated
75+ end
76+ return tags
77+ end
78+ local function diagnostic_vim_to_lsp (diagnostics )
79+ --- @param diagnostic vim.Diagnostic
80+ --- @return lsp.Diagnostic
81+ return vim .tbl_map (function (diagnostic )
82+ local user_data = diagnostic .user_data or {}
83+ if user_data .lsp then
84+ return user_data .lsp
85+ end
86+ return {
87+ range = {
88+ start = {
89+ line = diagnostic .lnum ,
90+ character = diagnostic .col ,
91+ },
92+ [' end' ] = {
93+ line = diagnostic .end_lnum ,
94+ character = diagnostic .end_col ,
95+ },
96+ },
97+ severity = severity_vim_to_lsp (diagnostic .severity ),
98+ message = diagnostic .message ,
99+ source = diagnostic .source ,
100+ code = diagnostic .code ,
101+ tags = tags_vim_to_lsp (diagnostic ),
102+ }
103+ end , diagnostics )
104+ end
105+
55106local function render (bufnr )
56107 local row = api .nvim_win_get_cursor (0 )[1 ] - 1
57108 local params = lsp .util .make_range_params ()
58109 params .context = {
59- diagnostics = vim .diagnostic .get (bufnr , { lnum = row + 1 }),
110+ diagnostics = diagnostic_vim_to_lsp ( vim .diagnostic .get (bufnr , { lnum = row + 1 }) ),
60111 }
61112
62113 lsp .buf_request (bufnr , ' textDocument/codeAction' , params , function (_ , result , _ )
0 commit comments