aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/diagnostic.lua
diff options
context:
space:
mode:
authorMathias Fußenegger <mfussenegger@users.noreply.github.com>2023-10-14 09:47:20 +0200
committerGitHub <noreply@github.com>2023-10-14 09:47:20 +0200
commit712adacdf546fbaccd9f2134534889a3f6f36dbc (patch)
tree2884bc9dbd706d25392fc0da88a1a864a82f9157 /runtime/lua/vim/lsp/diagnostic.lua
parentee156ca60ede95c95160cb8dff0197d40cb1a491 (diff)
downloadrneovim-712adacdf546fbaccd9f2134534889a3f6f36dbc.tar.gz
rneovim-712adacdf546fbaccd9f2134534889a3f6f36dbc.tar.bz2
rneovim-712adacdf546fbaccd9f2134534889a3f6f36dbc.zip
refactor(lsp): make is_pull in lsp.diagnostic.get_namespace optional (#25156)
Follw up to https://github.com/neovim/neovim/commit/63b3408551561127f7845470eb51404bcd6f547b `is_pull` should be optional, otherwise it is an API change that introduces warnings in consumers. Also fixes the type annotation of `_client_pull_namespaces` where the key is a string.
Diffstat (limited to 'runtime/lua/vim/lsp/diagnostic.lua')
-rw-r--r--runtime/lua/vim/lsp/diagnostic.lua41
1 files changed, 21 insertions, 20 deletions
diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua
index 73ffa1a46c..73444d8c6a 100644
--- a/runtime/lua/vim/lsp/diagnostic.lua
+++ b/runtime/lua/vim/lsp/diagnostic.lua
@@ -159,44 +159,45 @@ local function diagnostic_vim_to_lsp(diagnostics)
end, diagnostics)
end
----@type table<integer,integer>
+---@type table<integer, integer>
local _client_push_namespaces = {}
----@type table<integer,integer>
+
+---@type table<string, integer>
local _client_pull_namespaces = {}
--- Get the diagnostic namespace associated with an LSP client |vim.diagnostic| for diagnostics
---
---@param client_id integer The id of the LSP client
----@param is_pull boolean Whether the namespace is for a pull or push client
+---@param is_pull boolean? Whether the namespace is for a pull or push client. Defaults to push
function M.get_namespace(client_id, is_pull)
vim.validate({ client_id = { client_id, 'n' } })
- local namespace_table
- local key
- local name
local client = vim.lsp.get_client_by_id(client_id)
-
if is_pull then
- namespace_table = _client_pull_namespaces
- local server_id = vim.tbl_get(client.server_capabilities, 'diagnosticProvider', 'identifier')
- key = string.format('%d:%s', client_id, server_id or 'nil')
- name = string.format(
+ local server_id =
+ vim.tbl_get((client or {}).server_capabilities, 'diagnosticProvider', 'identifier')
+ local key = string.format('%d:%s', client_id, server_id or 'nil')
+ local name = string.format(
'vim.lsp.%s.%d.%s',
client and client.name or 'unknown',
client_id,
server_id or 'nil'
)
+ local ns = _client_pull_namespaces[key]
+ if not ns then
+ ns = api.nvim_create_namespace(name)
+ _client_pull_namespaces[key] = ns
+ end
+ return ns
else
- namespace_table = _client_push_namespaces
- key = client_id
- name = string.format('vim.lsp.%s.%d', client and client.name or 'unknown', client_id)
- end
-
- if not namespace_table[key] then
- namespace_table[key] = api.nvim_create_namespace(name)
+ local name = string.format('vim.lsp.%s.%d', client and client.name or 'unknown', client_id)
+ local ns = _client_push_namespaces[client_id]
+ if not ns then
+ ns = api.nvim_create_namespace(name)
+ _client_push_namespaces[client_id] = ns
+ end
+ return ns
end
-
- return namespace_table[key]
end
--- |lsp-handler| for the method "textDocument/publishDiagnostics"