nvim: use Buffer.Lsp key binds in psoxizsh.lsp.key

This commit is contained in:
Paul Stemmet 2024-08-18 13:31:46 +00:00
parent f22a04f130
commit 69a424a081
Signed by: Paul Stemmet
GPG Key ID: EDEA539F594E7E75
1 changed files with 43 additions and 19 deletions

View File

@ -1,30 +1,54 @@
-- Keys for LSP on_attach functionality
--
-- These are for generic / language server independent functions, see the below
-- link for how to add key binds for specific LSPs.
--
-- https://www.lazyvim.org/configuration/keymaps#lsp-server-keymaps
local function rebind(args)
local target, bind = args[1], args[2]
-- Do nothing if given a nil bind
if type(bind) == 'nil' then return end
-- Disable (but keep) the bind if given a false bind
if type(bind) == 'boolean' and not bind then
target[2] = false ; return
end
-- Otherwise, set key pattern and description
target[1] = bind.Key
if bind.Desc then target.desc = bind.Desc end
end
return {
{ 'neovim/nvim-lspconfig',
opts = function(_, _)
local keys = require('psoxizsh.key.binds').Buffer.Lsp
local K = require("lazyvim.plugins.lsp.keymaps").get()
-- So this is a bit obtuse to set, because we have to match the order
-- provided by LazyVim, see the following for the offsets
-- https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/plugins/lsp/keymaps.lua#L15
K[1][1] = '<leader>Ci' -- 'Lsp Info'
K[2][1] = 'gd' -- 'Goto Definition'
K[3][1] = 'gr' -- 'References'
K[4][1] = 'gI' -- 'Goto Implementation'
K[5][1] = 'gT' ; K[5].desc = 'Goto Type Definition'
K[6][1] = 'gD' -- 'Goto Declaration'
K[7][1] = 'K' -- 'Hover'
K[8][1] = 'gS' -- 'Signature Help'
K[9][2] = false -- 'Signature Help' (disable insert mode map)
K[10][1] = '<leader>.' -- 'Code Action'
K[11][1] = '<leader>r>' -- 'Run Codelens'
K[12][1] = '<leader>>' -- 'Refresh & Display Codelens'
K[13][1] = '<leader>rF' -- 'Rename File'
K[14][1] = '<leader>rn' -- 'Rename'
K[15][1] = '<leader>Ca' -- 'Source Action'
K[16][1] = ']]' -- 'Next Reference'
K[17][1] = '[[' -- 'Prev Reference'
K[18][2] = false -- 'Next Reference' (disable alt map)
K[19][2] = false -- 'Prev Reference' (disable alt map)
rebind { K[1], keys.LspInfo } -- 'Lsp Info'
rebind { K[2], keys.GotoDefinition } -- 'Goto Definition'
rebind { K[3], keys.ShowReferences } -- 'References'
rebind { K[4], keys.GotoImplementation } -- 'Goto Implementation'
rebind { K[5], keys.GotoTypeDefinition } -- 'Goto Type Definition'
rebind { K[6], keys.GotoDeclaration } -- 'Goto Declaration'
rebind { K[7], keys.ShowDocumentation } -- 'Hover'
rebind { K[8], keys.ShowSignature } -- 'Signature Help'
rebind { K[9], false } -- 'Signature Help' (disable insert mode map)
rebind { K[10], keys.CodeAction } -- 'Code Action'
rebind { K[11], keys.CodelensRun } -- 'Run Codelens'
rebind { K[12], keys.CodelensDisplay } -- 'Refresh & Display Codelens'
rebind { K[13], keys.RenameFile } -- 'Rename File'
rebind { K[14], keys.RenameSymbol } -- 'Rename'
rebind { K[15], keys.SourceAction } -- 'Source Action'
rebind { K[16], keys.ReferenceNext } -- 'Next Reference'
rebind { K[17], keys.ReferencePrev } -- 'Prev Reference'
rebind { K[18], false } -- 'Next Reference' (disable alt map)
rebind { K[19], false } -- 'Prev Reference' (disable alt map)
end
},
}