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:
parent
d1b0dfe112
commit
ce9f101024
1 changed files with 22 additions and 11 deletions
|
@ -37,8 +37,25 @@ lsp.on_attach(function(client, bufnr)
|
|||
{ buffer = bufnr, desc = 'Codeactions' })
|
||||
map('n', '<localleader>ln', '<cmd>lua vim.lsp.buf.rename()<cr>',
|
||||
{ buffer = bufnr, desc = 'Rename element' })
|
||||
map('n', '<localleader>lr', '<cmd>lua vim.lsp.buf.references()<cr>',
|
||||
{ buffer = bufnr, desc = 'References' })
|
||||
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>',
|
||||
{ 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
|
||||
map('n', '<localleader>lf', "<cmd>lua vim.lsp.buf.formatting()<CR>",
|
||||
{ buffer = bufnr, desc = 'Format document' })
|
||||
|
@ -46,23 +63,17 @@ lsp.on_attach(function(client, bufnr)
|
|||
|
||||
map('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>',
|
||||
{ buffer = bufnr, desc = 'Hover definition' })
|
||||
map('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>',
|
||||
{ buffer = bufnr, desc = 'Definition' })
|
||||
map('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>',
|
||||
map('n', '<localleader>lc', '<cmd>lua vim.lsp.buf.declaration()<cr>',
|
||||
{ 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' })
|
||||
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)
|
||||
lsp.nvim_workspace()
|
||||
-- ensure python virtualenv is determined automatically on lsp start
|
||||
lsp.configure("pyright", {
|
||||
on_attach = function(client, _)
|
||||
local python_path, msg = require('util.pyenv').get_path(client.config
|
||||
.root_dir)
|
||||
.root_dir)
|
||||
vim.notify(string.format('%s\n%s', msg, python_path))
|
||||
client.config.settings.python.pythonPath = python_path
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue