fix(ui): use actual handler values for rendering plugin handlers

This commit is contained in:
Folke Lemaitre 2023-10-11 14:25:10 +02:00
parent b65d308662
commit 99ee284739
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
2 changed files with 22 additions and 16 deletions

View File

@ -5,11 +5,6 @@ local Loader = require("lazy.core.loader")
local M = {}
M.extends = Event
---@param value string
function M:_event(value)
return "FileType " .. value
end
---@param plugin LazyPlugin
function M:add(plugin)
self.super.add(self, plugin)
@ -18,4 +13,12 @@ function M:add(plugin)
end
end
function M:parse(value)
return {
id = value,
event = "FileType",
pattern = value,
}
end
return M

View File

@ -319,17 +319,13 @@ function M:reason(reason, opts)
end
for _, key in ipairs(keys) do
local value = reason[key]
if type(key) == "number" then
-- elseif key == "require" then
elseif key ~= "time" then
local skip = type(key) == "number" or key == "time"
if not skip then
if first then
first = false
else
self:append(" ")
end
if key == "event" then
value = value:match("User (.*)") or value
end
if key == "keys" then
value = type(value) == "string" and value or value.lhs or value[1]
end
@ -414,11 +410,18 @@ function M:plugin(plugin)
if plugin._.kind ~= "disabled" then
for handler in pairs(Handler.types) do
if plugin[handler] then
local trigger = {}
for _, value in ipairs(plugin[handler]) do
table.insert(trigger, type(value) == "table" and value[1] or value)
end
reason[handler] = table.concat(trigger, " ")
local values = Handler.handlers[handler]:values(plugin)
values = vim.tbl_map(function(value)
if handler == "ft" or handler == "event" then
---@cast value LazyEvent
return value.id
elseif handler == "keys" then
---@cast value LazyKeys
return value.lhs .. (value.mode == "n" and "" or " (" .. value.mode .. ")")
end
return value
end, vim.tbl_values(values))
reason[handler] = table.concat(values, " ")
end
end
end