commit 5554fcc28683e5d182198158b293851a96f0d6a0
parent 95ab723995f1cc1a11c62355fbac64597526d47e
Author: Micah Halter <micah.halter@gtri.gatech.edu>
Date: Fri, 28 Mar 2025 08:46:10 -0400
fix(lsp): warn on missing config in :checkhealth #33087
Problem
When calling `:checkhealth vim.lsp` after the user has enabled a language
server with `vim.lsp.enable` that has no configuration a runtime error
is hit because the code expects for a configuration to exist.
Solution:
Check if a configuration was returned before parsing it, if it isn't
returned then warn the user that the server has been enabled but a
configuration was not found.
Diffstat:
1 file changed, 24 insertions(+), 18 deletions(-)
diff --git a/runtime/lua/vim/lsp/health.lua b/runtime/lua/vim/lsp/health.lua
@@ -187,26 +187,32 @@ local function check_enabled_configs()
local config = vim.lsp.config[name]
local text = {} --- @type string[]
text[#text + 1] = ('%s:'):format(name)
- for k, v in
- vim.spairs(config --[[@as table<string,any>]])
- do
- local v_str --- @type string?
- if k == 'name' then
- v_str = nil
- elseif k == 'filetypes' or k == 'root_markers' then
- v_str = table.concat(v, ', ')
- elseif type(v) == 'function' then
- v_str = func_tostring(v)
- else
- v_str = vim.inspect(v, { newline = '\n ' })
- end
+ if not config then
+ report_warn(
+ ("'%s' config not found. Ensure that vim.lsp.config('%s') was called."):format(name, name)
+ )
+ else
+ for k, v in
+ vim.spairs(config --[[@as table<string,any>]])
+ do
+ local v_str --- @type string?
+ if k == 'name' then
+ v_str = nil
+ elseif k == 'filetypes' or k == 'root_markers' then
+ v_str = table.concat(v, ', ')
+ elseif type(v) == 'function' then
+ v_str = func_tostring(v)
+ else
+ v_str = vim.inspect(v, { newline = '\n ' })
+ end
- if k == 'cmd' and type(v) == 'table' and vim.fn.executable(v[1]) == 0 then
- report_warn(("'%s' is not executable. Configuration will not be used."):format(v[1]))
- end
+ if k == 'cmd' and type(v) == 'table' and vim.fn.executable(v[1]) == 0 then
+ report_warn(("'%s' is not executable. Configuration will not be used."):format(v[1]))
+ end
- if v_str then
- text[#text + 1] = ('- %s: %s'):format(k, v_str)
+ if v_str then
+ text[#text + 1] = ('- %s: %s'):format(k, v_str)
+ end
end
end
text[#text + 1] = ''