-
Notifications
You must be signed in to change notification settings - Fork 4
Closed
Description
Description
The current implementation of M.register_lsp in plugins/nobbz/lua/nobbz/health.lua assumes that the LSP configuration exists and has the expected structure. This can lead to runtime errors if:
- The LSP configuration doesn't exist
- The LSP configuration doesn't have a
cmdfield or it's empty - The LSP configuration doesn't have a
filetypesfield or it's empty
Proposed Solution
Add error handling to safely handle these cases:
M.register_lsp = function(lsp)
local config = require("lspconfig")[lsp]
if not config then
vim.notify("LSP configuration for " .. lsp .. " not found", vim.log.levels.WARN)
return
end
if not config.cmd or #config.cmd == 0 then
vim.notify("No command found for LSP " .. lsp, vim.log.levels.WARN)
return
end
if not config.filetypes or #config.filetypes == 0 then
vim.notify("No filetypes found for LSP " .. lsp, vim.log.levels.WARN)
return
end
local program = config.cmd[1]
local pattern = config.filetypes[1]
M.register_program(program, false)
vim.api.nvim_create_autocmd("FileType", {
pattern = pattern,
callback = function()
M.register_program(program, true)
end,
})
endReferences
- Related to PR healthchecks #55
- Discussed in healthchecks #55 (comment)
Assignee
Metadata
Metadata
Assignees
Labels
No labels