Skip to content

Commit

Permalink
feat(ui): added debug interface to inspect active handlers and the mo…
Browse files Browse the repository at this point in the history
…dule cache
  • Loading branch information
folke committed Dec 5, 2022
1 parent d36ad41 commit 6d68cc6
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 15 deletions.
13 changes: 7 additions & 6 deletions lua/lazy/view/colors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ M.colors = {
},
ProgressTodo = "LineNr",
Special = "@punctuation.special",
LoaderPlugin = "Special",
LoaderEvent = "Constant",
LoaderKeys = "Statement",
LoaderStart = "@field",
LoaderSource = "Character",
LoaderCmd = "Operator",
HandlerPlugin = "Special",
HandlerEvent = "Constant",
HandlerKeys = "Statement",
HandlerStart = "@field",
HandlerSource = "Character",
HandlerFt = "Character",
HandlerCmd = "Operator",
Button = "CursorLine",
ButtonActive = "Visual",
}
Expand Down
3 changes: 3 additions & 0 deletions lua/lazy/view/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ M.commands = {
help = function()
View.show("help")
end,
debug = function()
View.show("debug")
end,
profile = function()
View.show("profile")
end,
Expand Down
1 change: 1 addition & 0 deletions lua/lazy/view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ M.modes = {
{ name = "log", key = "L", desc = "Show recent updates for all plugins" },
{ name = "restore", key = "R", desc = "Updates all plugins to the state in the lockfile" },
{ name = "profile", key = "P", desc = "Show detailed profiling", toggle = true },
{ name = "debug", key = "D", desc = "Show debug information", toggle = true },
{ name = "help", key = "?", hide = true, desc = "Toggle this help page", toggle = true },

{ plugin = true, name = "update", key = "u", desc = "Update this plugin. This will also update the lockfile" },
Expand Down
51 changes: 42 additions & 9 deletions lua/lazy/view/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ function M:update()
self:help()
elseif mode == "profile" then
self:profile()
elseif mode == "debug" then
self:debug()
else
for _, section in ipairs(Sections) do
self:section(section)
Expand Down Expand Up @@ -109,7 +111,7 @@ function M:title()
end
self:nl()

if View.mode ~= "help" and View.mode ~= "profile" then
if View.mode ~= "help" and View.mode ~= "profile" and View.mode ~= "debug" then
if self.progress.done < self.progress.total then
self:append("Tasks: ", "LazyH2")
self:append(self.progress.done .. "/" .. self.progress.total, "LazyMuted")
Expand Down Expand Up @@ -208,8 +210,8 @@ function M:reason(reason, opts)
end
end
end
local time = " " .. math.floor((reason.time or 0) / 1e6 * 100) / 100 .. "ms"
if not opts.time_right then
local time = reason.time and (" " .. math.floor(reason.time / 1e6 * 100) / 100 .. "ms")
if time and not opts.time_right then
self:append(time, "Bold")
end
self:append(" ")
Expand All @@ -227,10 +229,6 @@ function M:reason(reason, opts)
local value = reason[key]
if type(key) == "number" then
elseif key == "require" then
-- self:append("require", "@function.builtin")
-- self:append("(", "@punctuation.bracket")
-- self:append('"' .. value .. '"', "@string")
-- self:append(")", "@punctuation.bracket")
elseif key ~= "time" then
if first then
first = false
Expand All @@ -239,8 +237,10 @@ function M:reason(reason, opts)
end
if key == "event" then
value = value:match("User (.*)") or value
elseif key == "ft" then
value = value:match("FileType (.*)") or value
end
local hl = "LazyLoader" .. key:sub(1, 1):upper() .. key:sub(2)
local hl = "LazyHandler" .. key:sub(1, 1):upper() .. key:sub(2)
local icon = Config.options.ui.icons[key]
if icon then
self:append(icon .. " ", hl)
Expand All @@ -251,7 +251,7 @@ function M:reason(reason, opts)
end
end
end
if opts.time_right then
if time and opts.time_right then
self:append(time, "Bold")
end
-- self:append(")", "Conceal")
Expand Down Expand Up @@ -432,4 +432,37 @@ function M:profile()
end
end

function M:debug()
self:append("Active Handlers", "LazyH2"):nl()
self
:append(
"This shows only the lazy handlers that are still active. When a plugin loads, its handlers are removed",
"Comment",
{ indent = 2 }
)
:nl()

Util.foreach(require("lazy.core.handler").handlers, function(type, handler)
Util.foreach(handler.active, function(value, plugins)
if not vim.tbl_isempty(plugins) then
plugins = vim.tbl_values(plugins)
table.sort(plugins)
self:append("", "LazySpecial", { indent = 2 })
self:reason({ [type] = value }, { time_right = true })
for _, plugin in pairs(plugins) do
self:reason({ plugin = plugin }, { time_right = true })
end
self:nl()
end
end)
end)
self:nl()
self:append("Cache", "LazyH2"):nl()
local Cache = require("lazy.core.cache")
Util.foreach(Cache.cache, function(modname, entry)
local kb = math.floor(#entry.chunk / 10.24) / 100
self:append("", "LazySpecial", { indent = 2 }):append(modname):append(" " .. kb .. "Kb", "Bold"):nl()
end)
end

return M

0 comments on commit 6d68cc6

Please sign in to comment.