aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Rozdzialik <voreny.gelio@gmail.com>2024-08-07 17:28:01 +0200
committerGitHub <noreply@github.com>2024-08-07 17:28:01 +0200
commit7031949be065870f0daf74a9f1be3df47f83312c (patch)
tree0a67e67de699325d6ea4092ed5497659fb94c041
parent328ea02eb7dec32286ae6c691ecef71d988c905b (diff)
downloadrneovim-7031949be065870f0daf74a9f1be3df47f83312c.tar.gz
rneovim-7031949be065870f0daf74a9f1be3df47f83312c.tar.bz2
rneovim-7031949be065870f0daf74a9f1be3df47f83312c.zip
fix(lsp): avoid reusing diagnostics from different servers in actions (#30002)
Problem: When preparing the parameters for a code actions LSP request, the code set `context.diagnostics` when processing the first LSP client, and then reused those `context.diagnostics` for subsequent LSP clients. This meant that the second and next LSP clients got diagnostics that did not originate from them, and they did not get the diagnostics that they sent. Solution: Avoid setting `context.diagnostics` (which is referenced by all clients). Instead, set `params.context.diagnostics` directly, which is specific to a single client. Fixes #30001 Caused by #29501
-rw-r--r--runtime/lua/vim/lsp/buf.lua16
1 files changed, 10 insertions, 6 deletions
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua
index a512d48a06..d7463d74f8 100644
--- a/runtime/lua/vim/lsp/buf.lua
+++ b/runtime/lua/vim/lsp/buf.lua
@@ -897,19 +897,23 @@ function M.code_action(opts)
else
params = util.make_range_params(win, client.offset_encoding)
end
- if not context.diagnostics then
+ if context.diagnostics then
+ params.context = context
+ else
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)
+ params.context = vim.tbl_extend('force', context, {
+ ---@diagnostic disable-next-line: no-unknown
+ 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
end