From 77d3fdfb3554632c7a3b101ded643d422de7626f Mon Sep 17 00:00:00 2001 From: Markus Koller Date: Tue, 10 Jun 2025 16:14:18 +0200 Subject: fix: support :LspRestart without arguments #3895 Problem: After the refactoring in e4d1c8b for Neovim 0.11.2 this command now requires an argument. Solution: Restore the previous behaviour where `:LspRestart` defaults to restarting all active servers. --- plugin/lspconfig.lua | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'plugin/lspconfig.lua') diff --git a/plugin/lspconfig.lua b/plugin/lspconfig.lua index a5cd4715..7cde1386 100644 --- a/plugin/lspconfig.lua +++ b/plugin/lspconfig.lua @@ -120,9 +120,21 @@ if vim.version.ge(vim.version(), { 0, 11, 2 }) then }) api.nvim_create_user_command('LspRestart', function(info) - for _, name in ipairs(info.fargs) do + local clients = info.fargs + + -- Default to restarting all active servers + if #clients == 0 then + clients = vim + .iter(vim.lsp.get_clients()) + :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 @@ -130,7 +142,7 @@ if vim.version.ge(vim.version(), { 0, 11, 2 }) then local timer = assert(vim.uv.new_timer()) timer:start(500, 0, function() - for _, name in ipairs(info.fargs) do + for _, name in ipairs(clients) do vim.schedule_wrap(function(x) vim.lsp.enable(x) end)(name) @@ -138,7 +150,7 @@ if vim.version.ge(vim.version(), { 0, 11, 2 }) then end) end, { desc = 'Restart the given client(s)', - nargs = '+', + nargs = '*', complete = complete_client, }) -- cgit v1.2.3-70-g09d2