Add lazy.track() for accurate module loading statistics in starter dashboard

- Introduce lazy.track(name) to mark directly-loaded modules as loaded
  without invoking their setup function again.
- Replace plugin-package counting with a fixed module list (15 functional
  modules) so the starter footer shows consistent X/Y progress.
- Call lazy.track() for starter, notify, cmdline, lspconfig, and mason.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
xfy 2026-05-28 15:47:02 +08:00
parent 4366e3d696
commit ae765f7438
3 changed files with 28 additions and 17 deletions

View File

@ -43,6 +43,11 @@ M.load = function(name, fn)
end end
end end
-- 仅标记模块为已加载,不执行 setup用于直接加载的插件
M.track = function(name)
M._loaded[name] = true
end
-- --------------------------------------------------------------------------- -- ---------------------------------------------------------------------------
-- 事件触发懒加载 -- 事件触发懒加载
-- --------------------------------------------------------------------------- -- ---------------------------------------------------------------------------

View File

@ -83,7 +83,10 @@ end)
-- nvim-lspconfig 提供常见 LSP 服务器的预设配置。 -- nvim-lspconfig 提供常见 LSP 服务器的预设配置。
vim.cmd.packadd("nvim-lspconfig") vim.cmd.packadd("nvim-lspconfig")
lazy.track("lspconfig")
require("mason").setup() require("mason").setup()
lazy.track("mason")
-- 构建 LSP 客户端 capabilities能力声明告知服务器客户端支持的功能。 -- 构建 LSP 客户端 capabilities能力声明告知服务器客户端支持的功能。
-- 先获取 Neovim 默认 capabilities再与 mini.completion 的 LSP 补全能力合并。 -- 先获取 Neovim 默认 capabilities再与 mini.completion 的 LSP 补全能力合并。

View File

@ -57,19 +57,18 @@ vim.pack.add({
local starter = require("mini.starter") local starter = require("mini.starter")
-- 统计已安装插件数量(用于页脚显示 "Loaded X/Y plugins" -- 所有功能模块列表(用于页脚 "X/Y modules" 统计)。
-- 遍历 stdpath("data")/site/pack/core/opt/ 目录下的所有子目录 -- 口径与 lazy._loaded 一致:每个独立初始化的功能模块算一个,
local function get_total_plugins() -- 不再按 vim.pack 的插件包统计(如 mini.nvim 包含多个模块)。
local pack_dir = vim.fn.stdpath("data") .. "/site/pack/core/opt" local all_modules = {
local paths = vim.fn.glob(pack_dir .. "/*", false, true) "starter", "notify", "cmdline", "icons",
local count = 0 "pick", "files",
for _, path in ipairs(paths) do "diff", "surround",
if vim.fn.isdirectory(path) == 1 then "completion", "snippets",
count = count + 1 "treesitter", "lsp",
end "conform", "lspconfig", "mason",
end "fugitive", "grugfar",
return count }
end
-- Neovim ASCII Art Logo使用 Unicode 方块字符绘制) -- Neovim ASCII Art Logo使用 Unicode 方块字符绘制)
local header_lines = { local header_lines = {
@ -95,13 +94,13 @@ starter.setup({
items = { { name = " ", action = "", section = "" } }, -- 空选项(仅展示页眉页脚) items = { { name = " ", action = "", section = "" } }, -- 空选项(仅展示页眉页脚)
header = table.concat(header_lines, "\n"), -- Logo 文本 header = table.concat(header_lines, "\n"), -- Logo 文本
-- 页脚函数:显示启动耗时和插件加载统计 -- 页脚函数:显示启动耗时和模块加载统计
footer = function() footer = function()
-- 已加载的懒加载模块数(动态统计) -- 已加载的模块数(动态统计,包含直接加载和懒加载
local loaded = vim.tbl_count(require("lazy")._loaded) local loaded = vim.tbl_count(require("lazy")._loaded)
local total = get_total_plugins() local total = #all_modules
-- startup_ms 在 pack.lua 加载时一次性计算,避免后续渲染时数值变化 -- startup_ms 在 pack.lua 加载时一次性计算,避免后续渲染时数值变化
local text = string.format("Loaded %d/%d plugins in %.0f ms", loaded, total, startup_ms) local text = string.format("%d/%d modules | %.0f ms", loaded, total, startup_ms)
local text_width = vim.fn.strdisplaywidth(text) local text_width = vim.fn.strdisplaywidth(text)
-- 计算左填充空格数以实现居中 -- 计算左填充空格数以实现居中
local pad = math.floor((max_header_width - text_width) / 2) local pad = math.floor((max_header_width - text_width) / 2)
@ -114,6 +113,8 @@ starter.setup({
}, },
}) })
lazy.track("starter")
-- --------------------------------------------------------------------------- -- ---------------------------------------------------------------------------
-- mini.files — 文件浏览器(按键触发懒加载) -- mini.files — 文件浏览器(按键触发懒加载)
-- --------------------------------------------------------------------------- -- ---------------------------------------------------------------------------
@ -193,6 +194,7 @@ require("mini.notify").setup({
}) })
-- 将 vim.notify 重定向到 mini.notify -- 将 vim.notify 重定向到 mini.notify
vim.notify = require("mini.notify").make_notify() vim.notify = require("mini.notify").make_notify()
lazy.track("notify")
-- --------------------------------------------------------------------------- -- ---------------------------------------------------------------------------
-- mini.cmdline — 增强命令行 -- mini.cmdline — 增强命令行
@ -206,6 +208,7 @@ vim.keymap.set("n", ":", function()
require("mini.cmdline").setup({ require("mini.cmdline").setup({
autocorrect = { enable = false }, -- 禁用自动纠正 autocorrect = { enable = false }, -- 禁用自动纠正
}) })
lazy.track("cmdline")
return ":" return ":"
end, { expr = true, noremap = true }) end, { expr = true, noremap = true })