Skip to content

Commit 77d3fdf

Browse files
authored
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.
1 parent a182334 commit 77d3fdf

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Most of the time, the reason for failure is present in the logs.
154154
* `:LspInfo` (alias to `:checkhealth vim.lsp`) shows the status of active and configured language servers.
155155
* `:LspStart <config_name>` Start the requested server name. Will only successfully start if the command detects a root directory matching the current config.
156156
* `:LspStop [<client_id_or_name> ...]` Stops the given server(s). Defaults to stopping all servers active on the current buffer. To force stop add `++force`
157-
* `:LspRestart [<client_id_or_name> ...]` Restarts the given client(s), and attempts to reattach to all previously attached buffers.
157+
* `:LspRestart [<client_id_or_name> ...]` Restarts the given client(s), and attempts to reattach to all previously attached buffers. Defaults to restarting all active servers.
158158

159159
## Contributions
160160

doc/lspconfig.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ servers: >vim
9393

9494
:LspRestart [client_id] or [config_name] ... *:LspRestart*
9595
Restarts the clients with the given client-ids or config names, and attempts
96-
to reattach to all previously attached buffers.
96+
to reattach to all previously attached buffers. Defaults to restarting all
97+
active servers.
9798

9899
==============================================================================
99100
SERVER CONFIGS *lspconfig-configurations*

plugin/lspconfig.lua

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,25 +120,37 @@ if vim.version.ge(vim.version(), { 0, 11, 2 }) then
120120
})
121121

122122
api.nvim_create_user_command('LspRestart', function(info)
123-
for _, name in ipairs(info.fargs) do
123+
local clients = info.fargs
124+
125+
-- Default to restarting all active servers
126+
if #clients == 0 then
127+
clients = vim
128+
.iter(vim.lsp.get_clients())
129+
:map(function(client)
130+
return client.name
131+
end)
132+
:totable()
133+
end
134+
135+
for _, name in ipairs(clients) do
124136
if vim.lsp.config[name] == nil then
125-
vim.notify(("Invalid server name '%s'"):format(info.args))
137+
vim.notify(("Invalid server name '%s'"):format(name))
126138
else
127139
vim.lsp.enable(name, false)
128140
end
129141
end
130142

131143
local timer = assert(vim.uv.new_timer())
132144
timer:start(500, 0, function()
133-
for _, name in ipairs(info.fargs) do
145+
for _, name in ipairs(clients) do
134146
vim.schedule_wrap(function(x)
135147
vim.lsp.enable(x)
136148
end)(name)
137149
end
138150
end)
139151
end, {
140152
desc = 'Restart the given client(s)',
141-
nargs = '+',
153+
nargs = '*',
142154
complete = complete_client,
143155
})
144156

0 commit comments

Comments
 (0)