fix(lsp): clear lsp client diagnostics (#29091)

Problem: When an lsp client is stopped, the client will
only clear the diagnostics for the attached buffers but
not the unattached buffers.
Solution: Reset the diagnostics for the whole namespace rather than
for only the attached buffers.

(cherry picked from commit 025c874415)

Co-authored-by: crwebb85 <51029315+crwebb85@users.noreply.github.com>
This commit is contained in:
github-actions[bot]
2024-05-30 09:23:04 +02:00
committed by GitHub
parent 89fa1ee822
commit d8ff216040

View File

@ -387,8 +387,8 @@ end
local function on_client_exit(code, signal, client_id)
local client = all_clients[client_id]
for bufnr in pairs(client.attached_buffers) do
vim.schedule(function()
vim.schedule(function()
for bufnr in pairs(client.attached_buffers) do
if client and client.attached_buffers[bufnr] then
api.nvim_exec_autocmds('LspDetach', {
buffer = bufnr,
@ -397,15 +397,16 @@ local function on_client_exit(code, signal, client_id)
})
end
local namespace = vim.lsp.diagnostic.get_namespace(client_id)
vim.diagnostic.reset(namespace, bufnr)
client.attached_buffers[bufnr] = nil
if #lsp.get_clients({ bufnr = bufnr, _uninitialized = true }) == 0 then
reset_defaults(bufnr)
end
end)
end
end
local namespace = vim.lsp.diagnostic.get_namespace(client_id)
vim.diagnostic.reset(namespace)
end)
local name = client.name or 'unknown'