From cb1b4bbeae882cc983929258a8192ce034064bf7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 21 May 2022 16:02:38 +0200 Subject: [PATCH] fix(lsp): only send diagnostics from current buffer in code_action() (#18655) Fix vim.lsp.buf.(range_)code_action() to only send diagnostics belonging to the current buffer and not to other files in the workspace. (cherry picked from commit e3d660e4563c32d25a5f1f2ed79c47b0fc088c35) Co-authored-by: Fredrik Ekre --- runtime/lua/vim/lsp/buf.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua index eb7ec579f1..cbaa042214 100644 --- a/runtime/lua/vim/lsp/buf.lua +++ b/runtime/lua/vim/lsp/buf.lua @@ -595,7 +595,8 @@ function M.code_action(context) 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_range_params() params.context = context @@ -621,7 +622,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