diff options
| author | Lorenzo Bellina <59364991+TheRealLorenz@users.noreply.github.com> | 2025-05-04 22:18:24 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-04 13:18:24 -0700 |
| commit | e4d1c8bf9077ecf617ce18f27738658a7d76ac95 (patch) | |
| tree | 34de7f30b1dde2199aa053b6407e2ac90b617a8d /plugin | |
| parent | docs: update configs.md (diff) | |
| download | nvim-lspconfig-e4d1c8bf9077ecf617ce18f27738658a7d76ac95.tar nvim-lspconfig-e4d1c8bf9077ecf617ce18f27738658a7d76ac95.tar.gz nvim-lspconfig-e4d1c8bf9077ecf617ce18f27738658a7d76ac95.tar.bz2 nvim-lspconfig-e4d1c8bf9077ecf617ce18f27738658a7d76ac95.tar.lz nvim-lspconfig-e4d1c8bf9077ecf617ce18f27738658a7d76ac95.tar.xz nvim-lspconfig-e4d1c8bf9077ecf617ce18f27738658a7d76ac95.tar.zst nvim-lspconfig-e4d1c8bf9077ecf617ce18f27738658a7d76ac95.zip | |
feat: support :LspStart/LspRestart in Nvim 0.11.2+ #3734
Diffstat (limited to 'plugin')
| -rw-r--r-- | plugin/lspconfig.lua | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/plugin/lspconfig.lua b/plugin/lspconfig.lua index 6c3b953b..d77000e8 100644 --- a/plugin/lspconfig.lua +++ b/plugin/lspconfig.lua @@ -67,6 +67,82 @@ end -- script in scriptnames to be executed is lspconfig. api.nvim_create_user_command('LspInfo', ':checkhealth vim.lsp', { desc = 'Alias to `:checkhealth vim.lsp`' }) +if vim.version.ge(vim.version(), { 0, 11, 2 }) then + local complete_client = function(arg) + return vim + .iter(vim.lsp.get_clients()) + :map(function(client) + return client.name + end) + :filter(function(name) + return name:sub(1, #arg) == arg + end) + :totable() + end + + local complete_config = function(arg) + return vim + .iter(vim.api.nvim_get_runtime_file(('lsp/%s*.lua'):format(arg), true)) + :map(function(path) + local file_name = path:match('[^/]*.lua$') + return file_name:sub(0, #file_name - 4) + end) + :totable() + 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 + end + + vim.lsp.enable(info.args) + end, { + desc = 'Enable and launch a language server', + nargs = '?', + complete = complete_config, + }) + + api.nvim_create_user_command('LspRestart', function(info) + for _, name in ipairs(info.fargs) do + if vim.lsp.config[name] == nil then + vim.notify(("Invalid server name '%s'"):format(info.args)) + else + vim.lsp.enable(name, false) + end + end + + local timer = assert(vim.uv.new_timer()) + timer:start(500, 0, function() + for _, name in ipairs(info.fargs) do + vim.schedule_wrap(function(x) + vim.lsp.enable(x) + end)(name) + end + end) + end, { + desc = 'Restart the given client(s)', + nargs = '+', + complete = complete_client, + }) + + api.nvim_create_user_command('LspStop', function(info) + for _, name in ipairs(info.fargs) do + if vim.lsp.config[name] == nil then + vim.notify(("Invalid server name '%s'"):format(info.args)) + else + vim.lsp.enable(name, false) + end + end + end, { + desc = 'Disable and stop the given client(s)', + nargs = '+', + complete = complete_client, + }) + + return +end + api.nvim_create_user_command('LspStart', function(info) local server_name = string.len(info.args) > 0 and info.args or nil if server_name then |
