mirror of
https://github.com/neovim/neovim.git
synced 2026-03-06 17:17:21 +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:2f78ff816bLua 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]
parent
be94fe3156
commit
2668a46902
@@ -496,10 +496,16 @@ local function validate_config(config)
|
||||
validate('filetypes', config.filetypes, 'table', true)
|
||||
end
|
||||
|
||||
--- Returns true if:
|
||||
--- 1. the config is managed by vim.lsp,
|
||||
--- 2. it applies to the given buffer, and
|
||||
--- 3. its config is valid (in particular: its `cmd` isn't broken).
|
||||
---
|
||||
--- @param bufnr integer
|
||||
--- @param config vim.lsp.Config
|
||||
--- @param logging boolean
|
||||
local function can_start(bufnr, config, logging)
|
||||
assert(config)
|
||||
if
|
||||
type(config.filetypes) == 'table'
|
||||
and not vim.tbl_contains(config.filetypes, vim.bo[bufnr].filetype)
|
||||
@@ -538,7 +544,13 @@ local function lsp_enable_callback(bufnr)
|
||||
-- Stop any clients that no longer apply to this buffer.
|
||||
local clients = lsp.get_clients({ bufnr = bufnr, _uninitialized = true })
|
||||
for _, client in ipairs(clients) do
|
||||
if lsp.is_enabled(client.name) and not can_start(bufnr, lsp.config[client.name], false) then
|
||||
-- Don't index into lsp.config[…] unless is_enabled() is true.
|
||||
if
|
||||
lsp.is_enabled(client.name)
|
||||
-- Check that the client is managed by vim.lsp.config before deciding to detach it!
|
||||
and lsp.config[client.name]
|
||||
and not can_start(bufnr, lsp.config[client.name], false)
|
||||
then
|
||||
lsp.buf_detach_client(bufnr, client.id)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user