aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/buf.lua
diff options
context:
space:
mode:
authorMathias Fußenegger <mfussenegger@users.noreply.github.com>2024-08-01 16:01:15 +0200
committerGitHub <noreply@github.com>2024-08-01 16:01:15 +0200
commit720b309c786c4a258adccc9c468d433fb0f755b9 (patch)
treefd3f02f5fc9f8eccf8bb76d5ba1732bd789549fc /runtime/lua/vim/lsp/buf.lua
parent32e128f20992e350b3e39c7469baa1f692418203 (diff)
downloadrneovim-720b309c786c4a258adccc9c468d433fb0f755b9.tar.gz
rneovim-720b309c786c4a258adccc9c468d433fb0f755b9.tar.bz2
rneovim-720b309c786c4a258adccc9c468d433fb0f755b9.zip
fix(lsp): don't send foreign diagnostics to servers in buf.code_action (#29501)
`buf.code_action` always included diagnostics on a given line from all clients. Servers should only receive diagnostics they published, and in the exact same format they sent it. Should fix https://github.com/neovim/neovim/issues/29500
Diffstat (limited to 'runtime/lua/vim/lsp/buf.lua')
-rw-r--r--runtime/lua/vim/lsp/buf.lua18
1 files changed, 13 insertions, 5 deletions
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua
index f20730b8e6..a512d48a06 100644
--- a/runtime/lua/vim/lsp/buf.lua
+++ b/runtime/lua/vim/lsp/buf.lua
@@ -852,14 +852,10 @@ function M.code_action(opts)
if opts.diagnostics or opts.only then
opts = { options = opts }
end
- local context = opts.context or {}
+ local context = opts.context and vim.deepcopy(opts.context) or {}
if not context.triggerKind then
context.triggerKind = vim.lsp.protocol.CodeActionTriggerKind.Invoked
end
- if not context.diagnostics then
- local bufnr = api.nvim_get_current_buf()
- context.diagnostics = vim.lsp.diagnostic.get_line_diagnostics(bufnr)
- end
local mode = api.nvim_get_mode().mode
local bufnr = api.nvim_get_current_buf()
local win = api.nvim_get_current_win()
@@ -901,6 +897,18 @@ function M.code_action(opts)
else
params = util.make_range_params(win, client.offset_encoding)
end
+ if not context.diagnostics then
+ local ns_push = vim.lsp.diagnostic.get_namespace(client.id, false)
+ local ns_pull = vim.lsp.diagnostic.get_namespace(client.id, true)
+ local diagnostics = {}
+ local lnum = api.nvim_win_get_cursor(0)[1] - 1
+ vim.list_extend(diagnostics, vim.diagnostic.get(bufnr, { namespace = ns_pull, lnum = lnum }))
+ vim.list_extend(diagnostics, vim.diagnostic.get(bufnr, { namespace = ns_push, lnum = lnum }))
+ ---@diagnostic disable-next-line: no-unknown
+ context.diagnostics = vim.tbl_map(function(d)
+ return d.user_data.lsp
+ end, diagnostics)
+ end
params.context = context
client.request(ms.textDocument_codeAction, params, on_result, bufnr)
end