fix(lightbulb): convert diagnostic to lsp fix #1478
This commit is contained in:
parent
508d01a3b0
commit
42eb7b26ee
|
@ -52,11 +52,62 @@ local function update_lightbulb(bufnr, row)
|
|||
inrender_buf = bufnr
|
||||
end
|
||||
|
||||
local function severity_vim_to_lsp(severity)
|
||||
if type(severity) == 'string' then
|
||||
severity = vim.diagnostic.severity[severity]
|
||||
end
|
||||
return severity
|
||||
end
|
||||
|
||||
--- @param diagnostic vim.Diagnostic
|
||||
--- @return lsp.DiagnosticTag[]?
|
||||
local function tags_vim_to_lsp(diagnostic)
|
||||
if not diagnostic._tags then
|
||||
return
|
||||
end
|
||||
|
||||
local tags = {} --- @type lsp.DiagnosticTag[]
|
||||
if diagnostic._tags.unnecessary then
|
||||
tags[#tags + 1] = vim.lsp.protocol.DiagnosticTag.Unnecessary
|
||||
end
|
||||
if diagnostic._tags.deprecated then
|
||||
tags[#tags + 1] = vim.lsp.protocol.DiagnosticTag.Deprecated
|
||||
end
|
||||
return tags
|
||||
end
|
||||
local function diagnostic_vim_to_lsp(diagnostics)
|
||||
---@param diagnostic vim.Diagnostic
|
||||
---@return lsp.Diagnostic
|
||||
return vim.tbl_map(function(diagnostic)
|
||||
local user_data = diagnostic.user_data or {}
|
||||
if user_data.lsp then
|
||||
return user_data.lsp
|
||||
end
|
||||
return {
|
||||
range = {
|
||||
start = {
|
||||
line = diagnostic.lnum,
|
||||
character = diagnostic.col,
|
||||
},
|
||||
['end'] = {
|
||||
line = diagnostic.end_lnum,
|
||||
character = diagnostic.end_col,
|
||||
},
|
||||
},
|
||||
severity = severity_vim_to_lsp(diagnostic.severity),
|
||||
message = diagnostic.message,
|
||||
source = diagnostic.source,
|
||||
code = diagnostic.code,
|
||||
tags = tags_vim_to_lsp(diagnostic),
|
||||
}
|
||||
end, diagnostics)
|
||||
end
|
||||
|
||||
local function render(bufnr)
|
||||
local row = api.nvim_win_get_cursor(0)[1] - 1
|
||||
local params = lsp.util.make_range_params()
|
||||
params.context = {
|
||||
diagnostics = vim.diagnostic.get(bufnr, { lnum = row + 1 }),
|
||||
diagnostics = diagnostic_vim_to_lsp(vim.diagnostic.get(bufnr, { lnum = row + 1 })),
|
||||
}
|
||||
|
||||
lsp.buf_request(bufnr, 'textDocument/codeAction', params, function(_, result, _)
|
||||
|
|
Loading…
Reference in New Issue