runtime: Add vim.lsp.get_client_by_name (#11603)

Since the client name is more obvious than the client id for the user, add an
API to get the lsp client by the client name.
This commit is contained in:
Hirokazu Hata
2019-12-29 02:28:00 +09:00
committed by Ashkan Kiani
parent 4f4c06a7a4
commit 680693e263
3 changed files with 22 additions and 2 deletions

View File

@@ -697,6 +697,16 @@ function lsp.get_client_by_id(client_id)
return active_clients[client_id]
end
-- Look up an active client by its name, returns nil if it is not yet initialized
-- or is not a valid name.
-- @param client_name string the client name.
function lsp.get_client_by_name(client_name)
for _, client in pairs(active_clients) do
if client.name == client_name then return client end
end
return nil
end
-- Stop a client by its id, optionally with force.
-- You can also use the `stop()` function on a client if you already have
-- access to it.