diff options
| author | Vsevolod <kefirchik3@gmail.com> | 2021-10-18 02:13:21 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-17 16:13:21 -0700 |
| commit | a209627886c3edc6926bede732543f9c09aaf22c (patch) | |
| tree | 088da10576a493acb63740a19b1dbd2ce95474e2 /lua | |
| parent | docs: update CONFIG.md (diff) | |
| download | nvim-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)
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/lspconfig.lua | 44 | ||||
| -rw-r--r-- | lua/lspconfig/util.lua | 11 |
2 files changed, 26 insertions, 29 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 |
