mirror of
https://github.com/neovim/neovim.git
synced 2026-05-03 12:35:00 +00:00
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.
(cherry picked from commit b877aa34cf)
This commit is contained in:
committed by
github-actions[bot]
parent
968947b3c3
commit
216c56b7e0
@@ -526,6 +526,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
|
||||
|
||||
Reference in New Issue
Block a user