fix(lsp): added a-n, a-p for document highlights and cycling. Closes #3320

This commit is contained in:
Folke Lemaitre
2024-05-26 16:03:13 +02:00
parent c9ab8224f5
commit b3373f3428
2 changed files with 38 additions and 28 deletions

View File

@ -3,8 +3,8 @@ local M = {}
---@type LazyKeysLspSpec[]|nil
M._keys = nil
---@alias LazyKeysLspSpec LazyKeysSpec|{has?:string}
---@alias LazyKeysLsp LazyKeys|{has?:string}
---@alias LazyKeysLspSpec LazyKeysSpec|{has?:string, cond?:fun():boolean}
---@alias LazyKeysLsp LazyKeys|{has?:string, cond?:fun():boolean}
---@return LazyKeysLspSpec[]
function M.get()
@ -40,8 +40,14 @@ function M.get()
desc = "Source Action",
has = "codeAction",
},
{ "]]", function() LazyVim.lsp.words.jump(vim.v.count1) end, has = "documentHighlight", desc = "Next Reference" },
{ "[[", function() LazyVim.lsp.words.jump(-vim.v.count1) end, has = "documentHighlight", desc = "Prev Reference" },
{ "]]", function() LazyVim.lsp.words.jump(vim.v.count1) end, has = "documentHighlight",
desc = "Next Reference", cond = function() return LazyVim.lsp.words.enabled end },
{ "[[", function() LazyVim.lsp.words.jump(-vim.v.count1) end, has = "documentHighlight",
desc = "Prev Reference", cond = function() return LazyVim.lsp.words.enabled end },
{ "<a-n>", function() LazyVim.lsp.words.jump(vim.v.count1, true) end, has = "documentHighlight",
desc = "Next Reference", cond = function() return LazyVim.lsp.words.enabled end },
{ "<a-p>", function() LazyVim.lsp.words.jump(-vim.v.count1, true) end, has = "documentHighlight",
desc = "Prev Reference", cond = function() return LazyVim.lsp.words.enabled end },
}
if LazyVim.has("inc-rename.nvim") then
M._keys[#M._keys + 1] = {
@ -72,7 +78,7 @@ function M.has(buffer, method)
return false
end
---@return (LazyKeys|{has?:string})[]
---@return LazyKeysLsp[]
function M.resolve(buffer)
local Keys = require("lazy.core.handler.keys")
if not Keys.resolve then
@ -93,8 +99,12 @@ function M.on_attach(_, buffer)
local keymaps = M.resolve(buffer)
for _, keys in pairs(keymaps) do
if not keys.has or M.has(buffer, keys.has) then
local has = not keys.has or M.has(buffer, keys.has)
local cond = not (keys.cond == false or ((type(keys.cond) == "function") and not keys.cond()))
if has and cond then
local opts = Keys.opts(keys)
opts.cond = nil
opts.has = nil
opts.silent = opts.silent ~= false
opts.buffer = buffer