mirror of
https://github.com/neovim/neovim.git
synced 2025-10-17 15:21:47 +00:00
fix(lsp): "attempt to index nil config" #36189
Problem: If a client doesn't have a config then an error may be thrown. Probably caused by:2f78ff816b
Lua callback: …/lsp.lua:442: attempt to index local 'config' (a nil value) stack traceback: …/lsp.lua:442: in function 'can_start' …/lsp.lua:479: in function 'lsp_enable_callback' …/lsp.lua:566: in function <…/lsp.lua:565> Solution: Not all clients necessarily have configs. - Handle `config=nil` in `can_start`. - If user "enables" an invalid name that happens to match a *client* name, don't auto-detach the client. (cherry picked from commitbf4710d8c3
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
be94fe3156
commit
2668a46902
@@ -6446,6 +6446,35 @@ describe('LSP', function()
|
||||
)
|
||||
end)
|
||||
|
||||
it('handle nil config (some clients may not have a config!)', function()
|
||||
exec_lua(create_server_definition)
|
||||
exec_lua(function()
|
||||
local server = _G._create_server()
|
||||
vim.bo.filetype = 'lua'
|
||||
-- Attach a client without defining a config.
|
||||
local client_id = vim.lsp.start({
|
||||
name = 'test_ls',
|
||||
cmd = function(dispatchers, config)
|
||||
_G.test_resolved_root = config.root_dir --[[@type string]]
|
||||
return server.cmd(dispatchers, config)
|
||||
end,
|
||||
}, { bufnr = 0 })
|
||||
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local client = vim.lsp.get_client_by_id(client_id)
|
||||
assert(client.attached_buffers[bufnr])
|
||||
|
||||
-- Exercise the codepath which had a regression:
|
||||
vim.lsp.enable('test_ls')
|
||||
vim.api.nvim_exec_autocmds('FileType', { buffer = bufnr })
|
||||
|
||||
-- enable() does _not_ detach the client since it doesn't actually have a config.
|
||||
-- XXX: otoh, is it confusing to allow `enable("foo")` if there a "foo" _client_ without a "foo" _config_?
|
||||
assert(client.attached_buffers[bufnr])
|
||||
assert(client_id == vim.lsp.get_client_by_id(bufnr).id)
|
||||
end)
|
||||
end)
|
||||
|
||||
it('attaches to buffers when they are opened', function()
|
||||
exec_lua(create_server_definition)
|
||||
|
||||
|
Reference in New Issue
Block a user