plugins: rewrite the LSP configuration
- Rewrites the LSP configuration to neovim v0.11+ capabilities in the mason.lua file. - Adapts the completion configuration accordingly. - Removes lsp-zero unnecessary plugin. - Removes the nvim-lsp-file-operations plugin that I never use. - I have been helped by the Kimi language model provided by the Kagi assistant interface. Co-Authored-by: iGor milhit <igor@milhit.ch>
parent
21bb2a4393
commit
e06c86d9af
|
|
@ -1,10 +0,0 @@
|
||||||
-- Install lsp-zero, to ease LSP support configuration
|
|
||||||
-- https://lsp-zero.netlify.app
|
|
||||||
-- https://github.com/VonHeikemen/lsp-zero.nvim/
|
|
||||||
|
|
||||||
return {
|
|
||||||
"VonHeikemen/lsp-zero.nvim",
|
|
||||||
branch = "v4.x",
|
|
||||||
lazy = true,
|
|
||||||
config = false,
|
|
||||||
}
|
|
||||||
|
|
@ -6,155 +6,21 @@ return {
|
||||||
dependencies = {
|
dependencies = {
|
||||||
-- Send LSP results to autocompletion nvim-cmp
|
-- Send LSP results to autocompletion nvim-cmp
|
||||||
"hrsh7th/cmp-nvim-lsp",
|
"hrsh7th/cmp-nvim-lsp",
|
||||||
-- Adds code actions, such as smart file renaming, etc
|
|
||||||
{ "antosha417/nvim-lsp-file-operations", config = true },
|
|
||||||
-- 💫 Extensible UI for Neovim notifications and LSP progress messages
|
-- 💫 Extensible UI for Neovim notifications and LSP progress messages
|
||||||
{ 'j-hui/fidget.nvim', tag = "legacy", opts = {} },
|
{ 'j-hui/fidget.nvim', tag = "legacy", opts = {} },
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
-- Import lsp-zero
|
|
||||||
local lsp_zero = require("lsp-zero")
|
|
||||||
|
|
||||||
-- Activate some functionalities when a LSP is activated to the current
|
vim.diagnostic.config({
|
||||||
-- file
|
signs = {
|
||||||
local lsp_attach = function(_, bufnr)
|
text = {
|
||||||
local opts = { buffer = bufnr, silent = true }
|
[vim.diagnostic.severity.ERROR] = " ",
|
||||||
|
[vim.diagnostic.severity.WARN] = " ",
|
||||||
-- Keymaps
|
[vim.diagnostic.severity.HINT] = " ",
|
||||||
|
[vim.diagnostic.severity.INFO] = " ",
|
||||||
opts.desc = "[LSP] Show LSP references"
|
}
|
||||||
vim.keymap.set(
|
}
|
||||||
"n",
|
|
||||||
"gR",
|
|
||||||
"<cmd>Telescope lsp_references<CR>",
|
|
||||||
opts
|
|
||||||
)
|
|
||||||
|
|
||||||
opts.desc = "[LSP] Go to declaration"
|
|
||||||
vim.keymap.set(
|
|
||||||
"n",
|
|
||||||
"gD",
|
|
||||||
vim.lsp.buf.declaration,
|
|
||||||
opts
|
|
||||||
)
|
|
||||||
|
|
||||||
opts.desc = "[LSP] Show LSP definitions"
|
|
||||||
vim.keymap.set(
|
|
||||||
"n",
|
|
||||||
"gd",
|
|
||||||
"<cmd>Telescope lsp_definitions<CR>",
|
|
||||||
opts
|
|
||||||
)
|
|
||||||
|
|
||||||
opts.desc = "[LSP] Show LSP implementations"
|
|
||||||
vim.keymap.set(
|
|
||||||
"n",
|
|
||||||
"gi",
|
|
||||||
"<cmd>Telescope lsp_implementations<CR>",
|
|
||||||
opts
|
|
||||||
)
|
|
||||||
|
|
||||||
opts.desc = "[LSP] Show LSP type definitions"
|
|
||||||
vim.keymap.set(
|
|
||||||
"n",
|
|
||||||
"gt",
|
|
||||||
"<cmd>Telescope lsp_type_definitions<CR>",
|
|
||||||
opts
|
|
||||||
)
|
|
||||||
|
|
||||||
opts.desc = "[LSP] Show LSP signature help"
|
|
||||||
vim.keymap.set(
|
|
||||||
"n",
|
|
||||||
"gs",
|
|
||||||
vim.lsp.buf.signature_help,
|
|
||||||
opts
|
|
||||||
)
|
|
||||||
|
|
||||||
opts.desc = "[LSP] See available code actions"
|
|
||||||
vim.keymap.set(
|
|
||||||
{ "n", "v" },
|
|
||||||
"<leader>ca",
|
|
||||||
vim.lsp.buf.code_action,
|
|
||||||
opts
|
|
||||||
)
|
|
||||||
|
|
||||||
opts.desc = "[LSP] Smart rename"
|
|
||||||
vim.keymap.set(
|
|
||||||
"n",
|
|
||||||
"<leader>rn",
|
|
||||||
vim.lsp.buf.rename,
|
|
||||||
opts
|
|
||||||
)
|
|
||||||
|
|
||||||
opts.desc = "[LSP] Show buffer diagnostics"
|
|
||||||
vim.keymap.set(
|
|
||||||
"n",
|
|
||||||
"<leader>D",
|
|
||||||
"<cmd>Telescope diagnostics bufnr=0<CR>",
|
|
||||||
opts
|
|
||||||
)
|
|
||||||
|
|
||||||
opts.desc = "[LSP] Show line diagnostics"
|
|
||||||
vim.keymap.set(
|
|
||||||
"n",
|
|
||||||
"<leader>d",
|
|
||||||
vim.diagnostic.open_float,
|
|
||||||
opts
|
|
||||||
)
|
|
||||||
|
|
||||||
opts.desc = "[LSP] Go to previous diagnostic"
|
|
||||||
vim.keymap.set("n", "[d", function()
|
|
||||||
vim.diagnostic.jump({ count = -1, float = true })
|
|
||||||
end, opts) -- jump to previous diagnostic in buffer
|
|
||||||
|
|
||||||
opts.desc = "[LSP] Go to next diagnostic"
|
|
||||||
vim.keymap.set("n", "]d", function()
|
|
||||||
vim.diagnostic.jump({ count = 1, float = true })
|
|
||||||
end, opts) -- jump to next diagnostic in buffer
|
|
||||||
|
|
||||||
opts.desc = "[LSP] Show documentation for what is under cursor"
|
|
||||||
vim.keymap.set(
|
|
||||||
"n",
|
|
||||||
"K",
|
|
||||||
vim.lsp.buf.hover,
|
|
||||||
opts
|
|
||||||
)
|
|
||||||
|
|
||||||
opts.desc = "[LSP] Format buffer"
|
|
||||||
vim.keymap.set(
|
|
||||||
{ "n", "x" },
|
|
||||||
"F",
|
|
||||||
"<cmd>lua vim.lsp.buf.format({async = true})<cr>",
|
|
||||||
opts
|
|
||||||
)
|
|
||||||
|
|
||||||
opts.desc = "[LSP] Restart LSP"
|
|
||||||
vim.keymap.set(
|
|
||||||
"n",
|
|
||||||
"<leader>rs",
|
|
||||||
":LspRestart<CR>",
|
|
||||||
opts
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
lsp_zero.extend_lspconfig({
|
|
||||||
-- Display diagnostic signs in the sign column
|
|
||||||
sign_text = true,
|
|
||||||
-- Attach the keymap function
|
|
||||||
lsp_attach = lsp_attach,
|
|
||||||
-- Extend the default completion capabilities by LSP suggestions
|
|
||||||
capabilities = require("cmp_nvim_lsp").default_capabilities(),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Use lsp_zero to configure interface
|
|
||||||
lsp_zero.ui({
|
|
||||||
float_border = "rounded",
|
|
||||||
sign_text = {
|
|
||||||
error = " ",
|
|
||||||
warn = " ",
|
|
||||||
hint = " ",
|
|
||||||
info = " ",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,129 +1,67 @@
|
||||||
-- Install and configure mason.nvim which will install automatically the needed
|
-- New LSP configuration (since neovim 0.11+)
|
||||||
-- LSP
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"mason-org/mason.nvim",
|
'mason-org/mason-lspconfig.nvim',
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"mason-org/mason-lspconfig.nvim",
|
'mason-org/mason.nvim',
|
||||||
"WhoIsSethDaniel/mason-tool-installer.nvim",
|
'neovim/nvim-lspconfig',
|
||||||
|
'WhoIsSethDaniel/mason-tool-installer.nvim',
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
-- Import mason
|
|
||||||
local mason = require("mason")
|
|
||||||
|
|
||||||
-- Import mason-lspconfig
|
require("mason").setup({
|
||||||
local mason_lspconfig = require("mason-lspconfig")
|
|
||||||
|
|
||||||
-- Import lspconfig
|
|
||||||
-- local lspconfig = require("lspconfig")
|
|
||||||
local lspconfig = vim.lsp.config
|
|
||||||
|
|
||||||
-- local util = require("lspconfig.util")
|
|
||||||
local util = vim.lsp.util
|
|
||||||
|
|
||||||
-- Import mason-tool-installer
|
|
||||||
local mason_tool_installer = require("mason-tool-installer")
|
|
||||||
|
|
||||||
-- Activate mason and set icones
|
|
||||||
mason.setup({
|
|
||||||
ui = {
|
ui = {
|
||||||
icons = {
|
icons = {
|
||||||
package_installed = "✓",
|
package_installed = "✓",
|
||||||
package_pending = "➜",
|
package_pending = "➜",
|
||||||
package_uninstalled = "✗",
|
package_uninstalled = "✗",
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
mason_tool_installer.setup({
|
require("mason-tool-installer").setup({
|
||||||
ensure_installed = {
|
ensure_installed = {
|
||||||
"prettier",
|
"prettier",
|
||||||
|
"ruff",
|
||||||
"stylua",
|
"stylua",
|
||||||
"tree-sitter-cli",
|
"tree-sitter-cli",
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
mason_lspconfig.setup({
|
require("mason-lspconfig").setup({
|
||||||
-- LSP to be installed by default
|
|
||||||
-- Available LSP: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
|
|
||||||
-- LSP can be installed with :Mason
|
|
||||||
-- But installing LSP through the following list is better
|
|
||||||
ensure_installed = {
|
ensure_installed = {
|
||||||
"cssls",
|
"cssls",
|
||||||
"html",
|
"html",
|
||||||
"jsonls",
|
"jsonls",
|
||||||
"lua_ls",
|
"lua_ls",
|
||||||
"marksman",
|
"marksman",
|
||||||
|
"ty",
|
||||||
"ruff",
|
"ruff",
|
||||||
"yamlls",
|
"yamlls",
|
||||||
},
|
},
|
||||||
handlers = {
|
|
||||||
-- Function called for each LSP from the ensure_installed list loaded
|
|
||||||
function(server_name)
|
|
||||||
-- Activate all LSP from the ensure_installed list with its default
|
|
||||||
-- configuration
|
|
||||||
lspconfig[server_name].setup({})
|
|
||||||
end,
|
|
||||||
|
|
||||||
-- Then, configure each LSP as needed
|
|
||||||
-- See https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
|
|
||||||
--
|
|
||||||
-- To deactivate a LSP:
|
|
||||||
-- lsp_name = require("lsp-zero").noop,
|
|
||||||
|
|
||||||
-- The LSP name before`= function()` has to be the same than after
|
|
||||||
-- `lspconfig.`
|
|
||||||
-- The first one is the mason_lspconfig key, the seconde one is the
|
|
||||||
-- lspconfig key. They are identical to the ensure_installed entries.
|
|
||||||
|
|
||||||
ruff = function()
|
|
||||||
lspconfig.ruff.setup({
|
|
||||||
setting = {
|
|
||||||
},
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
|
|
||||||
lua_ls = function()
|
|
||||||
lspconfig.lua_ls.setup({
|
|
||||||
settings = {
|
|
||||||
Lua = {
|
|
||||||
diagnostics = {
|
|
||||||
-- Force LSP to recognize global variable `vim`.
|
|
||||||
globals = { "vim" },
|
|
||||||
disable = { "missing-fields" },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
|
|
||||||
jsonls = function()
|
|
||||||
lspconfig.jsonls.setup({
|
|
||||||
settings = {
|
|
||||||
json = {
|
|
||||||
schemas = require("schemastore").json.schemas(),
|
|
||||||
validate = { enable = true },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
|
|
||||||
marksman = function()
|
|
||||||
lspconfig.marksman.setup({
|
|
||||||
setting = {
|
|
||||||
filetypes = {
|
|
||||||
"markdown",
|
|
||||||
"quarto",
|
|
||||||
},
|
|
||||||
root_dir = util.root_pattern(
|
|
||||||
'.git',
|
|
||||||
'.marksman.toml',
|
|
||||||
'_quarto.yml'
|
|
||||||
),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
end
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
end,
|
|
||||||
|
vim.lsp.config.marksman = {
|
||||||
|
filetypes = { "markdown", "quarto" },
|
||||||
|
root_dir = vim.fs.root(0, {
|
||||||
|
".git",
|
||||||
|
".marksman.toml",
|
||||||
|
"._quarto.yml"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
vim.lsp.config.jsonls = {
|
||||||
|
settings = {
|
||||||
|
json = {
|
||||||
|
schemas = require('schemastore').json.schemas(),
|
||||||
|
validate = { enable = true },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vim.lsp.config('*', {
|
||||||
|
capabilities = require('cmp_nvim_lsp').default_capabilities(),
|
||||||
|
})
|
||||||
|
|
||||||
|
end
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,8 @@ return {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ name = "path" },
|
{ name = "path" },
|
||||||
|
{ name = "ty" },
|
||||||
|
{ name = "ruff" },
|
||||||
{ name = "emoji" },
|
{ name = "emoji" },
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
@ -128,10 +130,14 @@ return {
|
||||||
nvim_lua = "[Lua]",
|
nvim_lua = "[Lua]",
|
||||||
lazydev = "[Lazydev]",
|
lazydev = "[Lazydev]",
|
||||||
path = "[Path]",
|
path = "[Path]",
|
||||||
|
ty = "[Ty]",
|
||||||
|
ruff = "[Ruff]",
|
||||||
emoji = "[Emoji]",
|
emoji = "[Emoji]",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
end,
|
end,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue