mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-04-18 20:36:45 +00:00
refactor(handlers): lazy resolving of plugin handlers (#1126)
* refactor(handlers): lazy resolving of plugin handlers * test: fixed tests
This commit is contained in:
parent
b9c604e839
commit
2f169e74d4
9 changed files with 126 additions and 120 deletions
|
@ -19,10 +19,13 @@ local Util = require("lazy.core.util")
|
|||
---@field rhs? string|fun() rhs
|
||||
---@field mode? string
|
||||
---@field id string
|
||||
---@field name string
|
||||
|
||||
---@class LazyKeysHandler:LazyHandler
|
||||
local M = {}
|
||||
|
||||
local skip = { mode = true, id = true, ft = true, rhs = true, lhs = true }
|
||||
|
||||
---@param value string|LazyKeysSpec
|
||||
---@param mode? string
|
||||
---@return LazyKeys
|
||||
|
@ -37,12 +40,18 @@ function M.parse(value, mode)
|
|||
ret[2] = nil
|
||||
ret.mode = mode or "n"
|
||||
ret.id = vim.api.nvim_replace_termcodes(ret.lhs, true, true, true)
|
||||
|
||||
if ret.mode ~= "n" then
|
||||
ret.id = ret.id .. " (" .. ret.mode .. ")"
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
---@param keys LazyKeys
|
||||
function M.to_string(keys)
|
||||
return keys.lhs .. (keys.mode == "n" and "" or " (" .. keys.mode .. ")")
|
||||
end
|
||||
|
||||
---@param lhs string
|
||||
---@param mode? string
|
||||
function M:have(lhs, mode)
|
||||
|
@ -50,10 +59,8 @@ function M:have(lhs, mode)
|
|||
return self.managed[keys.id] ~= nil
|
||||
end
|
||||
|
||||
---@param plugin LazyPlugin
|
||||
function M:values(plugin)
|
||||
local Plugin = require("lazy.core.plugin")
|
||||
return M.resolve(Plugin.values(plugin, "keys", true))
|
||||
function M:_values(values)
|
||||
return M.resolve(values)
|
||||
end
|
||||
|
||||
---@param spec? (string|LazyKeysSpec)[]
|
||||
|
@ -79,7 +86,6 @@ end
|
|||
|
||||
---@param keys LazyKeys
|
||||
function M.opts(keys)
|
||||
local skip = { mode = true, id = true, ft = true, rhs = true, lhs = true }
|
||||
local opts = {} ---@type LazyKeysBase
|
||||
---@diagnostic disable-next-line: no-unknown
|
||||
for k, v in pairs(keys) do
|
||||
|
@ -106,8 +112,9 @@ function M:_add(keys)
|
|||
self.active[keys.id] = nil
|
||||
|
||||
if plugins then
|
||||
Util.track({ keys = lhs })
|
||||
Loader.load(plugins, { keys = lhs })
|
||||
local name = M.to_string(keys)
|
||||
Util.track({ keys = name })
|
||||
Loader.load(plugins, { keys = name })
|
||||
Util.track()
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue