aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod <kefirchik3@gmail.com>2021-10-18 02:13:21 +0300
committerGitHub <noreply@github.com>2021-10-17 16:13:21 -0700
commita209627886c3edc6926bede732543f9c09aaf22c (patch)
tree088da10576a493acb63740a19b1dbd2ce95474e2
parentdocs: update CONFIG.md (diff)
downloadnvim-lspconfig-a209627886c3edc6926bede732543f9c09aaf22c.tar
nvim-lspconfig-a209627886c3edc6926bede732543f9c09aaf22c.tar.gz
nvim-lspconfig-a209627886c3edc6926bede732543f9c09aaf22c.tar.bz2
nvim-lspconfig-a209627886c3edc6926bede732543f9c09aaf22c.tar.lz
nvim-lspconfig-a209627886c3edc6926bede732543f9c09aaf22c.tar.xz
nvim-lspconfig-a209627886c3edc6926bede732543f9c09aaf22c.tar.zst
nvim-lspconfig-a209627886c3edc6926bede732543f9c09aaf22c.zip
feat: improve interface for `:Lsp*` commands (#1324)
-rw-r--r--lua/lspconfig.lua44
-rw-r--r--lua/lspconfig/util.lua11
-rw-r--r--plugin/lspconfig.vim8
3 files changed, 29 insertions, 34 deletions
diff --git a/lua/lspconfig.lua b/lua/lspconfig.lua
index d2957b7e..fd15f6a0 100644
--- a/lua/lspconfig.lua
+++ b/lua/lspconfig.lua
@@ -26,15 +26,15 @@ function M._root._setup()
LspStart = {
function(server_name)
if server_name then
- require('lspconfig')[server_name].autostart()
+ if configs[server_name] then
+ configs[server_name].autostart()
+ end
else
local buffer_filetype = vim.bo.filetype
- for client_name, config in pairs(configs) do
- if config.filetypes then
- for _, filetype_match in ipairs(config.filetypes) do
- if buffer_filetype == filetype_match then
- require('lspconfig')[client_name].autostart()
- end
+ for _, config in pairs(configs) do
+ for _, filetype_match in ipairs(config.filetypes or {}) do
+ if buffer_filetype == filetype_match then
+ config.autostart()
end
end
end
@@ -44,39 +44,25 @@ function M._root._setup()
description = '`:LspStart` Manually launches a language server.',
},
LspStop = {
- function(client_id)
- if not client_id then
- vim.lsp.stop_client(vim.lsp.get_active_clients())
- else
- local client = vim.lsp.get_client_by_id(tonumber(client_id))
- if client then
- client.stop()
- end
+ function(cmd_args)
+ for _, client in ipairs(M.util.get_clients_from_cmd_args(cmd_args)) do
+ client.stop()
end
end,
'-nargs=? -complete=customlist,v:lua.lsp_get_active_client_ids',
- description = '`:LspStop` Manually stops the given language client.',
+ description = '`:LspStop` Manually stops the given language client(s).',
},
LspRestart = {
- function(client_id)
- local clients
-
- if client_id == nil then
- clients = vim.lsp.buf_get_clients(0)
- else
- clients = { vim.lsp.get_client_by_id(tonumber(client_id)) }
- end
-
- for _, client in pairs(clients) do
- local client_name = client.name
+ function(cmd_args)
+ for _, client in ipairs(M.util.get_clients_from_cmd_args(cmd_args)) do
client.stop()
vim.defer_fn(function()
- require('lspconfig')[client_name].autostart()
+ configs[client.name].autostart()
end, 500)
end
end,
'-nargs=? -complete=customlist,v:lua.lsp_get_active_client_ids',
- description = '`:LspRestart` Manually restart the given language client.',
+ description = '`:LspRestart` Manually restart the given language client(s).',
},
}
diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua
index 6e0f7f41..3691da68 100644
--- a/lua/lspconfig/util.lua
+++ b/lua/lspconfig/util.lua
@@ -373,4 +373,15 @@ function M.get_other_matching_providers(filetype)
return other_matching_configs
end
+function M.get_clients_from_cmd_args(arg)
+ local result = {}
+ for id in (arg or ''):gmatch '(%d+) %((%w+)%)' do
+ result[id] = vim.lsp.get_client_by_id(tonumber(id))
+ end
+ if vim.tbl_isempty(result) then
+ return vim.lsp.get_active_clients()
+ end
+ return vim.tbl_values(result)
+end
+
return M
diff --git a/plugin/lspconfig.vim b/plugin/lspconfig.vim
index a9e947c6..7b7ee55a 100644
--- a/plugin/lspconfig.vim
+++ b/plugin/lspconfig.vim
@@ -8,11 +8,9 @@ lsp_complete_configured_servers = function()
return table.concat(require'lspconfig'.available_servers(), '\n')
end
lsp_get_active_client_ids = function()
- client_ids = {}
- for idx, client in ipairs(vim.lsp.get_active_clients()) do
- table.insert(client_ids, tostring(client.id))
- end
- return client_ids
+ return vim.tbl_map(function(client)
+ return ("%d (%s)"):format(client.id, client.name)
+ end, vim.lsp.get_active_clients())
end
require'lspconfig'._root._setup()
EOF