Skip to content

Commit

Permalink
fix(ui): use actual handler values for rendering plugin handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Oct 11, 2023
1 parent b65d308 commit 99ee284
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
13 changes: 8 additions & 5 deletions lua/lazy/core/handler/ft.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -18,4 +13,12 @@ function M:add(plugin)
end
end

function M:parse(value)
return {
id = value,
event = "FileType",
pattern = value,
}
end

return M
25 changes: 14 additions & 11 deletions lua/lazy/view/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 99ee284

Please sign in to comment.