diff --git a/lua/lazyvim/plugins/lsp/init.lua b/lua/lazyvim/plugins/lsp/init.lua index eb882c5c..540b6c5c 100644 --- a/lua/lazyvim/plugins/lsp/init.lua +++ b/lua/lazyvim/plugins/lsp/init.lua @@ -92,13 +92,13 @@ return { { "cr", vim.lsp.buf.rename, desc = "Rename", has = "rename" }, { "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 }, { "", 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 }, { "", 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 }, diff --git a/lua/lazyvim/plugins/lsp/keymaps.lua b/lua/lazyvim/plugins/lsp/keymaps.lua index 8fe36647..57280055 100644 --- a/lua/lazyvim/plugins/lsp/keymaps.lua +++ b/lua/lazyvim/plugins/lsp/keymaps.lua @@ -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