diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2025-09-13 21:51:06 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-13 18:51:06 -0700 |
| commit | 2f78ff816b03661b5f74d0624e973eaca0d64ef1 (patch) | |
| tree | 35ad5cefe6d25145ac45e48b5b75dce9458faca3 /runtime/lua/vim/lsp.lua | |
| parent | 5ef567d13049792cf00e3a50961353908f791d4b (diff) | |
| download | rneovim-2f78ff816b03661b5f74d0624e973eaca0d64ef1.tar.gz rneovim-2f78ff816b03661b5f74d0624e973eaca0d64ef1.tar.bz2 rneovim-2f78ff816b03661b5f74d0624e973eaca0d64ef1.zip | |
fix(lsp): misleading logs in non-applicable filetypes #35749
Problem:
LSP logs show misleading "cannot start" messages when editing a filetype
NOT listed in the `config.filetypes` field.
[ERROR][2025-09-13 18:55:56] …/runtime//lua/vim/lsp/log.lua:151
"cannot start cssls due to config error: …/runtime//lua/vim/lsp.lua:423:
cmd: expected expected function or table with executable command,
got table: 0x0104701b18. Info: vscode-css-language-server is not executable"
Solution:
- `can_start`: check `config.filetypes` before checking the rest of the
config.
Diffstat (limited to 'runtime/lua/vim/lsp.lua')
| -rw-r--r-- | runtime/lua/vim/lsp.lua | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index dc09cdde5c..4967aefd6d 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -426,16 +426,21 @@ local function validate_config(config) end --- @param bufnr integer ---- @param name string --- @param config vim.lsp.Config -local function can_start(bufnr, name, config) - local config_ok, err = pcall(validate_config, config) - if not config_ok then - log.error(('cannot start %s due to config error: %s'):format(name, err)) +--- @param logging boolean +local function can_start(bufnr, config, logging) + if + type(config.filetypes) == 'table' + and not vim.tbl_contains(config.filetypes, vim.bo[bufnr].filetype) + then return false end - if config.filetypes and not vim.tbl_contains(config.filetypes, vim.bo[bufnr].filetype) then + local config_ok, err = pcall(validate_config, config) + if not config_ok then + if logging then + log.error(('invalid "%s" config: %s'):format(config.name, err)) + end return false end @@ -462,9 +467,7 @@ 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, client.name, lsp.config[client.name]) - then + if lsp.is_enabled(client.name) and not can_start(bufnr, lsp.config[client.name], false) then lsp.buf_detach_client(bufnr, client.id) end end @@ -472,7 +475,7 @@ local function lsp_enable_callback(bufnr) -- Start any clients that apply to this buffer. for name in vim.spairs(lsp._enabled_configs) do local config = lsp.config[name] - if config and can_start(bufnr, name, config) then + if config and can_start(bufnr, config, true) then -- Deepcopy config so changes done in the client -- do not propagate back to the enabled configs. config = vim.deepcopy(config) |