Skip to content

fix: support :LspRestart without arguments #3895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <config_name>` Start the requested server name. Will only successfully start if the command detects a root directory matching the current config.
* `: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`
* `:LspRestart [<client_id_or_name> ...]` Restarts the given client(s), and attempts to reattach to all previously attached buffers.
* `: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.

## Contributions

Expand Down
3 changes: 2 additions & 1 deletion doc/lspconfig.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
20 changes: 16 additions & 4 deletions plugin/lspconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,37 @@ 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
end

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)
end
end)
end, {
desc = 'Restart the given client(s)',
nargs = '+',
nargs = '*',
complete = complete_client,
})

Expand Down