Skip to content

Commit

Permalink
feat(ui): improvements to profiling and rendering of loaded reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Dec 2, 2022
1 parent 5eb2622 commit 714bc0a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions lua/lazy/core/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ M.defaults = {
border = "none",
icons = {
start = "",
init = "",
plugin = "",
source = "",
config = "",
Expand Down
6 changes: 3 additions & 3 deletions lua/lazy/core/loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ function M.setup()
end

function M.init_plugins()
Util.track("plugin_init")
Util.track({ start = "init" })
for _, plugin in pairs(Config.plugins) do
if plugin.init then
Util.track({ plugin = plugin.name, start = "init" })
Util.track({ plugin = plugin.name, init = "init" })
Util.try(plugin.init, "Failed to run `init` for **" .. plugin.name .. "**")
Util.track()
end
if plugin.lazy == false then
M.load(plugin, { start = "start" })
M.load(plugin, { start = "startup" })
end
end
Util.track()
Expand Down
2 changes: 1 addition & 1 deletion lua/lazy/core/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ local M = {}
---@field build? string|fun(LazyPlugin)

---@class LazyPluginState
---@field loaded? {[string]:string, time:number}
---@field loaded? {[string]:string}|{time:number}
---@field installed boolean
---@field tasks? LazyTask[]
---@field dirty? boolean
Expand Down
13 changes: 6 additions & 7 deletions lua/lazy/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ local M = {}
---@param spec LazySpec Should be a module name to load, or a plugin spec
---@param opts? LazyConfig
function M.setup(spec, opts)
local module_start = vim.loop.hrtime()
local start = vim.loop.hrtime()
require("lazy.core.module").setup()
local Util = require("lazy.core.util")
local Config = require("lazy.core.config")
local Loader = require("lazy.core.loader")
local Plugin = require("lazy.core.plugin")

Util.track("module", vim.loop.hrtime() - module_start)

Util.track("setup")
Util.track({ plugin = "lazy.nvim" })

Util.track("module", vim.loop.hrtime() - start)
Util.track("config")
Config.setup(spec, opts)
Util.track()
Expand All @@ -24,14 +23,14 @@ function M.setup(spec, opts)
Loader.setup()
Util.track()

local lazy_delta = vim.loop.hrtime() - module_start
local delta = vim.loop.hrtime() - start

Util.track() -- end setup
Util.track().time = delta -- end setup

Loader.init_plugins()

if Config.plugins["lazy.nvim"] then
Config.plugins["lazy.nvim"]._.loaded.time = lazy_delta
Config.plugins["lazy.nvim"]._.loaded = { time = delta, source = "init.lua" }
end

vim.cmd("do User LazyDone")
Expand Down
11 changes: 10 additions & 1 deletion lua/lazy/view/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,16 @@ function M:reason(reason, opts)
self:append(" ")
-- self:append(" (", "Conceal")
local first = true
for key, value in pairs(reason) do
local keys = vim.tbl_keys(reason)
table.sort(keys)
if vim.tbl_contains(keys, "plugin") then
keys = vim.tbl_filter(function(key)
return key ~= "plugin"
end, keys)
table.insert(keys, "plugin")
end
for _, key in ipairs(keys) do
local value = reason[key]
if type(key) == "number" then
elseif key == "require" then
-- self:append("require", "@function.builtin")
Expand Down

0 comments on commit 714bc0a

Please sign in to comment.