feat(neovim): improve lsp
configuration to use newer setup (#255)
This change is based on the pull request [#1475][0]. Reviewed-on: #255 [0]: https://github.com/nvim-lua/kickstart.nvim/pull/1475 Co-authored-by: Joao P Dubas <joao.dubas+gitea@gmail.com> Co-committed-by: Joao P Dubas <joao.dubas+gitea@gmail.com>
This commit is contained in:
parent
e6a3064f30
commit
4236d03d18
@ -1,5 +1,5 @@
|
|||||||
diff --git a/init.lua b/init.lua
|
diff --git a/init.lua b/init.lua
|
||||||
index b98ffc6..8013e25 100644
|
index b98ffc6..f2d0ea5 100644
|
||||||
--- a/init.lua
|
--- a/init.lua
|
||||||
+++ b/init.lua
|
+++ b/init.lua
|
||||||
@@ -91,7 +91,7 @@ vim.g.mapleader = ' '
|
@@ -91,7 +91,7 @@ vim.g.mapleader = ' '
|
||||||
@ -60,6 +60,15 @@ index b98ffc6..8013e25 100644
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -659,7 +668,7 @@ require('lazy').setup({
|
||||||
|
-- By default, Neovim doesn't support everything that is in the LSP specification.
|
||||||
|
-- When you add blink.cmp, luasnip, etc. Neovim now has *more* capabilities.
|
||||||
|
-- So, we create new capabilities with blink.cmp, and then broadcast that to the servers.
|
||||||
|
- local capabilities = require('blink.cmp').get_lsp_capabilities()
|
||||||
|
+ -- local capabilities = require('blink.cmp').get_lsp_capabilities()
|
||||||
|
|
||||||
|
-- Enable the following language servers
|
||||||
|
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
|
||||||
@@ -684,6 +693,28 @@ require('lazy').setup({
|
@@ -684,6 +693,28 @@ require('lazy').setup({
|
||||||
-- ts_ls = {},
|
-- ts_ls = {},
|
||||||
--
|
--
|
||||||
@ -89,7 +98,7 @@ index b98ffc6..8013e25 100644
|
|||||||
lua_ls = {
|
lua_ls = {
|
||||||
-- cmd = { ... },
|
-- cmd = { ... },
|
||||||
-- filetypes = { ... },
|
-- filetypes = { ... },
|
||||||
@@ -698,6 +729,32 @@ require('lazy').setup({
|
@@ -698,6 +729,38 @@ require('lazy').setup({
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -119,17 +128,40 @@ index b98ffc6..8013e25 100644
|
|||||||
+ },
|
+ },
|
||||||
+ },
|
+ },
|
||||||
+ },
|
+ },
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ ---@type MasonLspconfigSettings
|
||||||
|
+ ---@diagnostic disable-next-line: missing-fields
|
||||||
|
+ require('mason-lspconfig').setup {
|
||||||
|
+ automatic_enable = vim.tbl_keys(servers or {}),
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Ensure the servers and tools above are installed
|
-- Ensure the servers and tools above are installed
|
||||||
@@ -729,6 +786,33 @@ require('lazy').setup({
|
@@ -719,20 +782,50 @@ require('lazy').setup({
|
||||||
-- by the server configuration above. Useful when disabling
|
})
|
||||||
-- certain features of an LSP (for example, turning off formatting for ts_ls)
|
require('mason-tool-installer').setup { ensure_installed = ensure_installed }
|
||||||
server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
|
|
||||||
|
- require('mason-lspconfig').setup {
|
||||||
|
- ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer)
|
||||||
|
- automatic_installation = false,
|
||||||
|
- handlers = {
|
||||||
|
- function(server_name)
|
||||||
|
- local server = servers[server_name] or {}
|
||||||
|
- -- This handles overriding only values explicitly passed
|
||||||
|
- -- by the server configuration above. Useful when disabling
|
||||||
|
- -- certain features of an LSP (for example, turning off formatting for ts_ls)
|
||||||
|
- server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
|
||||||
|
- require('lspconfig')[server_name].setup(server)
|
||||||
|
- end,
|
||||||
|
- },
|
||||||
|
- }
|
||||||
|
+ local extend_server_config = function (server_name)
|
||||||
|
+ local config = {}
|
||||||
|
+
|
||||||
|
+ if server_name == 'elixirls' then
|
||||||
+ -- overwrite elixirls for older versions of elixir
|
+ -- overwrite elixirls for older versions of elixir
|
||||||
+ -- * elixir 1.11 use version 0.12.0
|
+ -- * elixir 1.11 use version 0.12.0
|
||||||
+ -- * elixir 1.12 use verions 0.14.6
|
+ -- * elixir 1.12 use verions 0.14.6
|
||||||
+ if server_name == 'elixirls' then
|
|
||||||
+ local version = vim.fn.system('mise current elixir') or ''
|
+ local version = vim.fn.system('mise current elixir') or ''
|
||||||
+ local elixir_servers = {
|
+ local elixir_servers = {
|
||||||
+ { version = '^1.11', path = '/elixir-ls/release/v0.12.0/language_server.sh' },
|
+ { version = '^1.11', path = '/elixir-ls/release/v0.12.0/language_server.sh' },
|
||||||
@ -137,26 +169,40 @@ index b98ffc6..8013e25 100644
|
|||||||
+ }
|
+ }
|
||||||
+ for _, ex_server in ipairs(elixir_servers) do
|
+ for _, ex_server in ipairs(elixir_servers) do
|
||||||
+ if string.match(version, ex_server.version) == nil then goto continue end
|
+ if string.match(version, ex_server.version) == nil then goto continue end
|
||||||
+ server = vim.tbl_extend('keep', server, { cmd = { vim.fn.expand('$LOCAL_SRC_HOME') .. ex_server.path } })
|
+ config = { cmd = { vim.fn.expand('$LOCAL_SRC_HOME') .. ex_server.path } }
|
||||||
+ ::continue::
|
+ ::continue::
|
||||||
+ end
|
+ end
|
||||||
+ elseif server_name == 'pyright' then
|
+ elseif server_name == 'pyright' then
|
||||||
|
+ -- overwrite python path for pyright according to the virtualenv manager, be it poetry or system.
|
||||||
+ local python_paths = {
|
+ local python_paths = {
|
||||||
+ { name = 'poetry', cmd = { 'poetry', 'env', 'info', '--executable' }},
|
|
||||||
+ { name = 'system', cmd = { 'which', 'python' }},
|
+ { name = 'system', cmd = { 'which', 'python' }},
|
||||||
|
+ { name = 'poetry', cmd = { 'poetry', 'env', 'info', '--executable' }},
|
||||||
+ }
|
+ }
|
||||||
+ for _, py_server in ipairs(python_paths) do
|
+ for _, py_server in ipairs(python_paths) do
|
||||||
+ local cmd = vim.system(py_server.cmd, { text = true }):wait()
|
+ local cmd = vim.system(py_server.cmd, { text = true }):wait()
|
||||||
+ if (cmd.code > 0) then goto continue end
|
+ if (cmd.code > 0) then goto continue end
|
||||||
+ local python_path = string.gsub(cmd.stdout, '\n', '')
|
+ local python_path = string.gsub(cmd.stdout, '\n', '')
|
||||||
+ server = vim.tbl_extend('keep', server, { settings = { python = { pythonPath = python_path } } })
|
+ config = { settings = { python = { pythonPath = python_path } } }
|
||||||
+ ::continue::
|
+ ::continue::
|
||||||
+ end
|
+ end
|
||||||
+ end
|
+ end
|
||||||
require('lspconfig')[server_name].setup(server)
|
+
|
||||||
|
+ return config
|
||||||
|
+ end
|
||||||
|
+
|
||||||
|
+ -- Installed LSPs are configured and enabled automatically with mason-lspconfig
|
||||||
|
+ -- The loop below is for overriding the default configuration of LSPs with the ones in the servers table
|
||||||
|
+ for server_name, config in pairs(servers) do
|
||||||
|
+ config = vim.tbl_extend('keep', config, extend_server_config(server_name))
|
||||||
|
+ vim.lsp.config(server_name, config)
|
||||||
|
+ end
|
||||||
|
+
|
||||||
|
+ -- NOTE: Some servers may require an old setup until they are updated. For the full list refer here: https://github.com/neovim/nvim-lspconfig/issues/3705
|
||||||
|
+ -- These servers will have to be manually set up with require("lspconfig").server_name.setup{}
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
@@ -809,6 +893,9 @@ require('lazy').setup({
|
|
||||||
|
@@ -809,6 +902,9 @@ require('lazy').setup({
|
||||||
opts = {},
|
opts = {},
|
||||||
},
|
},
|
||||||
'folke/lazydev.nvim',
|
'folke/lazydev.nvim',
|
||||||
@ -166,7 +212,7 @@ index b98ffc6..8013e25 100644
|
|||||||
},
|
},
|
||||||
--- @module 'blink.cmp'
|
--- @module 'blink.cmp'
|
||||||
--- @type blink.cmp.Config
|
--- @type blink.cmp.Config
|
||||||
@@ -854,9 +941,19 @@ require('lazy').setup({
|
@@ -854,9 +950,19 @@ require('lazy').setup({
|
||||||
},
|
},
|
||||||
|
|
||||||
sources = {
|
sources = {
|
||||||
@ -187,7 +233,7 @@ index b98ffc6..8013e25 100644
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -882,19 +979,39 @@ require('lazy').setup({
|
@@ -882,19 +988,39 @@ require('lazy').setup({
|
||||||
--
|
--
|
||||||
-- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme`.
|
-- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme`.
|
||||||
'folke/tokyonight.nvim',
|
'folke/tokyonight.nvim',
|
||||||
@ -233,7 +279,7 @@ index b98ffc6..8013e25 100644
|
|||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -944,7 +1061,39 @@ require('lazy').setup({
|
@@ -944,7 +1070,39 @@ require('lazy').setup({
|
||||||
main = 'nvim-treesitter.configs', -- Sets main module to use for opts
|
main = 'nvim-treesitter.configs', -- Sets main module to use for opts
|
||||||
-- [[ Configure Treesitter ]] See `:help nvim-treesitter`
|
-- [[ Configure Treesitter ]] See `:help nvim-treesitter`
|
||||||
opts = {
|
opts = {
|
||||||
@ -274,7 +320,7 @@ index b98ffc6..8013e25 100644
|
|||||||
-- Autoinstall languages that are not installed
|
-- Autoinstall languages that are not installed
|
||||||
auto_install = true,
|
auto_install = true,
|
||||||
highlight = {
|
highlight = {
|
||||||
@@ -974,17 +1123,17 @@ require('lazy').setup({
|
@@ -974,17 +1132,17 @@ require('lazy').setup({
|
||||||
-- Uncomment any of the lines below to enable them (you will need to restart nvim).
|
-- Uncomment any of the lines below to enable them (you will need to restart nvim).
|
||||||
--
|
--
|
||||||
-- require 'kickstart.plugins.debug',
|
-- require 'kickstart.plugins.debug',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user