-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,12 +97,24 @@ 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) | ||
for _, name in ipairs(servers) do | ||
vim.lsp.enable(name) | ||
end | ||
end, { | ||
desc = 'Enable and launch a language server', | ||
nargs = '?', | ||
|
@@ -133,16 +145,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 = '*', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noticed some inconsistencies here:
Happy to change these too in this PR if nobody objects. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
let's finish this pr first There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@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 😀
I pushed #3896 for that now. |
||
complete = complete_client, | ||
}) | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enable() accepts a list. this is a case where "configs" might be less confusing than "servers". we are enabling configs, which may eventually start a client and a server. we aren't really enabling "servers"