From 9c20342297391c4076809964e799f2c7705b819b Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 13 Dec 2024 10:51:33 +0000 Subject: fix(lsp): reuse client if configs match and no root dir Problem: An LSP configuration that creates client with no root_dir or workspace_folders can result in vim.lsp.enable attaching to it multiple times. Solution: When checking existing clients, reuse a client if it wasn't initially configured have any workspace_folders. This more closely matches the behaviour we had prior to d9235ef --- runtime/lua/vim/lsp.lua | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'runtime/lua') diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index 596e1b609b..6a8c3d1ff3 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -201,23 +201,28 @@ local function reuse_client_default(client, config) end local config_folders = lsp._get_workspace_folders(config.workspace_folders or config.root_dir) - or {} - local config_folders_included = 0 - if not next(config_folders) then - return false + if not config_folders or not next(config_folders) then + -- Reuse if the client was configured with no workspace folders + local client_config_folders = + lsp._get_workspace_folders(client.config.workspace_folders or client.config.root_dir) + return not client_config_folders or not next(client_config_folders) end for _, config_folder in ipairs(config_folders) do + local found = false for _, client_folder in ipairs(client.workspace_folders) do if config_folder.uri == client_folder.uri then - config_folders_included = config_folders_included + 1 + found = true break end end + if not found then + return false + end end - return config_folders_included == #config_folders + return true end --- Reset defaults set by `set_defaults`. -- cgit