diff options
| author | Jeremy Fleischman <jeremyfleischman@gmail.com> | 2025-05-03 14:57:59 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-03 14:57:59 -0700 |
| commit | b877aa34cf366982bf92aa8b17a8409a1f8eb134 (patch) | |
| tree | efed41ec55417b68f8432172b665c89683581cbe /runtime/lua/vim/lsp.lua | |
| parent | 047a10bfde531f433b9c8a07e6b380f376a7ec70 (diff) | |
| download | rneovim-b877aa34cf366982bf92aa8b17a8409a1f8eb134.tar.gz rneovim-b877aa34cf366982bf92aa8b17a8409a1f8eb134.tar.bz2 rneovim-b877aa34cf366982bf92aa8b17a8409a1f8eb134.zip | |
feat(lsp): detach LSP clients when 'filetype' changes #33707
Problem:
When the buffer 'filetype' changes, invalid or non-applicable LSP
clients are not detached.
https://github.com/neovim/neovim/issues/33443
https://github.com/neovim/nvim-lspconfig/issues/3326
Solution:
In the enable() routine, check can_start() on _existing_ clients.
Diffstat (limited to 'runtime/lua/vim/lsp.lua')
| -rw-r--r-- | runtime/lua/vim/lsp.lua | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index 5cd1e4eec7..cb711859da 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -544,6 +544,15 @@ local function lsp_enable_callback(bufnr) return end + -- 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 not can_start(bufnr, client.name, lsp.config[client.name]) then + lsp.buf_detach_client(bufnr, client.id) + end + end + + -- 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 |