aboutsummaryrefslogtreecommitdiffstats
path: root/lua/lspconfig/util.lua
diff options
context:
space:
mode:
authorRaphael <glepnir@neovim.pro>2022-12-11 19:25:44 +0800
committerGitHub <noreply@github.com>2022-12-11 19:25:44 +0800
commit6eb24ef9175d1fa3c7a23e115854b1a2d923d386 (patch)
treed62431dbb0e480ef8fa0caac0d57f1cdacf321cf /lua/lspconfig/util.lua
parentfix: check client is available and get client id from cache (#2303) (diff)
downloadnvim-lspconfig-6eb24ef9175d1fa3c7a23e115854b1a2d923d386.tar
nvim-lspconfig-6eb24ef9175d1fa3c7a23e115854b1a2d923d386.tar.gz
nvim-lspconfig-6eb24ef9175d1fa3c7a23e115854b1a2d923d386.tar.bz2
nvim-lspconfig-6eb24ef9175d1fa3c7a23e115854b1a2d923d386.tar.lz
nvim-lspconfig-6eb24ef9175d1fa3c7a23e115854b1a2d923d386.tar.xz
nvim-lspconfig-6eb24ef9175d1fa3c7a23e115854b1a2d923d386.tar.zst
nvim-lspconfig-6eb24ef9175d1fa3c7a23e115854b1a2d923d386.zip
feat: support multiple workspaceFolders and show correct root in Lspinfo (#2304)
* feat: support multiple workspaceFolders and show correct root in Lspinfo * fix: add return branch * fix: convert path before compare * fix: improve find root dir in LspInfo * fix: check logic * fix: remove unnecessary code
Diffstat (limited to 'lua/lspconfig/util.lua')
-rw-r--r--lua/lspconfig/util.lua36
1 files changed, 26 insertions, 10 deletions
diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua
index d4390e40..f7614924 100644
--- a/lua/lspconfig/util.lua
+++ b/lua/lspconfig/util.lua
@@ -247,20 +247,36 @@ function M.server_per_root_dir_manager(make_config)
return
end
+ local get_client_from_cache = function(conf)
+ local id
+ if vim.tbl_count(clients) == 1 then
+ id = vim.tbl_values(clients)[1]
+ elseif vim.tbl_count(single_file_clients) == 1 then
+ id = vim.tbl_values(single_file_clients)[1]
+ else
+ return
+ end
+ local client = lsp.get_client_by_id(id)
+ if client and client.name == conf.name then
+ return client
+ end
+ return nil
+ end
+
-- Check if we have a client already or start and store it.
if not client_id then
local new_config = make_config(root_dir)
- if vim.tbl_count(clients) == 1 then
- local id = vim.tbl_values(clients)[1]
- local client = lsp.get_client_by_id(id)
- if client and client.name == new_config.name then
- local params = lsp.util.make_workspace_params(
- { { uri = vim.uri_from_fname(root_dir), name = root_dir } },
- { {} }
- )
- table.insert(client.workspace_folders, params.event.added[1])
- return id
+ local client = get_client_from_cache(new_config)
+ if client then
+ local params = lsp.util.make_workspace_params(
+ { { uri = vim.uri_from_fname(root_dir), name = root_dir } },
+ { {} }
+ )
+ if not client.workspace_folders then
+ client.workspace_folders = {}
end
+ table.insert(client.workspace_folders, params.event.added[1])
+ return client.id
end
-- do nothing if the client is not enabled
if new_config.enabled == false then