64 lines
2.5 KiB
Lua
64 lines
2.5 KiB
Lua
return {
|
|
{
|
|
'mason-org/mason.nvim', -- manage lsp
|
|
config = function()
|
|
require('mason').setup()
|
|
end,
|
|
},
|
|
{
|
|
'mason-org/mason-lspconfig.nvim', -- bridge mason with lspconfig
|
|
config = function()
|
|
local on_attach = function(client, bufnr)
|
|
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
|
|
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
|
|
|
|
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
|
|
|
|
local opts = { noremap = true, silent = true }
|
|
|
|
-- Raccourcis LSP
|
|
buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
|
|
buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
|
|
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
|
|
buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
|
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
|
|
buf_set_keymap('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
|
buf_set_keymap('n', '<leader>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
|
|
end
|
|
|
|
-- Configuration automatique pour TOUS les serveurs installés
|
|
require('mason-lspconfig').setup({
|
|
handlers = {
|
|
-- Handler par défaut pour tous les serveurs
|
|
function(server_name)
|
|
require("lspconfig")[server_name].setup({
|
|
on_attach = on_attach,
|
|
capabilities = require('cmp_nvim_lsp').default_capabilities(),
|
|
})
|
|
end,
|
|
}
|
|
})
|
|
|
|
-- Configuration globale des raccourcis LSP (au cas où on_attach ne fonctionne pas)
|
|
vim.api.nvim_create_autocmd("LspAttach", {
|
|
callback = function(args)
|
|
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
|
local bufnr = args.buf
|
|
|
|
print("LspAttach autocmd triggered for: " .. client.name) -- Debug
|
|
|
|
local opts = { noremap = true, silent = true, buffer = bufnr }
|
|
|
|
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
|
|
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
|
|
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
|
|
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
|
|
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
|
|
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts)
|
|
vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, opts)
|
|
end,
|
|
})
|
|
end
|
|
}
|
|
}
|