refactor(lsp): track clients in all_clients once initialized

This commit is contained in:
Yi Ming
2025-07-20 22:03:44 +08:00
parent 8f75c0b586
commit 5400df0f7f
2 changed files with 23 additions and 18 deletions

View File

@@ -6,6 +6,10 @@ local ms = lsp.protocol.Methods
local changetracking = lsp._changetracking
local validate = vim.validate
--- Tracks all clients initialized.
---@type table<integer,vim.lsp.Client>
local all_clients = {}
--- @alias vim.lsp.client.on_init_cb fun(client: vim.lsp.Client, init_result: lsp.InitializeResult)
--- @alias vim.lsp.client.on_attach_cb fun(client: vim.lsp.Client, bufnr: integer)
--- @alias vim.lsp.client.on_exit_cb fun(code: integer, signal: integer, client_id: integer)
@@ -493,6 +497,9 @@ end
--- @nodoc
function Client:initialize()
-- Register all initialized clients.
all_clients[self.id] = self
local config = self.config
local root_uri --- @type string?
@@ -1293,4 +1300,7 @@ function Client:_remove_workspace_folder(dir)
end
end
-- Export for internal use only.
Client._all = all_clients
return Client