mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-12-25 12:14:19 +01:00
fix(lsp.keymaps): make cond -> enabled work again. Closes #6697
This commit is contained in:
@@ -92,13 +92,13 @@ return {
|
||||
{ "<leader>cr", vim.lsp.buf.rename, desc = "Rename", has = "rename" },
|
||||
{ "<leader>cA", LazyVim.lsp.action.source, desc = "Source Action", has = "codeAction" },
|
||||
{ "]]", function() Snacks.words.jump(vim.v.count1) end, has = "documentHighlight",
|
||||
desc = "Next Reference", cond = function() return Snacks.words.is_enabled() end },
|
||||
desc = "Next Reference", enabled = function() return Snacks.words.is_enabled() end },
|
||||
{ "[[", function() Snacks.words.jump(-vim.v.count1) end, has = "documentHighlight",
|
||||
desc = "Prev Reference", cond = function() return Snacks.words.is_enabled() end },
|
||||
desc = "Prev Reference", enabled = function() return Snacks.words.is_enabled() end },
|
||||
{ "<a-n>", function() Snacks.words.jump(vim.v.count1, true) end, has = "documentHighlight",
|
||||
desc = "Next Reference", cond = function() return Snacks.words.is_enabled() end },
|
||||
desc = "Next Reference", enabled = function() return Snacks.words.is_enabled() end },
|
||||
{ "<a-p>", function() Snacks.words.jump(-vim.v.count1, true) end, has = "documentHighlight",
|
||||
desc = "Prev Reference", cond = function() return Snacks.words.is_enabled() end },
|
||||
desc = "Prev Reference", enabled = function() return Snacks.words.is_enabled() end },
|
||||
},
|
||||
},
|
||||
stylua = { enabled = false },
|
||||
|
||||
@@ -3,8 +3,8 @@ local M = {}
|
||||
---@type LazyKeysLspSpec[]|nil
|
||||
M._keys = {}
|
||||
|
||||
---@alias LazyKeysLspSpec LazyKeysSpec|{has?:string|string[], cond?:fun():boolean}
|
||||
---@alias LazyKeysLsp LazyKeys|{has?:string|string[], cond?:fun():boolean}
|
||||
---@alias LazyKeysLspSpec LazyKeysSpec|{has?:string|string[], enabled?:fun():boolean}
|
||||
---@alias LazyKeysLsp LazyKeys|{has?:string|string[], enabled?:fun():boolean}
|
||||
|
||||
---@deprecated
|
||||
---@return LazyKeysLspSpec[]
|
||||
@@ -43,24 +43,23 @@ function M.set(filter, spec)
|
||||
local Keys = require("lazy.core.handler.keys")
|
||||
for _, keys in pairs(Keys.resolve(spec)) do
|
||||
---@cast keys LazyKeysLsp
|
||||
if keys.cond == nil or keys.cond() then
|
||||
local filters = {} ---@type vim.lsp.get_clients.Filter[]
|
||||
if keys.has then
|
||||
local methods = type(keys.has) == "string" and { keys.has } or keys.has --[[@as string[] ]]
|
||||
for _, method in ipairs(methods) do
|
||||
method = method:find("/") and method or ("textDocument/" .. method)
|
||||
filters[#filters + 1] = vim.tbl_extend("force", vim.deepcopy(filter), { method = method })
|
||||
end
|
||||
else
|
||||
filters[#filters + 1] = filter
|
||||
local filters = {} ---@type vim.lsp.get_clients.Filter[]
|
||||
if keys.has then
|
||||
local methods = type(keys.has) == "string" and { keys.has } or keys.has --[[@as string[] ]]
|
||||
for _, method in ipairs(methods) do
|
||||
method = method:find("/") and method or ("textDocument/" .. method)
|
||||
filters[#filters + 1] = vim.tbl_extend("force", vim.deepcopy(filter), { method = method })
|
||||
end
|
||||
else
|
||||
filters[#filters + 1] = filter
|
||||
end
|
||||
|
||||
for _, f in ipairs(filters) do
|
||||
local opts = Keys.opts(keys)
|
||||
---@cast opts snacks.keymap.set.Opts
|
||||
opts.lsp = f
|
||||
Snacks.keymap.set(keys.mode or "n", keys.lhs, keys.rhs, opts)
|
||||
end
|
||||
for _, f in ipairs(filters) do
|
||||
local opts = Keys.opts(keys)
|
||||
---@cast opts snacks.keymap.set.Opts
|
||||
opts.lsp = f
|
||||
opts.enabled = keys.enabled
|
||||
Snacks.keymap.set(keys.mode or "n", keys.lhs, keys.rhs, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user