nvim: lsp: Fix use of diagnostic API
With get_line_diagnostics being deprecated we switched to
vim.diagnostic.get but vim diagnostics are different from
LSP diagnostics and need to be converted.
We copy the code from get_line_diagnostics here as that
will be dropped in 0.12. Strangely the issue only kept
coming up with ruff/Python and HLS/Haskell.
This fixes commit ef0daa5d4
which broke code action
light bulb functionality.
This commit is contained in:
parent
fffb2c06bc
commit
24cd59f124
1 changed files with 14 additions and 7 deletions
|
@ -183,7 +183,7 @@ local client_custom_cleanup = function(client, bufnr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local on_attach = function(client, bufnr)
|
local on_attach = function(client_id, client, bufnr)
|
||||||
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
|
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
|
||||||
|
|
||||||
if client.config.flags then
|
if client.config.flags then
|
||||||
|
@ -207,11 +207,18 @@ local on_attach = function(client, bufnr)
|
||||||
group = lsp_augroup_id,
|
group = lsp_augroup_id,
|
||||||
buffer = bufnr,
|
buffer = bufnr,
|
||||||
callback = function()
|
callback = function()
|
||||||
-- Taken from https://github.com/neovim/nvim-lspconfig/wiki/Code-Actions
|
-- Adapted from https://github.com/neovim/nvim-lspconfig/wiki/Code-Actions
|
||||||
local context = { diagnostics = vim.diagnostic.get(bufnr) }
|
-- Copied from deprecated vim.lsp.diagnostic.get_line_diagnostics()
|
||||||
local params = lsp_util.make_range_params()
|
local diag_opts = {} --- @type vim.diagnostic.GetOpts
|
||||||
params.context = context
|
diag_opts.namespace = vim.lsp.diagnostic.get_namespace(client_id)
|
||||||
vim.lsp.buf_request(0, 'textDocument/codeAction', params, function(err, result, ctx, config)
|
diag_opts.lnum = vim.api.nvim_win_get_cursor(0)[1] - 1
|
||||||
|
|
||||||
|
local lsp_diagnostics = vim.lsp.diagnostic.from(vim.diagnostic.get(bufnr, diag_opts))
|
||||||
|
local context = { diagnostics = lsp_diagnostics }
|
||||||
|
local params = lsp_util.make_range_params()
|
||||||
|
params.context = context
|
||||||
|
|
||||||
|
vim.lsp.buf_request(bufnr, 'textDocument/codeAction', params, function(err, result, ctx, config)
|
||||||
if result and not vim.tbl_isempty(result) then
|
if result and not vim.tbl_isempty(result) then
|
||||||
local line = params.range.start.line
|
local line = params.range.start.line
|
||||||
code_action_update_sign(vim.b.code_action_line, line + 1, bufnr)
|
code_action_update_sign(vim.b.code_action_line, line + 1, bufnr)
|
||||||
|
@ -268,7 +275,7 @@ vim.api.nvim_create_autocmd("LspAttach", {
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
on_attach(client, bufnr)
|
on_attach(args.data.client_id, client, bufnr)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue