Skip to content

Commit 888a803

Browse files
authored
fix(lsp): vim.lsp.start fails if existing client has no workspace_folders neovim#31608
Problem: regression since neovim#31340 `nvim -l repro.lua`: ```lua vim.lsp.start { cmd = { 'lua-language-server' }, name = 'lua_ls' } vim.lsp.start { cmd = { 'lua-language-server' }, name = 'lua_ls', root_dir = 'foo' } -- swapped case will be ok: -- vim.lsp.start { cmd = { 'lua-language-server' }, name = 'lua_ls', root_dir = 'foo' } -- vim.lsp.start { cmd = { 'lua-language-server' }, name = 'lua_ls' } ``` Failure: ``` E5113: Error while calling lua chunk: /…/lua/vim/lsp.lua:214: bad argument #1 to 'ipairs' (table expected, got nil) stack traceback: [C]: in function 'ipairs' /…/lua/vim/lsp.lua:214: in function 'reuse_client' /…/lua/vim/lsp.lua:629: in function 'start' repro.lua:34: in main chunk ```
1 parent 07d5dc8 commit 888a803

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

runtime/lua/vim/lsp.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ local function reuse_client_default(client, config)
211211

212212
for _, config_folder in ipairs(config_folders) do
213213
local found = false
214-
for _, client_folder in ipairs(client.workspace_folders) do
214+
for _, client_folder in ipairs(client.workspace_folders or {}) do
215215
if config_folder.uri == client_folder.uri then
216216
found = true
217217
break

test/functional/plugin/lsp_spec.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,6 +1854,20 @@ describe('LSP', function()
18541854
end,
18551855
}
18561856
end)
1857+
1858+
it('vim.lsp.start when existing client has no workspace_folders', function()
1859+
exec_lua(create_server_definition)
1860+
eq(
1861+
{ 2, 'foo', 'foo' },
1862+
exec_lua(function()
1863+
local server = _G._create_server()
1864+
vim.lsp.start { cmd = server.cmd, name = 'foo' }
1865+
vim.lsp.start { cmd = server.cmd, name = 'foo', root_dir = 'bar' }
1866+
local foos = vim.lsp.get_clients()
1867+
return { #foos, foos[1].name, foos[2].name }
1868+
end)
1869+
)
1870+
end)
18571871
end)
18581872

18591873
describe('parsing tests', function()

0 commit comments

Comments
 (0)