dotfiles.pub/_config/nvim/plugin/lsp.lua
2025-09-07 01:30:45 +02:00

56 lines
1.8 KiB
Lua

vim.lsp.enable('ts_ls')
vim.lsp.enable('luals')
vim.lsp.enable('clangd')
-- LSP keymaps to mimic lsp-zero's defaults
-- Source for lsp-zero defaults: see note at bottom
-- Create the autocommand once
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspKeymaps', { clear = true }),
callback = function(ev)
local buf = ev.buf
local function map(mode, lhs, rhs, desc)
vim.keymap.set(mode, lhs, rhs, { buffer = buf, silent = true, noremap = true, desc = desc })
end
-- Hover
map('n', 'K', vim.lsp.buf.hover, 'LSP: Hover')
-- Go to...
map('n', 'gd', vim.lsp.buf.definition, 'LSP: Go to Definition')
map('n', 'gD', vim.lsp.buf.declaration, 'LSP: Go to Declaration')
map('n', 'gi', vim.lsp.buf.implementation, 'LSP: Go to Implementation')
map('n', 'go', vim.lsp.buf.type_definition, 'LSP: Go to Type Definition')
map('n', 'gr', vim.lsp.buf.references, 'LSP: List References')
-- Signatures
map('n', 'gs', vim.lsp.buf.signature_help, 'LSP: Signature Help')
-- Rename / Actions / Format (normal + visual)
map('n', '<F2>', vim.lsp.buf.rename, 'LSP: Rename')
map({ 'n', 'x' }, '<F3>', function()
vim.lsp.buf.format({ async = false })
end, 'LSP: Format')
map({ 'n', 'x' }, '<F4>', vim.lsp.buf.code_action, 'LSP: Code Action')
end,
})
require("mason").setup()
require("mason-lspconfig").setup({})
local cmp = require('cmp')
local cmp_nvim_lsp = require('cmp_nvim_lsp')
vim.opt.completeopt = { 'menu', 'menuone', 'noselect' }
cmp.setup({
sources = {
{ name = 'nvim_lsp' },
},
mapping = cmp.mapping.preset.insert({
['<CR>'] = cmp.mapping.confirm({ select = false }),
}),
})
cmp_nvim_lsp.default_capabilities()