2022-11-20 21:33:47 +00:00
|
|
|
local M = {}
|
|
|
|
|
|
|
|
---@param opts? LazyConfig
|
|
|
|
function M.setup(opts)
|
2022-11-22 20:12:33 +00:00
|
|
|
local done = false
|
|
|
|
-- table.insert(package.loaders, 1, function(modname)
|
|
|
|
-- if not done and modname:find("lazy") == 1 then
|
|
|
|
-- dd(modname)
|
|
|
|
-- end
|
|
|
|
-- end)
|
|
|
|
-- Loading order
|
|
|
|
-- 1. load module cache
|
|
|
|
-- 2. if changes, then reload
|
|
|
|
|
|
|
|
local cache_start = vim.loop.hrtime()
|
|
|
|
require("lazy.core.cache").setup()
|
|
|
|
|
|
|
|
local module_start = vim.loop.hrtime()
|
|
|
|
local Module = require("lazy.core.module").setup()
|
|
|
|
|
|
|
|
local require_start = vim.loop.hrtime()
|
2022-11-22 20:28:08 +00:00
|
|
|
local Util = require("lazy.core.util")
|
|
|
|
local Config = require("lazy.core.config")
|
|
|
|
local Loader = require("lazy.core.loader")
|
2022-11-22 20:12:33 +00:00
|
|
|
local State = require("lazy.core.state")
|
2022-11-20 21:33:47 +00:00
|
|
|
|
2022-11-22 20:12:33 +00:00
|
|
|
Util.track("cache.setup", module_start - cache_start)
|
|
|
|
Util.track("module.setup", require_start - module_start)
|
|
|
|
Util.track("require.core", vim.loop.hrtime() - require_start)
|
2022-11-21 20:50:16 +00:00
|
|
|
|
2022-11-22 20:12:33 +00:00
|
|
|
Util.track("setup")
|
2022-11-20 21:33:47 +00:00
|
|
|
|
2022-11-22 20:12:33 +00:00
|
|
|
Util.track("config")
|
2022-11-20 21:34:55 +00:00
|
|
|
Config.setup(opts)
|
|
|
|
Util.track()
|
2022-11-20 21:33:47 +00:00
|
|
|
|
2022-11-23 15:10:16 +00:00
|
|
|
Util.track("state")
|
2022-11-22 20:12:33 +00:00
|
|
|
if Module.changed or not State.load() then
|
|
|
|
-- rebuild state
|
|
|
|
local Plugin = require("lazy.plugin")
|
|
|
|
Module.add_module(vim.fn.stdpath("config") .. "/lua/" .. Config.options.plugins:gsub("%.", "/"))
|
2022-11-22 21:27:29 +00:00
|
|
|
-- Module.add_module(vim.fn.stdpath("config") .. "/lua")
|
|
|
|
-- Module.add_module(Config.options.package_path .. "/start/tokyonight.nvim/lua")
|
|
|
|
-- Module.add_module(Config.options.package_path .. "/opt/nvim-cmp/lua")
|
|
|
|
-- Module.add_module(Config.options.package_path .. "/opt/cmp-buffer/lua")
|
2022-11-21 20:50:16 +00:00
|
|
|
vim.schedule(function()
|
2022-11-22 21:35:06 +00:00
|
|
|
Util.info("Reloading...")
|
2022-11-21 20:50:16 +00:00
|
|
|
end)
|
2022-11-22 20:12:33 +00:00
|
|
|
Util.track("normalize")
|
2022-11-21 20:50:16 +00:00
|
|
|
Plugin.normalize(require(Config.options.plugins))
|
|
|
|
if not Config.plugins.lazy then
|
|
|
|
Plugin.plugin({
|
|
|
|
"folke/lazy.nvim",
|
|
|
|
opt = false,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
Util.track()
|
2022-11-20 21:33:47 +00:00
|
|
|
|
2022-11-22 20:12:33 +00:00
|
|
|
Util.track("process")
|
2022-11-21 20:50:16 +00:00
|
|
|
Plugin.process()
|
|
|
|
Util.track()
|
|
|
|
end
|
2022-11-20 21:34:55 +00:00
|
|
|
Util.track()
|
2022-11-20 21:33:47 +00:00
|
|
|
|
2022-11-22 20:12:33 +00:00
|
|
|
Util.track("install")
|
2022-11-20 21:34:55 +00:00
|
|
|
for _, plugin in pairs(Config.plugins) do
|
|
|
|
if not plugin.installed then
|
2022-11-20 23:27:28 +00:00
|
|
|
require("lazy.manager").install({
|
|
|
|
wait = true,
|
|
|
|
})
|
2022-11-20 21:34:55 +00:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
Util.track()
|
2022-11-20 21:33:47 +00:00
|
|
|
|
2022-11-22 20:12:33 +00:00
|
|
|
Util.track("loader")
|
2022-11-20 21:34:55 +00:00
|
|
|
Loader.setup()
|
|
|
|
Util.track()
|
2022-11-20 21:33:47 +00:00
|
|
|
|
2022-11-22 20:12:33 +00:00
|
|
|
Util.track() -- end setup
|
|
|
|
|
2022-11-20 21:34:55 +00:00
|
|
|
Loader.init_plugins()
|
2022-11-22 20:12:33 +00:00
|
|
|
done = true
|
2022-11-20 21:33:47 +00:00
|
|
|
|
2022-11-20 21:34:55 +00:00
|
|
|
vim.cmd("do User LazyDone")
|
2022-11-20 21:33:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.stats()
|
2022-11-20 21:34:55 +00:00
|
|
|
local ret = {
|
|
|
|
count = 0,
|
|
|
|
loaded = 0,
|
|
|
|
}
|
2022-11-20 21:33:47 +00:00
|
|
|
|
2022-11-22 20:28:08 +00:00
|
|
|
for _, plugin in pairs(require("lazy.core.config").plugins) do
|
2022-11-20 21:34:55 +00:00
|
|
|
ret.count = ret.count + 1
|
2022-11-20 21:33:47 +00:00
|
|
|
|
2022-11-20 21:34:55 +00:00
|
|
|
if plugin.loaded then
|
|
|
|
ret.loaded = ret.loaded + 1
|
|
|
|
end
|
|
|
|
end
|
2022-11-20 21:33:47 +00:00
|
|
|
|
2022-11-20 21:34:55 +00:00
|
|
|
return ret
|
2022-11-20 21:33:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|