Skip to content

[idea] Per-buffer LSP client enable/disable command — manage active clients without restarting #123

@stanfish06

Description

@stanfish06

What

A user command (e.g. :LspToggle <client-name>) that stops or re-starts a specific LSP client for the current buffer without restarting Neovim.

Where

lua/config/plugin_config.lua — the LspAttach block and/or a new autocommand group. Would complement the existing LSP setup at lines 104–116.

Why it matters

The config enables several LSPs simultaneously, including both pyright and pyrefly for Python (see related audit issue). More generally, some LSPs are expensive (pyright on a large monorepo, rust_analyzer on a cold cache) and the user may want to temporarily silence one without editing config and reloading. Currently there is no ergonomic way to do this — the only escape hatch is :lua vim.lsp.stop_client(id) which requires knowing the numeric client ID.

A command like:

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)  -- re-attach if it was stopped
end, { nargs = 1, complete = function()
    return vim.tbl_map(function(c) return c.name end, vim.lsp.get_clients({ bufnr = 0 }))
end })

would let the user toggle an active client from the command line with tab-completion.

Suggested implementation sketch

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions