mirror of
https://github.com/nvim-lua/kickstart.nvim.git
synced 2025-06-22 13:23:46 +02:00
feat: improved lsp setup for nvim > 0.11
This commit is contained in:
parent
3338d39206
commit
0028a33e0a
1 changed files with 83 additions and 48 deletions
79
init.lua
79
init.lua
|
@ -1,5 +1,4 @@
|
||||||
--[[
|
--[[
|
||||||
|
|
||||||
=====================================================================
|
=====================================================================
|
||||||
==================== READ THIS BEFORE CONTINUING ====================
|
==================== READ THIS BEFORE CONTINUING ====================
|
||||||
=====================================================================
|
=====================================================================
|
||||||
|
@ -659,18 +658,27 @@ require('lazy').setup({
|
||||||
-- By default, Neovim doesn't support everything that is in the LSP specification.
|
-- 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.
|
-- 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.
|
-- So, we create new capabilities with blink.cmp, and then broadcast that to the servers.
|
||||||
local capabilities = require('blink.cmp').get_lsp_capabilities()
|
-- NOTE: The following line is now commented as blink.cmp extends capabilites by default from its internal code:
|
||||||
|
-- https://github.com/Saghen/blink.cmp/blob/102db2f5996a46818661845cf283484870b60450/plugin/blink-cmp.lua
|
||||||
-- Enable the following language servers
|
-- It has been left here as a comment for educational purposes (as the predecessor completion plugin required this explicit step).
|
||||||
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
|
|
||||||
--
|
--
|
||||||
-- Add any additional override configuration in the following tables. Available keys are:
|
-- local capabilities = require("blink.cmp").get_lsp_capabilities()
|
||||||
|
|
||||||
|
-- Language servers can broadly be installed in the following ways:
|
||||||
|
-- 1) via the mason package manager; or
|
||||||
|
-- 2) via your system's package manager; or
|
||||||
|
-- 3) via a release binary from a language server's repo that's accessible somewhere on your system.
|
||||||
|
--
|
||||||
|
local servers = {
|
||||||
|
-- Add any additional override configuration in any of the following tables. Available keys are:
|
||||||
-- - cmd (table): Override the default command used to start the server
|
-- - cmd (table): Override the default command used to start the server
|
||||||
-- - filetypes (table): Override the default list of associated filetypes for the server
|
-- - filetypes (table): Override the default list of associated filetypes for the server
|
||||||
-- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
|
-- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
|
||||||
-- - settings (table): Override the default settings passed when initializing the server.
|
-- - settings (table): Override the default settings passed when initializing the server.
|
||||||
-- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
|
-- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
|
||||||
local servers = {
|
--
|
||||||
|
-- Feel free to add/remove any LSPs here that you want to install via Mason. They will automatically be installed and setup.
|
||||||
|
mason = {
|
||||||
-- clangd = {},
|
-- clangd = {},
|
||||||
-- gopls = {},
|
-- gopls = {},
|
||||||
-- pyright = {},
|
-- pyright = {},
|
||||||
|
@ -683,7 +691,6 @@ require('lazy').setup({
|
||||||
-- But for many setups, the LSP (`ts_ls`) will work just fine
|
-- But for many setups, the LSP (`ts_ls`) will work just fine
|
||||||
-- ts_ls = {},
|
-- ts_ls = {},
|
||||||
--
|
--
|
||||||
|
|
||||||
lua_ls = {
|
lua_ls = {
|
||||||
-- cmd = { ... },
|
-- cmd = { ... },
|
||||||
-- filetypes = { ... },
|
-- filetypes = { ... },
|
||||||
|
@ -698,6 +705,12 @@ require('lazy').setup({
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
-- This table contains config for all language servers that are *not* installed via Mason.
|
||||||
|
-- Structure is identical to the mason table from above.
|
||||||
|
others = {
|
||||||
|
-- dartls = {},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Ensure the servers and tools above are installed
|
-- Ensure the servers and tools above are installed
|
||||||
|
@ -713,26 +726,31 @@ require('lazy').setup({
|
||||||
--
|
--
|
||||||
-- You can add other tools here that you want Mason to install
|
-- You can add other tools here that you want Mason to install
|
||||||
-- for you, so that they are available from within Neovim.
|
-- for you, so that they are available from within Neovim.
|
||||||
local ensure_installed = vim.tbl_keys(servers or {})
|
local ensure_installed = vim.tbl_keys(servers.mason or {})
|
||||||
vim.list_extend(ensure_installed, {
|
vim.list_extend(ensure_installed, {
|
||||||
'stylua', -- Used to format Lua code
|
'stylua', -- Used to format Lua code
|
||||||
})
|
})
|
||||||
require('mason-tool-installer').setup { ensure_installed = ensure_installed }
|
require('mason-tool-installer').setup { ensure_installed = ensure_installed }
|
||||||
|
|
||||||
|
-- Either merge all additional server configs from the `servers.mason` and `servers.others` tables
|
||||||
|
-- to the default language server configs as provided by nvim-lspconfig or
|
||||||
|
-- define a custom server config that's unavailable on nvim-lspconfig.
|
||||||
|
for server, config in pairs(vim.tbl_extend('keep', servers.mason, servers.others)) do
|
||||||
|
if vim.fn.empty(config) ~= 1 then
|
||||||
|
vim.lsp.config(server, config)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- After configuring our language servers, we now enable them
|
||||||
require('mason-lspconfig').setup {
|
require('mason-lspconfig').setup {
|
||||||
ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer)
|
ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer)
|
||||||
automatic_installation = false,
|
automatic_enable = true, -- automatically run vim.lsp.enable() for all servers that are installed via Mason
|
||||||
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,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- Manually run vim.lsp.enable for all language servers that are *not* installed via Mason
|
||||||
|
if vim.fn.empty(servers.others) ~= 1 then
|
||||||
|
vim.lsp.enable(vim.tbl_keys(servers.others))
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -899,7 +917,12 @@ require('lazy').setup({
|
||||||
},
|
},
|
||||||
|
|
||||||
-- Highlight todo, notes, etc in comments
|
-- Highlight todo, notes, etc in comments
|
||||||
{ 'folke/todo-comments.nvim', event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim' }, opts = { signs = false } },
|
{
|
||||||
|
'folke/todo-comments.nvim',
|
||||||
|
event = 'VimEnter',
|
||||||
|
dependencies = { 'nvim-lua/plenary.nvim' },
|
||||||
|
opts = { signs = false },
|
||||||
|
},
|
||||||
|
|
||||||
{ -- Collection of various small independent plugins/modules
|
{ -- Collection of various small independent plugins/modules
|
||||||
'echasnovski/mini.nvim',
|
'echasnovski/mini.nvim',
|
||||||
|
@ -944,7 +967,19 @@ 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 = {
|
||||||
ensure_installed = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' },
|
ensure_installed = {
|
||||||
|
'bash',
|
||||||
|
'c',
|
||||||
|
'diff',
|
||||||
|
'html',
|
||||||
|
'lua',
|
||||||
|
'luadoc',
|
||||||
|
'markdown',
|
||||||
|
'markdown_inline',
|
||||||
|
'query',
|
||||||
|
'vim',
|
||||||
|
'vimdoc',
|
||||||
|
},
|
||||||
-- Autoinstall languages that are not installed
|
-- Autoinstall languages that are not installed
|
||||||
auto_install = true,
|
auto_install = true,
|
||||||
highlight = {
|
highlight = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue