fix(lsp): only send diagnostics from current buffer in code_action() (#18639)

Fix vim.lsp.buf.(range_)code_action() to only send diagnostics belonging
to the current buffer and not to other files in the workspace.
This commit is contained in:
Fredrik Ekre 2022-05-20 13:11:23 +02:00 committed by GitHub
parent eb0aa8bb0e
commit a4862cbb5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -863,7 +863,8 @@ function M.code_action(options)
end
local context = options.context or {}
if not context.diagnostics then
context.diagnostics = vim.lsp.diagnostic.get_line_diagnostics()
local bufnr = vim.api.nvim_get_current_buf()
context.diagnostics = vim.lsp.diagnostic.get_line_diagnostics(bufnr)
end
local params = util.make_range_params()
params.context = context
@ -889,7 +890,8 @@ function M.range_code_action(context, start_pos, end_pos)
validate({ context = { context, 't', true } })
context = context or {}
if not context.diagnostics then
context.diagnostics = vim.lsp.diagnostic.get_line_diagnostics()
local bufnr = vim.api.nvim_get_current_buf()
context.diagnostics = vim.lsp.diagnostic.get_line_diagnostics(bufnr)
end
local params = util.make_given_range_params(start_pos, end_pos)
params.context = context