fix(lsp): only auto-detach lsp.config enabled clients #34325

Problem: A custom server (initialized through `vim.lsp.start`) gets
         unexpectedly detached.

Solution: Only auto-detach the clients enabled through `vim.lsp.enable`
          to prevent unexpected behavior.
(cherry picked from commit e5c5b563ec)
This commit is contained in:
Kai-Hsiang Hsu
2025-06-06 21:26:50 +08:00
committed by github-actions[bot]
parent d32a4dd4b0
commit c13eba5254

View File

@ -523,7 +523,9 @@ 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.config[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, client.name, lsp.config[client.name])
then
lsp.buf_detach_client(bufnr, client.id)
end
end