neovim-config/lua/plugins/lsp.lua

180 lines
6.3 KiB
Lua
Raw Normal View History

2025-10-22 06:57:49 +02:00
return {
{
"williamboman/mason.nvim",
build = ":MasonUpdate",
config = function()
require("mason").setup()
end,
},
-- Mason-LSPconfig : Intégration avec les serveurs LSP
{
"williamboman/mason-lspconfig.nvim",
config = function()
require("mason-lspconfig").setup({
ensure_installed = { "clangd","pyright", "lua_ls", "marksman", "ruff" },
})
2025-10-22 08:04:10 +02:00
pcall(require("mason-tool-installer").setup, {
ensure_installed = {},
auto_update = false,
run_on_start = false,
})
2025-10-22 06:57:49 +02:00
end,
},
-- LSP Config : Configuration des serveurs LSP
{
"neovim/nvim-lspconfig",
config = function()
local lspconfig = require("lspconfig")
local capabilities = require('cmp_nvim_lsp').default_capabilities()
local navic = require("nvim-navic")
local on_attach = function(client, bufnr)
if client.server_capabilities.documentSymbolProvider then
navic.attach(client, bufnr) -- Attache Navic au LSP
end
end
-- Cpp
lspconfig.clangd.setup({
capabilities = capabilities,
})
-- Python
lspconfig.pyright.setup({
on_attach = on_attach,
})
-- Lua
lspconfig.lua_ls.setup({
on_attach = on_attach,
settings = {
Lua = {
diagnostics = { globals = { "vim" } },
workspace = { library = vim.api.nvim_get_runtime_file("", true) },
},
},
})
-- Markdown & reStructuredText
lspconfig.marksman.setup({})
local navic = require("nvim-navic")
-- Exemple avec Pyright
require("lspconfig").pyright.setup({
on_attach = function(client, bufnr)
if client.server_capabilities.documentSymbolProvider then
navic.attach(client, bufnr) -- Attache Navic au LSP
end
end,
})
end,
},
{
"L3MON4D3/LuaSnip",
build = "make install_jsregexp",
config = function()
require("luasnip.loaders.from_vscode").lazy_load()
end,
},
-- nvim-cmp : Moteur dautocomplétion
{
"hrsh7th/nvim-cmp",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
"L3MON4D3/LuaSnip",
"saadparwaiz1/cmp_luasnip",
},
config = function()
local cmp = require("cmp")
local luasnip = require("luasnip")
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = {
-- Comportement intelligent pour Tab
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item() -- Sélectionne l'élément suivant si le menu est ouvert
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump() -- Passe au placeholder suivant si dans un snippet
else
fallback() -- Sinon, insère une tabulation normale
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item() -- Sélectionne l'élément précédent si le menu est ouvert
elseif luasnip.jumpable(-1) then
luasnip.jump(-1) -- Passe au placeholder précédent si dans un snippet
else
fallback() -- Sinon, insère une tabulation normale
end
end, { "i", "s" }),
-- Comportement pour Entrée
["<CR>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.confirm({ select = true }) -- Confirme la sélection
elseif luasnip.jumpable(1) then
luasnip.jump(1) -- Passe au placeholder suivant dans un snippet
else
fallback() -- Sinon, insère une nouvelle ligne
end
end, { "i", "s" }),
},
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "buffer" },
{ name = "path" },
}),
})
end,
},
-- black : Formatage de python
{
"psf/black",
ft = { "python" },
build = ":BlackUpgrade",
},
{
"jose-elias-alvarez/null-ls.nvim",
dependencies = { "nvim-lua/plenary.nvim" },
config = function()
local null_ls = require("null-ls")
null_ls.setup({
sources = {
null_ls.builtins.formatting.clang_format.with({
filetypes = { "cpp", "c", "objc", "objcpp" }, -- Limiter aux langages supportés
}),
},
-- Optionnel : configurer un mapping ou autoformat
on_attach = function(client, bufnr)
if client.supports_method("textDocument/formatting") then
local group = vim.api.nvim_create_augroup("LspFormatting", { clear = true })
vim.api.nvim_create_autocmd("BufWritePre", {
group = group,
buffer = bufnr,
callback = function()
vim.lsp.buf.format({ bufnr = bufnr })
end,
})
end
end,
})
end,
},
}