mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-03-10 09:27:25 +00: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>cr", vim.lsp.buf.rename, desc = "Rename", has = "rename" },
|
||||||
{ "<leader>cA", LazyVim.lsp.action.source, desc = "Source Action", has = "codeAction" },
|
{ "<leader>cA", LazyVim.lsp.action.source, desc = "Source Action", has = "codeAction" },
|
||||||
{ "]]", function() Snacks.words.jump(vim.v.count1) end, has = "documentHighlight",
|
{ "]]", 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",
|
{ "[[", 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",
|
{ "<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",
|
{ "<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 },
|
stylua = { enabled = false },
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ local M = {}
|
|||||||
---@type LazyKeysLspSpec[]|nil
|
---@type LazyKeysLspSpec[]|nil
|
||||||
M._keys = {}
|
M._keys = {}
|
||||||
|
|
||||||
---@alias LazyKeysLspSpec LazyKeysSpec|{has?:string|string[], cond?:fun():boolean}
|
---@alias LazyKeysLspSpec LazyKeysSpec|{has?:string|string[], enabled?:fun():boolean}
|
||||||
---@alias LazyKeysLsp LazyKeys|{has?:string|string[], cond?:fun():boolean}
|
---@alias LazyKeysLsp LazyKeys|{has?:string|string[], enabled?:fun():boolean}
|
||||||
|
|
||||||
---@deprecated
|
---@deprecated
|
||||||
---@return LazyKeysLspSpec[]
|
---@return LazyKeysLspSpec[]
|
||||||
@@ -43,24 +43,23 @@ function M.set(filter, spec)
|
|||||||
local Keys = require("lazy.core.handler.keys")
|
local Keys = require("lazy.core.handler.keys")
|
||||||
for _, keys in pairs(Keys.resolve(spec)) do
|
for _, keys in pairs(Keys.resolve(spec)) do
|
||||||
---@cast keys LazyKeysLsp
|
---@cast keys LazyKeysLsp
|
||||||
if keys.cond == nil or keys.cond() then
|
local filters = {} ---@type vim.lsp.get_clients.Filter[]
|
||||||
local filters = {} ---@type vim.lsp.get_clients.Filter[]
|
if keys.has then
|
||||||
if keys.has then
|
local methods = type(keys.has) == "string" and { keys.has } or keys.has --[[@as string[] ]]
|
||||||
local methods = type(keys.has) == "string" and { keys.has } or keys.has --[[@as string[] ]]
|
for _, method in ipairs(methods) do
|
||||||
for _, method in ipairs(methods) do
|
method = method:find("/") and method or ("textDocument/" .. method)
|
||||||
method = method:find("/") and method or ("textDocument/" .. method)
|
filters[#filters + 1] = vim.tbl_extend("force", vim.deepcopy(filter), { method = method })
|
||||||
filters[#filters + 1] = vim.tbl_extend("force", vim.deepcopy(filter), { method = method })
|
|
||||||
end
|
|
||||||
else
|
|
||||||
filters[#filters + 1] = filter
|
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
filters[#filters + 1] = filter
|
||||||
|
end
|
||||||
|
|
||||||
for _, f in ipairs(filters) do
|
for _, f in ipairs(filters) do
|
||||||
local opts = Keys.opts(keys)
|
local opts = Keys.opts(keys)
|
||||||
---@cast opts snacks.keymap.set.Opts
|
---@cast opts snacks.keymap.set.Opts
|
||||||
opts.lsp = f
|
opts.lsp = f
|
||||||
Snacks.keymap.set(keys.mode or "n", keys.lhs, keys.rhs, opts)
|
opts.enabled = keys.enabled
|
||||||
end
|
Snacks.keymap.set(keys.mode or "n", keys.lhs, keys.rhs, opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user