From e5c5b563ec1e2076b950e80dd5522187ca53b699 Mon Sep 17 00:00:00 2001 From: Kai-Hsiang Hsu Date: Fri, 6 Jun 2025 21:26:50 +0800 Subject: [PATCH] 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. --- runtime/lua/vim/lsp.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index 4f06ed68d7..a3bbf24937 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -541,7 +541,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