feat(ui): improvements to profiling and rendering of loaded reasons

This commit is contained in:
Folke Lemaitre 2022-12-01 16:27:52 +01:00
parent 5eb2622a4e
commit 714bc0a136
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
5 changed files with 21 additions and 12 deletions

View File

@ -36,6 +36,7 @@ M.defaults = {
border = "none", border = "none",
icons = { icons = {
start = "", start = "",
init = "",
plugin = "", plugin = "",
source = "", source = "",
config = "", config = "",

View File

@ -28,15 +28,15 @@ function M.setup()
end end
function M.init_plugins() function M.init_plugins()
Util.track("plugin_init") Util.track({ start = "init" })
for _, plugin in pairs(Config.plugins) do for _, plugin in pairs(Config.plugins) do
if plugin.init then 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.try(plugin.init, "Failed to run `init` for **" .. plugin.name .. "**")
Util.track() Util.track()
end end
if plugin.lazy == false then if plugin.lazy == false then
M.load(plugin, { start = "start" }) M.load(plugin, { start = "startup" })
end end
end end
Util.track() Util.track()

View File

@ -11,7 +11,7 @@ local M = {}
---@field build? string|fun(LazyPlugin) ---@field build? string|fun(LazyPlugin)
---@class LazyPluginState ---@class LazyPluginState
---@field loaded? {[string]:string, time:number} ---@field loaded? {[string]:string}|{time:number}
---@field installed boolean ---@field installed boolean
---@field tasks? LazyTask[] ---@field tasks? LazyTask[]
---@field dirty? boolean ---@field dirty? boolean

View File

@ -3,17 +3,16 @@ local M = {}
---@param spec LazySpec Should be a module name to load, or a plugin spec ---@param spec LazySpec Should be a module name to load, or a plugin spec
---@param opts? LazyConfig ---@param opts? LazyConfig
function M.setup(spec, opts) function M.setup(spec, opts)
local module_start = vim.loop.hrtime() local start = vim.loop.hrtime()
require("lazy.core.module").setup() require("lazy.core.module").setup()
local Util = require("lazy.core.util") local Util = require("lazy.core.util")
local Config = require("lazy.core.config") local Config = require("lazy.core.config")
local Loader = require("lazy.core.loader") local Loader = require("lazy.core.loader")
local Plugin = require("lazy.core.plugin") local Plugin = require("lazy.core.plugin")
Util.track("module", vim.loop.hrtime() - module_start) Util.track({ plugin = "lazy.nvim" })
Util.track("setup")
Util.track("module", vim.loop.hrtime() - start)
Util.track("config") Util.track("config")
Config.setup(spec, opts) Config.setup(spec, opts)
Util.track() Util.track()
@ -24,14 +23,14 @@ function M.setup(spec, opts)
Loader.setup() Loader.setup()
Util.track() 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() Loader.init_plugins()
if Config.plugins["lazy.nvim"] then 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 end
vim.cmd("do User LazyDone") vim.cmd("do User LazyDone")

View File

@ -217,7 +217,16 @@ function M:reason(reason, opts)
self:append(" ") self:append(" ")
-- self:append(" (", "Conceal") -- self:append(" (", "Conceal")
local first = true 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 if type(key) == "number" then
elseif key == "require" then elseif key == "require" then
-- self:append("require", "@function.builtin") -- self:append("require", "@function.builtin")