diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index 6a8c3d1ff3..5a93da4298 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -211,7 +211,7 @@ local function reuse_client_default(client, config) for _, config_folder in ipairs(config_folders) do local found = false - for _, client_folder in ipairs(client.workspace_folders) do + for _, client_folder in ipairs(client.workspace_folders or {}) do if config_folder.uri == client_folder.uri then found = true break diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index d2ef166983..1f246b0914 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -1854,6 +1854,20 @@ describe('LSP', function() end, } end) + + it('vim.lsp.start when existing client has no workspace_folders', function() + exec_lua(create_server_definition) + eq( + { 2, 'foo', 'foo' }, + exec_lua(function() + local server = _G._create_server() + vim.lsp.start { cmd = server.cmd, name = 'foo' } + vim.lsp.start { cmd = server.cmd, name = 'foo', root_dir = 'bar' } + local foos = vim.lsp.get_clients() + return { #foos, foos[1].name, foos[2].name } + end) + ) + end) end) describe('parsing tests', function()