From 2db48d9a893271fe0e3285b790ff0683ac675da4 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <41898282+claude[bot]@users.noreply.github.com> Date: Thu, 4 Jun 2026 07:56:30 +0000 Subject: [PATCH] feat: add LspToggle command to stop/re-enable LSP clients per buffer Adds :LspToggle user command that stops an active LSP client on the current buffer, or re-enables it if already stopped. Tab-completion is scoped to clients currently attached to the buffer. Closes #123 Co-authored-by: Zhiyuan --- lua/config/plugin_config.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lua/config/plugin_config.lua b/lua/config/plugin_config.lua index 8cd51cb..4abe568 100644 --- a/lua/config/plugin_config.lua +++ b/lua/config/plugin_config.lua @@ -116,6 +116,20 @@ if not is_vscode then vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) end, }) + vim.api.nvim_create_user_command("LspToggle", function(opts) + local name = opts.args + for _, client in ipairs(vim.lsp.get_clients({ bufnr = 0, name = name })) do + vim.lsp.stop_client(client.id) + return + end + vim.lsp.enable(name) + end, { + nargs = 1, + complete = function() + return vim.tbl_map(function(c) return c.name end, vim.lsp.get_clients({ bufnr = 0 })) + end, + desc = "Stop or re-enable a named LSP client for the current buffer", + }) end -- conform (formatting)