diff options
| author | Ranjith Hegde <ranjithshegde@gmail.com> | 2022-08-23 16:03:20 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-23 07:03:20 -0700 |
| commit | fe7a6f41e59654db6bbc9eb2d084decc54b295e4 (patch) | |
| tree | c7967bb5b649ad7f8f00c697bedc2f60db9e507a /plugin | |
| parent | Revert "docs: vim.lsp.buf.formatting() is deprecated #2077 (diff) | |
| download | nvim-lspconfig-fe7a6f41e59654db6bbc9eb2d084decc54b295e4.tar nvim-lspconfig-fe7a6f41e59654db6bbc9eb2d084decc54b295e4.tar.gz nvim-lspconfig-fe7a6f41e59654db6bbc9eb2d084decc54b295e4.tar.bz2 nvim-lspconfig-fe7a6f41e59654db6bbc9eb2d084decc54b295e4.tar.lz nvim-lspconfig-fe7a6f41e59654db6bbc9eb2d084decc54b295e4.tar.xz nvim-lspconfig-fe7a6f41e59654db6bbc9eb2d084decc54b295e4.tar.zst nvim-lspconfig-fe7a6f41e59654db6bbc9eb2d084decc54b295e4.zip | |
feat!: 0.7 API update (#1984)
* switch to lua api for autocommands
* switch to nvim_create_user_command
* move to lua plugin initialization
NOTICE: Defining commands in server configurations will be deprecated in
future releases.
See `:help lspconfig.txt` to setup the same in an `on_attach` function.
Co-authored-by: Michael Lingelbach <m.j.lbach@gmail.com>
Diffstat (limited to 'plugin')
| -rw-r--r-- | plugin/lspconfig.lua | 91 | ||||
| -rw-r--r-- | plugin/lspconfig.vim | 16 |
2 files changed, 91 insertions, 16 deletions
diff --git a/plugin/lspconfig.lua b/plugin/lspconfig.lua new file mode 100644 index 00000000..fd22a206 --- /dev/null +++ b/plugin/lspconfig.lua @@ -0,0 +1,91 @@ +if vim.g.lspconfig ~= nil then + return +end +vim.g.lspconfig = 1 + +local version_info = vim.version() +if vim.fn.has 'nvim-0.7' ~= 1 then + local warning_str = string.format( + '[lspconfig] requires neovim 0.7 or later. Detected neovim version: 0.%s.%s', + version_info.minor, + version_info.patch + ) + vim.notify_once(warning_str) + return +end + +local lsp_complete_configured_servers = function(arg) + return vim.tbl_filter(function(s) + return s:sub(1, #arg) == arg + end, vim.tbl_keys(require 'lspconfig.configs')) +end + +local lsp_get_active_client_ids = function(arg) + local clients = vim.tbl_map(function(client) + return ('%d (%s)'):format(client.id, client.name) + end, require('lspconfig.util').get_managed_clients()) + + return vim.tbl_filter(function(s) + return s:sub(1, #arg) == arg + end, clients) +end + +local get_clients_from_cmd_args = function(arg) + local result = {} + for id in (arg or ''):gmatch '(%d+)' do + result[id] = vim.lsp.get_client_by_id(tonumber(id)) + end + if vim.tbl_isempty(result) then + return require('lspconfig.util').get_managed_clients() + end + return vim.tbl_values(result) +end + +-- Called from plugin/lspconfig.vim because it requires knowing that the last +-- script in scriptnames to be executed is lspconfig. +vim.api.nvim_create_user_command('LspInfo', function() + require 'lspconfig.ui.lspinfo'() +end, { + desc = 'Displays attached, active, and configured language servers', +}) + +vim.api.nvim_create_user_command('LspStart', function(info) + local server_name = info.args[1] ~= '' and info.args + if server_name then + local config = require('lspconfig.configs')[server_name] + if config then + config.launch() + end + else + local other_matching_configs = require('lspconfig.util').get_other_matching_providers(vim.bo.filetype) + for _, config in ipairs(other_matching_configs) do + config.launch() + end + end +end, { + desc = 'Manually launches a language server', + nargs = '?', + complete = lsp_complete_configured_servers, +}) +vim.api.nvim_create_user_command('LspRestart', function(info) + for _, client in ipairs(get_clients_from_cmd_args(info.args)) do + client.stop() + vim.defer_fn(function() + require('lspconfig.configs')[client.name].launch() + end, 500) + end +end, { + desc = 'Manually restart the given language client(s)', + nargs = '?', + complete = lsp_get_active_client_ids, +}) + +vim.api.nvim_create_user_command('LspStop', function(info) + for _, client in ipairs(get_clients_from_cmd_args(info.args)) do + client.stop() + end +end, { + desc = 'Manually stops the given language client(s)', + nargs = '?', + complete = lsp_get_active_client_ids, +}) diff --git a/plugin/lspconfig.vim b/plugin/lspconfig.vim deleted file mode 100644 index 5c52d4e1..00000000 --- a/plugin/lspconfig.vim +++ /dev/null @@ -1,16 +0,0 @@ -if exists('g:lspconfig') - finish -endif -let g:lspconfig = 1 - -lua << EOF -lsp_complete_configured_servers = function() - return table.concat(require'lspconfig'.available_servers(), '\n') -end -lsp_get_active_client_ids = function() - return vim.tbl_map(function(client) - return ("%d (%s)"):format(client.id, client.name) - end, require'lspconfig.util'.get_managed_clients()) -end -require'lspconfig'._root._setup() -EOF |
