Skip to content

fix: restore :LspStart/LspStop behaviour without arguments #3890

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
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
36 changes: 29 additions & 7 deletions plugin/lspconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,22 @@ 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)
vim.lsp.enable(servers)
end, {
desc = 'Enable and launch a language server',
nargs = '?',
Expand Down Expand Up @@ -133,16 +143,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 = '*',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed some inconsistencies here:

  • We should probably use "servers" instead of "clients" in all user-facing descriptions etc.
  • :LspStop takes multiple arguments but :LspStart only one (or zero now).

Happy to change these too in this PR if nobody objects.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably use "servers" instead of "clients" in all user-facing descriptions etc

Only for cases where "server" is the least confusing name. Doesn't look like the case here.

In old versions of this repo "servers" (as opposed to "configs" or "clients") was used everywhere in a nonsensical way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:LspStop takes multiple arguments but :LspStart only one (or zero now).

let's finish this pr first

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only for cases where "server" is the least confusing name. Doesn't look like the case here.

In old versions of this repo "servers" (as opposed to "configs" or "clients") was used everywhere in a nonsensical way.

@justinmk okay I figured maybe for users "servers" would make the most sense (and I did just mean changing the user-facing parts, not internal variable names), but you definitely have more insight here 😀

:LspStop takes multiple arguments but :LspStart only one (or zero now).

I pushed #3896 for that now.

complete = complete_client,
})

Expand Down
Loading