From 1fdbd29dfa6366f8346693d0bf67f4f782ab0f32 Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Fri, 5 Nov 2021 10:10:27 -0600 Subject: [PATCH] fix(diagnostic): handle an unknown or missing client (#16242) Sometimes plugins use pseudo-client IDs (e.g. nvim-lint or null-ls) in order to hook into the LSP infrastructure without being a bona fide LSP client. In these cases, get_client_by_id() will return nil since the client ID given does not correspond to a real client recognized by the LSP subsystem. When this happens, use "unknown" for the client name. --- runtime/lua/vim/lsp/diagnostic.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua index 6b856a52a5..1e6f83c1ba 100644 --- a/runtime/lua/vim/lsp/diagnostic.lua +++ b/runtime/lua/vim/lsp/diagnostic.lua @@ -147,7 +147,7 @@ function M.get_namespace(client_id) vim.validate { client_id = { client_id, 'n' } } if not _client_namespaces[client_id] then local client = vim.lsp.get_client_by_id(client_id) - local name = string.format("vim.lsp.%s.%d", client.name, client_id) + local name = string.format("vim.lsp.%s.%d", client and client.name or "unknown", client_id) _client_namespaces[client_id] = vim.api.nvim_create_namespace(name) end return _client_namespaces[client_id]