Skip to content

Commit 6d68cc6

Browse files
committed
feat(ui): added debug interface to inspect active handlers and the module cache
1 parent d36ad41 commit 6d68cc6

File tree

4 files changed

+53
-15
lines changed

4 files changed

+53
-15
lines changed

lua/lazy/view/colors.lua

+7-6
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ M.colors = {
1616
},
1717
ProgressTodo = "LineNr",
1818
Special = "@punctuation.special",
19-
LoaderPlugin = "Special",
20-
LoaderEvent = "Constant",
21-
LoaderKeys = "Statement",
22-
LoaderStart = "@field",
23-
LoaderSource = "Character",
24-
LoaderCmd = "Operator",
19+
HandlerPlugin = "Special",
20+
HandlerEvent = "Constant",
21+
HandlerKeys = "Statement",
22+
HandlerStart = "@field",
23+
HandlerSource = "Character",
24+
HandlerFt = "Character",
25+
HandlerCmd = "Operator",
2526
Button = "CursorLine",
2627
ButtonActive = "Visual",
2728
}

lua/lazy/view/commands.lua

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ M.commands = {
3636
help = function()
3737
View.show("help")
3838
end,
39+
debug = function()
40+
View.show("debug")
41+
end,
3942
profile = function()
4043
View.show("profile")
4144
end,

lua/lazy/view/init.lua

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ M.modes = {
1313
{ name = "log", key = "L", desc = "Show recent updates for all plugins" },
1414
{ name = "restore", key = "R", desc = "Updates all plugins to the state in the lockfile" },
1515
{ name = "profile", key = "P", desc = "Show detailed profiling", toggle = true },
16+
{ name = "debug", key = "D", desc = "Show debug information", toggle = true },
1617
{ name = "help", key = "?", hide = true, desc = "Toggle this help page", toggle = true },
1718

1819
{ plugin = true, name = "update", key = "u", desc = "Update this plugin. This will also update the lockfile" },

lua/lazy/view/render.lua

+42-9
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ function M:update()
6060
self:help()
6161
elseif mode == "profile" then
6262
self:profile()
63+
elseif mode == "debug" then
64+
self:debug()
6365
else
6466
for _, section in ipairs(Sections) do
6567
self:section(section)
@@ -109,7 +111,7 @@ function M:title()
109111
end
110112
self:nl()
111113

112-
if View.mode ~= "help" and View.mode ~= "profile" then
114+
if View.mode ~= "help" and View.mode ~= "profile" and View.mode ~= "debug" then
113115
if self.progress.done < self.progress.total then
114116
self:append("Tasks: ", "LazyH2")
115117
self:append(self.progress.done .. "/" .. self.progress.total, "LazyMuted")
@@ -208,8 +210,8 @@ function M:reason(reason, opts)
208210
end
209211
end
210212
end
211-
local time = " " .. math.floor((reason.time or 0) / 1e6 * 100) / 100 .. "ms"
212-
if not opts.time_right then
213+
local time = reason.time and (" " .. math.floor(reason.time / 1e6 * 100) / 100 .. "ms")
214+
if time and not opts.time_right then
213215
self:append(time, "Bold")
214216
end
215217
self:append(" ")
@@ -227,10 +229,6 @@ function M:reason(reason, opts)
227229
local value = reason[key]
228230
if type(key) == "number" then
229231
elseif key == "require" then
230-
-- self:append("require", "@function.builtin")
231-
-- self:append("(", "@punctuation.bracket")
232-
-- self:append('"' .. value .. '"', "@string")
233-
-- self:append(")", "@punctuation.bracket")
234232
elseif key ~= "time" then
235233
if first then
236234
first = false
@@ -239,8 +237,10 @@ function M:reason(reason, opts)
239237
end
240238
if key == "event" then
241239
value = value:match("User (.*)") or value
240+
elseif key == "ft" then
241+
value = value:match("FileType (.*)") or value
242242
end
243-
local hl = "LazyLoader" .. key:sub(1, 1):upper() .. key:sub(2)
243+
local hl = "LazyHandler" .. key:sub(1, 1):upper() .. key:sub(2)
244244
local icon = Config.options.ui.icons[key]
245245
if icon then
246246
self:append(icon .. " ", hl)
@@ -251,7 +251,7 @@ function M:reason(reason, opts)
251251
end
252252
end
253253
end
254-
if opts.time_right then
254+
if time and opts.time_right then
255255
self:append(time, "Bold")
256256
end
257257
-- self:append(")", "Conceal")
@@ -432,4 +432,37 @@ function M:profile()
432432
end
433433
end
434434

435+
function M:debug()
436+
self:append("Active Handlers", "LazyH2"):nl()
437+
self
438+
:append(
439+
"This shows only the lazy handlers that are still active. When a plugin loads, its handlers are removed",
440+
"Comment",
441+
{ indent = 2 }
442+
)
443+
:nl()
444+
445+
Util.foreach(require("lazy.core.handler").handlers, function(type, handler)
446+
Util.foreach(handler.active, function(value, plugins)
447+
if not vim.tbl_isempty(plugins) then
448+
plugins = vim.tbl_values(plugins)
449+
table.sort(plugins)
450+
self:append("", "LazySpecial", { indent = 2 })
451+
self:reason({ [type] = value }, { time_right = true })
452+
for _, plugin in pairs(plugins) do
453+
self:reason({ plugin = plugin }, { time_right = true })
454+
end
455+
self:nl()
456+
end
457+
end)
458+
end)
459+
self:nl()
460+
self:append("Cache", "LazyH2"):nl()
461+
local Cache = require("lazy.core.cache")
462+
Util.foreach(Cache.cache, function(modname, entry)
463+
local kb = math.floor(#entry.chunk / 10.24) / 100
464+
self:append("", "LazySpecial", { indent = 2 }):append(modname):append(" " .. kb .. "Kb", "Bold"):nl()
465+
end)
466+
end
467+
435468
return M

0 commit comments

Comments
 (0)