nvim: Unify lsp mappings into local +l prefix

Whereas previously we had lsp-related mappings both on <localleader>l...
and g... mappings, they are now all unified under the <localleader>l
prefix group. Some mnemonics unfortunately had to give way to a weaker
version of themselves (definition becomes de[f]inition, implementation
becomes i[m]plementation) but overall I believe this to be much more
cohesive for my future lsp usage. With which-key enabled and everything
under the +l group we should be able to easily adapt to the new
mappings.

Additionally, some mappings will invoke the telescope version of their
lsp command if telescope is indeed installed, otherwise fall back to the
native neovim lsp implementation.
This commit is contained in:
Marty Oehme 2023-03-22 10:22:34 +01:00
parent d1b0dfe112
commit ce9f101024
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A

View file

@ -37,8 +37,25 @@ lsp.on_attach(function(client, bufnr)
{ buffer = bufnr, desc = 'Codeactions' }) { buffer = bufnr, desc = 'Codeactions' })
map('n', '<localleader>ln', '<cmd>lua vim.lsp.buf.rename()<cr>', map('n', '<localleader>ln', '<cmd>lua vim.lsp.buf.rename()<cr>',
{ buffer = bufnr, desc = 'Rename element' }) { buffer = bufnr, desc = 'Rename element' })
if vim.fn.exists(':Telescope') then
map('n', '<localleader>lr', '<cmd>Telescope lsp_references()<cr>',
{ buffer = bufnr, desc = 'References' })
map('n', '<localleader>lf', '<cmd>Telescope lsp_definitions<cr>',
{ buffer = bufnr, desc = 'Definition' })
map('n', '<localleader>lt', '<cmd>Telescope lsp_type_definitions<cr>',
{ buffer = bufnr, desc = 'Type definition' })
map('n', '<localleader>lm', '<cmd>Telescope lsp_implementations<cr>',
{ buffer = bufnr, desc = 'Implementation' })
else
map('n', '<localleader>lr', '<cmd>lua vim.lsp.buf.references()<cr>', map('n', '<localleader>lr', '<cmd>lua vim.lsp.buf.references()<cr>',
{ buffer = bufnr, desc = 'References' }) { buffer = bufnr, desc = 'References' })
map('n', '<localleader>lf', '<cmd>lua vim.lsp.buf.definition()<cr>',
{ buffer = bufnr, desc = 'Definition' })
map('n', '<localleader>lt', '<cmd>lua vim.lsp.buf.type_definition()<cr>',
{ buffer = bufnr, desc = 'Type definition' })
map('n', '<localleader>lm', '<cmd>lua vim.lsp.buf.implementation()<cr>',
{ buffer = bufnr, desc = 'Implementation' })
end
if client.server_capabilities.document_formatting then if client.server_capabilities.document_formatting then
map('n', '<localleader>lf', "<cmd>lua vim.lsp.buf.formatting()<CR>", map('n', '<localleader>lf', "<cmd>lua vim.lsp.buf.formatting()<CR>",
{ buffer = bufnr, desc = 'Format document' }) { buffer = bufnr, desc = 'Format document' })
@ -46,16 +63,10 @@ lsp.on_attach(function(client, bufnr)
map('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>', map('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>',
{ buffer = bufnr, desc = 'Hover definition' }) { buffer = bufnr, desc = 'Hover definition' })
map('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>', map('n', '<localleader>lc', '<cmd>lua vim.lsp.buf.declaration()<cr>',
{ buffer = bufnr, desc = 'Definition' })
map('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>',
{ buffer = bufnr, desc = 'Declaration' }) { buffer = bufnr, desc = 'Declaration' })
map('n', 'gs', '<cmd>lua vim.lsp.buf.signature_help()<cr>', map('n', '<localleader>ls', '<cmd>lua vim.lsp.buf.signature_help()<cr>',
{ buffer = bufnr, desc = 'Signature help' }) { buffer = bufnr, desc = 'Signature help' })
map('n', 'gI', '<cmd>lua vim.lsp.buf.implementation()<cr>',
{ buffer = bufnr, desc = 'Implementation' })
map('n', 'gt', '<cmd>lua vim.lsp.buf.type_definition()<cr>',
{ buffer = bufnr, desc = 'Type definition' })
end) end)
lsp.nvim_workspace() lsp.nvim_workspace()
-- ensure python virtualenv is determined automatically on lsp start -- ensure python virtualenv is determined automatically on lsp start