diff --git a/README.md b/README.md index 7979b2031b..7fac4221ba 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ Most of the time, the reason for failure is present in the logs. * `:LspInfo` (alias to `:checkhealth vim.lsp`) shows the status of active and configured language servers. * `:LspStart ` Start the requested server name. Will only successfully start if the command detects a root directory matching the current config. * `:LspStop [ ...]` Stops the given server(s). Defaults to stopping all servers active on the current buffer. To force stop add `++force` -* `:LspRestart [ ...]` Restarts the given client(s), and attempts to reattach to all previously attached buffers. +* `:LspRestart [ ...]` Restarts the given client(s), and attempts to reattach to all previously attached buffers. Defaults to restarting all active servers. ## Contributions diff --git a/doc/lspconfig.txt b/doc/lspconfig.txt index 8698b69b60..b63a00f5e3 100644 --- a/doc/lspconfig.txt +++ b/doc/lspconfig.txt @@ -93,7 +93,8 @@ servers: >vim :LspRestart [client_id] or [config_name] ... *:LspRestart* Restarts the clients with the given client-ids or config names, and attempts -to reattach to all previously attached buffers. +to reattach to all previously attached buffers. Defaults to restarting all +active servers. ============================================================================== SERVER CONFIGS *lspconfig-configurations* diff --git a/plugin/lspconfig.lua b/plugin/lspconfig.lua index a5cd471538..7cde138627 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, })