aboutsummaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorMarkus Koller <markus@snafu.ch>2025-06-08 03:23:32 +0200
committerGitHub <noreply@github.com>2025-06-07 18:23:32 -0700
commita182334ba933e58240c2c45e6ae2d9c7ae313e00 (patch)
treed17c286ba5a506ee674fa759ec4d2f1e4070cbbf /plugin
parentfix(helm_ls,yamlls): support custom filetype for helm-ls #3893 (diff)
downloadnvim-lspconfig-a182334ba933e58240c2c45e6ae2d9c7ae313e00.tar
nvim-lspconfig-a182334ba933e58240c2c45e6ae2d9c7ae313e00.tar.gz
nvim-lspconfig-a182334ba933e58240c2c45e6ae2d9c7ae313e00.tar.bz2
nvim-lspconfig-a182334ba933e58240c2c45e6ae2d9c7ae313e00.tar.lz
nvim-lspconfig-a182334ba933e58240c2c45e6ae2d9c7ae313e00.tar.xz
nvim-lspconfig-a182334ba933e58240c2c45e6ae2d9c7ae313e00.tar.zst
nvim-lspconfig-a182334ba933e58240c2c45e6ae2d9c7ae313e00.zip
fix: support :LspStart/LspStop without arguments #3890
Problem: After the refactoring in e4d1c8b for Neovim 0.11.2 these commands now require an argument. Solution: Restore the previous behaviour where `:LspStart` defaults to enabling all servers matching the filetype of the current buffer, and `:LspStop` defaults to disabling all servers attached to the current buffer.
Diffstat (limited to 'plugin')
-rw-r--r--plugin/lspconfig.lua36
1 files changed, 29 insertions, 7 deletions
diff --git a/plugin/lspconfig.lua b/plugin/lspconfig.lua
index 4fb5e74a..a5cd4715 100644
--- a/plugin/lspconfig.lua
+++ b/plugin/lspconfig.lua
@@ -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 = '?',
@@ -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 = '*',
complete = complete_client,
})