nvimdotfiles/after/plugin/lsp/lsp-common.lua
2023-12-30 12:16:42 +01:00

27 lines
1.5 KiB
Lua

vim.api.nvim_create_autocmd('LspAttach', {
callback = function(ev)
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>gr', builtin.lsp_references);
local opts = { noremap = true, silent = false, buffer = ev.buf }
vim.keymap.set('n', '<leader>ci', vim.lsp.buf.incoming_calls, opts);
vim.keymap.set('n', '<leader>gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
vim.keymap.set('n', '<leader>ga', '<Cmd>lua vim.lsp.buf.code_action()<CR>', opts)
vim.keymap.set('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
vim.keymap.set('n', '<leader>gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
vim.keymap.set('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
vim.keymap.set('n', '<leader>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
vim.keymap.set('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
vim.keymap.set('n', '<leader>eb', '<cmd>lua vim.diagnostic.open_float({scope="buffer"})<CR>', opts)
vim.keymap.set('n', '<leader>el', '<cmd>lua vim.diagnostic.open_float({scope="line"})<CR>', opts)
vim.keymap.set('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
vim.keymap.set('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
vim.keymap.set('n', '<leader>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
vim.keymap.set('n', '<leader>gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', '<leader>fo', function()
vim.lsp.buf.format { async = true }
end, opts)
end,
})