nvim: add LSP keymappings

This commit is contained in:
tea 2024-09-03 20:14:03 +02:00
parent 9a253eeaf0
commit ce4133afa2
No known key found for this signature in database

View File

@ -1,7 +1,28 @@
local map = require('my.functions').map local map = require('my.functions').map
local on_attach = function(client, bufnr) local on_attach = function(client, bufnr)
-- TODO: key mappings map('n', '<f5>', vim.diagnostic.goto_prev, 'Prev diagnostic', bufnr)
map('n', '<f6>', vim.diagnostic.goto_next, 'Next diagnostic', bufnr)
map('n', 'gD', vim.lsp.buf.declaration, 'Go to declaration', bufnr)
map('n', 'gd', vim.lsp.buf.definition, 'Go to definition', bufnr)
map('n', '<M-.>', vim.lsp.buf.definition, 'Go to definition', bufnr)
map('n', 'gi', vim.lsp.buf.implementation, 'Go to implementation',
bufnr)
map('n', 'gr', vim.lsp.buf.references, 'Show references', bufnr)
map('n', 'K', vim.lsp.buf.hover, 'Hover', bufnr)
map('i', '<C-K>', vim.lsp.buf.hover, 'Hover', bufnr)
require('which-key').add({{ '<Leader>l', group = 'LSP' }})
require('which-key').add({{ '<Leader>lw', group = 'workspace' }})
map('n', '<Leader>lwa', vim.lsp.buf.add_workspace_folder,
'Add workspace folder', bufnr)
map('n', '<Leader>lwr', vim.lsp.buf.remove_workspace_folder,
'Remove workspace folder', bufnr)
map('n', '<Leader>lwl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, 'List workspace folders', bufnr)
map('n', '<Leader>lr', vim.lsp.buf.rename, 'Rename symbol', bufnr)
map('n', '<Leader>la', vim.lsp.buf.code_action, 'Code action', bufnr)
map('n', '<Leader>lf', vim.lsp.buf.format, 'Format buffer', bufnr)
if client.server_capabilities.documentHighlightProvider then if client.server_capabilities.documentHighlightProvider then
vim.api.nvim_create_augroup('config_lsp', { clear = false }) vim.api.nvim_create_augroup('config_lsp', { clear = false })