From 433dea8c825919f10417078a39cb72fe157fbcba Mon Sep 17 00:00:00 2001 From: Markus Koller Date: Fri, 6 Jun 2025 17:09:42 +0200 Subject: [PATCH 1/2] fix: restore :LspStart/LspStop behaviour without arguments After the refactoring in e4d1c8b for Neovim 0.11.2 these commands now require an argument. This restores the previous behaviour where `:LspStart` defaults to enabling all servers matching the filetype of the current buffer, and `:LspStop` defaults to disabling all servers attached to the current buffer. --- plugin/lspconfig.lua | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/plugin/lspconfig.lua b/plugin/lspconfig.lua index 4fb5e74a99..5db2550caa 100644 --- a/plugin/lspconfig.lua +++ b/plugin/lspconfig.lua @@ -97,12 +97,24 @@ if vim.version.ge(vim.version(), { 0, 11, 2 }) then end api.nvim_create_user_command('LspStart', function(info) - if vim.lsp.config[info.args] == nil then - vim.notify(("Invalid server name '%s'"):format(info.args)) - return + local servers = info.fargs + + -- Default to enabling all servers matching the filetype of the current buffer. + -- This assumes that they've been explicitly configured through `vim.lsp.config`, + -- otherwise they won't be present in the private `vim.lsp.config._configs` table. + if #servers == 0 then + local filetype = vim.bo.filetype + for name, _ in pairs(vim.lsp.config._configs) do + local filetypes = vim.lsp.config[name].filetypes + if filetypes and vim.tbl_contains(filetypes, filetype) then + table.insert(servers, name) + end + end end - vim.lsp.enable(info.args) + for _, name in ipairs(servers) do + vim.lsp.enable(name) + end end, { desc = 'Enable and launch a language server', nargs = '?', @@ -133,16 +145,28 @@ if vim.version.ge(vim.version(), { 0, 11, 2 }) then }) api.nvim_create_user_command('LspStop', function(info) - for _, name in ipairs(info.fargs) do + local clients = info.fargs + + -- Default to disabling all servers on current buffer + if #clients == 0 then + clients = vim + .iter(vim.lsp.get_clients({ bufnr = vim.api.nvim_get_current_buf() })) + :map(function(client) + return client.name + end) + :totable() + end + + for _, name in ipairs(clients) do if vim.lsp.config[name] == nil then - vim.notify(("Invalid server name '%s'"):format(info.args)) + vim.notify(("Invalid server name '%s'"):format(name)) else vim.lsp.enable(name, false) end end end, { desc = 'Disable and stop the given client(s)', - nargs = '+', + nargs = '*', complete = complete_client, }) From ee7f5d7a545b035df608a4621b50da07e5cdedff Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 7 Jun 2025 18:19:53 -0700 Subject: [PATCH 2/2] Update plugin/lspconfig.lua --- plugin/lspconfig.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugin/lspconfig.lua b/plugin/lspconfig.lua index 5db2550caa..a5cd471538 100644 --- a/plugin/lspconfig.lua +++ b/plugin/lspconfig.lua @@ -112,9 +112,7 @@ if vim.version.ge(vim.version(), { 0, 11, 2 }) then end end - for _, name in ipairs(servers) do - vim.lsp.enable(name) - end + vim.lsp.enable(servers) end, { desc = 'Enable and launch a language server', nargs = '?',