2024-01-21 21:52:43 +00:00
|
|
|
-- note: diagnostics are not exclusive to lsp servers
|
|
|
|
-- so these can be global keybindings
|
|
|
|
vim.keymap.set('n', 'gl', '<cmd>lua vim.diagnostic.open_float()<cr>')
|
|
|
|
vim.keymap.set('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<cr>')
|
|
|
|
vim.keymap.set('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<cr>')
|
|
|
|
|
|
|
|
vim.api.nvim_create_autocmd('LspAttach', {
|
|
|
|
desc = 'LSP actions',
|
|
|
|
callback = function(event)
|
|
|
|
local opts = {buffer = event.buf}
|
|
|
|
|
|
|
|
-- these will be buffer-local keybindings
|
|
|
|
-- because they only work if you have an active language server
|
|
|
|
|
2024-01-22 13:36:34 +00:00
|
|
|
vim.keymap.set('n', '<leader>mh', '<cmd>lua vim.lsp.buf.hover()<cr>', opts)
|
|
|
|
vim.keymap.set('n', '<leader>mgd', '<cmd>lua vim.lsp.buf.definition()<cr>', opts)
|
|
|
|
vim.keymap.set('n', '<leader>mgD', '<cmd>lua vim.lsp.buf.declaration()<cr>', opts)
|
|
|
|
vim.keymap.set('n', '<leader>mgi', '<cmd>lua vim.lsp.buf.implementation()<cr>', opts)
|
|
|
|
vim.keymap.set('n', '<leader>mgo', '<cmd>lua vim.lsp.buf.type_definition()<cr>', opts)
|
|
|
|
vim.keymap.set('n', '<leader>mgr', '<cmd>lua vim.lsp.buf.references()<cr>', opts)
|
|
|
|
vim.keymap.set('n', '<leader>mgs', '<cmd>lua vim.lsp.buf.signature_help()<cr>', opts)
|
|
|
|
vim.keymap.set('n', '<leader>mr', '<cmd>lua vim.lsp.buf.rename()<cr>', opts)
|
|
|
|
vim.keymap.set({'n', 'x'}, '<leader>mf', '<cmd>lua vim.lsp.buf.format({async = true})<cr>', opts)
|
|
|
|
vim.keymap.set('n', '<leader>ma', '<cmd>lua vim.lsp.buf.code_action()<cr>', opts)
|
2024-01-21 21:52:43 +00:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
local lsp_capabilities = require('cmp_nvim_lsp').default_capabilities()
|
|
|
|
|
|
|
|
local default_setup = function(server)
|
|
|
|
require('lspconfig')[server].setup({
|
|
|
|
capabilities = lsp_capabilities,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
require('mason').setup({})
|
|
|
|
require('mason-lspconfig').setup({
|
|
|
|
ensure_installed = {},
|
|
|
|
handlers = {
|
|
|
|
default_setup,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
local cmp = require('cmp')
|
|
|
|
|
|
|
|
cmp.setup({
|
|
|
|
sources = {
|
|
|
|
{name = 'nvim_lsp'},
|
|
|
|
},
|
|
|
|
mapping = cmp.mapping.preset.insert({
|
|
|
|
-- Enter key confirms completion item
|
|
|
|
['<CR>'] = cmp.mapping.confirm({select = false}),
|
|
|
|
|
|
|
|
-- Ctrl + space triggers completion menu
|
|
|
|
['<C-Space>'] = cmp.mapping.complete(),
|
|
|
|
}),
|
|
|
|
snippet = {
|
|
|
|
expand = function(args)
|
|
|
|
require('luasnip').lsp_expand(args.body)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
})
|