diff --git a/README.md b/README.md index fb1a377..31963fc 100644 --- a/README.md +++ b/README.md @@ -355,6 +355,7 @@ return { not_loaded = "○", plugin = " ", runtime = " ", + require = "󰢱 ", source = " ", start = "", task = "✔ ", @@ -448,6 +449,15 @@ return { -- executed. In this case, a warning message will be shown. warn_on_override = true, }, + -- Enable profiling of lazy.nvim. This will add some overhead, + -- so only enable this when you are debugging lazy.nvim + profiling = { + -- Enables extra stats on the debug tab related to the loader cache. + -- Additionally gathers stats about all package.loaders + loader = false, + -- Track each new require in the Lazy profiling tab + require = false, + }, } ``` @@ -495,24 +505,24 @@ Any operation can be started from the UI, with a sub command or an API function: -| Command | Lua | Description | -| ------------------------- | -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | -| `:Lazy build {plugins}` | `require("lazy").build(opts)` | Rebuild a plugin | -| `:Lazy check [plugins]` | `require("lazy").check(opts?)` | Check for updates and show the log (git fetch) | -| `:Lazy clean [plugins]` | `require("lazy").clean(opts?)` | Clean plugins that are no longer needed | -| `:Lazy clear` | `require("lazy").clear()` | Clear finished tasks | -| `:Lazy debug` | `require("lazy").debug()` | Show debug information | -| `:Lazy health` | `require("lazy").health()` | Run `:checkhealth lazy` | -| `:Lazy help` | `require("lazy").help()` | Toggle this help page | -| `:Lazy home` | `require("lazy").home()` | Go back to plugin list | -| `:Lazy install [plugins]` | `require("lazy").install(opts?)` | Install missing plugins | -| `:Lazy load {plugins}` | `require("lazy").load(opts)` | Load a plugin that has not been loaded yet. Similar to `:packadd`. Like `:Lazy load foo.nvim`. Use `:Lazy! load` to skip `cond` checks. | -| `:Lazy log [plugins]` | `require("lazy").log(opts?)` | Show recent updates | -| `:Lazy profile` | `require("lazy").profile()` | Show detailed profiling | -| `:Lazy reload {plugins}` | `require("lazy").reload(opts)` | Reload a plugin (experimental!!) | +| Command | Lua | Description | +| --- | --- | --- | --- | +| `:Lazy build {plugins}` | `require("lazy").build(opts)` | Rebuild a plugin | +| `:Lazy check [plugins]` | `require("lazy").check(opts?)` | Check for updates and show the log (git fetch) | +| `:Lazy clean [plugins]` | `require("lazy").clean(opts?)` | Clean plugins that are no longer needed | +| `:Lazy clear` | `require("lazy").clear()` | Clear finished tasks | +| `:Lazy debug` | `require("lazy").debug()` | Show debug information | +| `:Lazy health` | `require("lazy").health()` | Run `:checkhealth lazy` | +| `:Lazy help` | `require("lazy").help()` | Toggle this help page | +| `:Lazy home` | `require("lazy").home()` | Go back to plugin list | +| `:Lazy install [plugins]` | `require("lazy").install(opts?)` | Install missing plugins | +| `:Lazy load {plugins}` | `require("lazy").load(opts)` | Load a plugin that has not been loaded yet. Similar to `:packadd`. Like `:Lazy load foo.nvim`. Use `:Lazy! load` to skip `cond` checks. | +| `:Lazy log [plugins]` | `require("lazy").log(opts?)` | Show recent updates | +| `:Lazy profile` | `require("lazy").profile()` | Show detailed profiling | +| `:Lazy reload {plugins}` | `require("lazy").reload(opts)` | Reload a plugin (experimental!!) | | `:Lazy restore [plugins]` | `require("lazy").restore(opts?)` | Updates all plugins to the state in the lockfile. For a single plugin: restore it to the state in the lockfile or to a given commit under the cursor | -| `:Lazy sync [plugins]` | `require("lazy").sync(opts?)` | Run install, clean and update | -| `:Lazy update [plugins]` | `require("lazy").update(opts?)` | Update plugins. This will also update the lockfile | +| `:Lazy sync [plugins]` | `require("lazy").sync(opts?)` | Run install, clean and update | +| `:Lazy update [plugins]` | `require("lazy").update(opts?)` | Update plugins. This will also update the lockfile | @@ -763,39 +773,40 @@ To uninstall **lazy.nvim**, you need to remove the following files and directori -| Highlight Group | Default Group | Description | -| --------------------- | -------------------------- | --------------------------------------------------- | -| **LazyButton** | **_CursorLine_** | | -| **LazyButtonActive** | **_Visual_** | | -| **LazyComment** | **_Comment_** | | -| **LazyCommit** | **_@variable.builtin_** | commit ref | -| **LazyCommitIssue** | **_Number_** | | -| **LazyCommitScope** | **_Italic_** | conventional commit scope | -| **LazyCommitType** | **_Title_** | conventional commit type | -| **LazyDimmed** | **_Conceal_** | property | -| **LazyDir** | **_@text.reference_** | directory | -| **LazyH1** | **_IncSearch_** | home button | -| **LazyH2** | **_Bold_** | titles | -| **LazyLocal** | **_Constant_** | | -| **LazyNoCond** | **_DiagnosticWarn_** | unloaded icon for a plugin where `cond()` was false | -| **LazyNormal** | **_NormalFloat_** | | -| **LazyProgressDone** | **_Constant_** | progress bar done | -| **LazyProgressTodo** | **_LineNr_** | progress bar todo | -| **LazyProp** | **_Conceal_** | property | -| **LazyReasonCmd** | **_Operator_** | | -| **LazyReasonEvent** | **_Constant_** | | -| **LazyReasonFt** | **_Character_** | | -| **LazyReasonImport** | **_Identifier_** | | -| **LazyReasonKeys** | **_Statement_** | | -| **LazyReasonPlugin** | **_Special_** | | -| **LazyReasonRuntime** | **_@macro_** | | -| **LazyReasonSource** | **_Character_** | | -| **LazyReasonStart** | **_@field_** | | -| **LazySpecial** | **_@punctuation.special_** | | -| **LazyTaskError** | **_ErrorMsg_** | task errors | -| **LazyTaskOutput** | **_MsgArea_** | task output | -| **LazyUrl** | **_@text.reference_** | url | -| **LazyValue** | **_@string_** | value of a property | +| Highlight Group | Default Group | Description | +| --- | --- | --- | +| **LazyButton** | ***CursorLine*** | | +| **LazyButtonActive** | ***Visual*** | | +| **LazyComment** | ***Comment*** | | +| **LazyCommit** | ***@variable.builtin*** | commit ref | +| **LazyCommitIssue** | ***Number*** | | +| **LazyCommitScope** | ***Italic*** | conventional commit scope | +| **LazyCommitType** | ***Title*** | conventional commit type | +| **LazyDimmed** | ***Conceal*** | property | +| **LazyDir** | ***@text.reference*** | directory | +| **LazyH1** | ***IncSearch*** | home button | +| **LazyH2** | ***Bold*** | titles | +| **LazyLocal** | ***Constant*** | | +| **LazyNoCond** | ***DiagnosticWarn*** | unloaded icon for a plugin where `cond()` was false | +| **LazyNormal** | ***NormalFloat*** | | +| **LazyProgressDone** | ***Constant*** | progress bar done | +| **LazyProgressTodo** | ***LineNr*** | progress bar todo | +| **LazyProp** | ***Conceal*** | property | +| **LazyReasonCmd** | ***Operator*** | | +| **LazyReasonEvent** | ***Constant*** | | +| **LazyReasonFt** | ***Character*** | | +| **LazyReasonImport** | ***Identifier*** | | +| **LazyReasonKeys** | ***Statement*** | | +| **LazyReasonPlugin** | ***Special*** | | +| **LazyReasonRequire** | ***@parameter*** | | +| **LazyReasonRuntime** | ***@macro*** | | +| **LazyReasonSource** | ***Character*** | | +| **LazyReasonStart** | ***@field*** | | +| **LazySpecial** | ***@punctuation.special*** | | +| **LazyTaskError** | ***ErrorMsg*** | task errors | +| **LazyTaskOutput** | ***MsgArea*** | task output | +| **LazyUrl** | ***@text.reference*** | url | +| **LazyValue** | ***@string*** | value of a property | diff --git a/lua/lazy/core/config.lua b/lua/lazy/core/config.lua index e676ab9..f4d948b 100644 --- a/lua/lazy/core/config.lua +++ b/lua/lazy/core/config.lua @@ -65,6 +65,7 @@ M.defaults = { not_loaded = "○", plugin = " ", runtime = " ", + require = "󰢱 ", source = " ", start = "", task = "✔ ", @@ -158,6 +159,15 @@ M.defaults = { -- executed. In this case, a warning message will be shown. warn_on_override = true, }, + -- Enable profiling of lazy.nvim. This will add some overhead, + -- so only enable this when you are debugging lazy.nvim + profiling = { + -- Enables extra stats on the debug tab related to the loader cache. + -- Additionally gathers stats about all package.loaders + loader = false, + -- Track each new require in the Lazy profiling tab + require = false, + }, debug = false, } diff --git a/lua/lazy/core/util.lua b/lua/lazy/core/util.lua index a11d3ae..da0fcf6 100644 --- a/lua/lazy/core/util.lua +++ b/lua/lazy/core/util.lua @@ -118,7 +118,7 @@ function M.get_source() if not info then break end - if info.what ~= "C" and not info.source:find("lazy.nvim", 1, true) then + if info.what ~= "C" and not info.source:find("lazy.nvim", 1, true) and info.source ~= "@vim/loader.lua" then return info.source:sub(2) end f = f + 1 diff --git a/lua/lazy/init.lua b/lua/lazy/init.lua index a2e0940..e219eaf 100644 --- a/lua/lazy/init.lua +++ b/lua/lazy/init.lua @@ -2,6 +2,23 @@ local M = {} M._start = 0 +local function profile_require() + local done = {} ---@type table + local r = require + _G.require = function(modname) + local Util = package.loaded["lazy.core.util"] + if Util and not done[modname] then + done[modname] = true + Util.track({ require = modname }) + local ret = vim.F.pack_len(r(modname)) + Util.track() + return vim.F.unpack_len(ret) + else + return r(modname) + end + end +end + ---@overload fun(opts: LazyConfig) ---@overload fun(spec:LazySpec, opts: LazyConfig) function M.setup(spec, opts) @@ -40,17 +57,16 @@ function M.setup(spec, opts) local Cache = require("lazy.core.cache") - local enable_cache = not ( - opts - and opts.performance - and opts.performance.cache - and opts.performance.cache.enabled == false - ) + local enable_cache = vim.tbl_get(opts, "performance", "cache", "enabled") ~= false -- load module cache before anything else if enable_cache then Cache.enable() end + if vim.tbl_get(opts, "profiling", "require") then + profile_require() + end + require("lazy.stats").track("LazyStart") local Util = require("lazy.core.util") @@ -59,8 +75,12 @@ function M.setup(spec, opts) table.insert(package.loaders, 3, Loader.loader) - if vim.g.profile_loaders then - Cache.profile_loaders() + if vim.tbl_get(opts, "profiling", "loader") then + if vim.loader then + vim.loader._profile({ loaders = true }) + else + Cache._profile_loaders() + end end Util.track({ plugin = "lazy.nvim" }) -- setup start diff --git a/lua/lazy/view/colors.lua b/lua/lazy/view/colors.lua index 6d43f1f..cc00a3a 100644 --- a/lua/lazy/view/colors.lua +++ b/lua/lazy/view/colors.lua @@ -26,6 +26,7 @@ M.colors = { ReasonFt = "Character", ReasonCmd = "Operator", ReasonImport = "Identifier", + ReasonRequire = "@parameter", Button = "CursorLine", ButtonActive = "Visual", TaskOutput = "MsgArea", -- task output diff --git a/lua/lazy/view/render.lua b/lua/lazy/view/render.lua index cc677b9..12c3da3 100644 --- a/lua/lazy/view/render.lua +++ b/lua/lazy/view/render.lua @@ -320,7 +320,7 @@ function M:reason(reason, opts) for _, key in ipairs(keys) do local value = reason[key] if type(key) == "number" then - elseif key == "require" then + -- elseif key == "require" then elseif key ~= "time" then if first then first = false