From 888a803755c58db56b5b20fcf6b812de877056c9 Mon Sep 17 00:00:00 2001 From: phanium <91544758+phanen@users.noreply.github.com> Date: Wed, 18 Dec 2024 22:37:12 +0800 Subject: fix(lsp): vim.lsp.start fails if existing client has no workspace_folders #31608 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: regression since https://github.com/neovim/neovim/pull/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 ``` --- runtime/lua/vim/lsp.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/vim') 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 -- cgit