diff options
author | Lewis Russell <lewis6991@gmail.com> | 2024-12-13 10:51:33 +0000 |
---|---|---|
committer | Lewis Russell <me@lewisr.dev> | 2024-12-13 14:36:24 +0000 |
commit | 9c20342297391c4076809964e799f2c7705b819b (patch) | |
tree | 7cd408a979aae4da77cb993b6a60cc3cd624d307 /runtime | |
parent | 7940ec69136fa992c98aa7b37265fbc2e619232e (diff) | |
download | rneovim-9c20342297391c4076809964e799f2c7705b819b.tar.gz rneovim-9c20342297391c4076809964e799f2c7705b819b.tar.bz2 rneovim-9c20342297391c4076809964e799f2c7705b819b.zip |
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
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/lua/vim/lsp.lua | 17 |
1 files changed, 11 insertions, 6 deletions
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`. |