2023-10-05 03:43:14 +08:00
|
|
|
---@class Lazy: LazyCommands
|
2022-11-21 05:33:47 +08:00
|
|
|
local M = {}
|
2022-12-27 20:34:07 +08:00
|
|
|
M._start = 0
|
2022-11-21 05:33:47 +08:00
|
|
|
|
2023-10-09 18:38:43 +08:00
|
|
|
local function profile_require()
|
|
|
|
local done = {} ---@type table<string, true>
|
|
|
|
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 })
|
2023-10-10 05:42:05 +08:00
|
|
|
local ok, ret = pcall(function()
|
|
|
|
return vim.F.pack_len(r(modname))
|
|
|
|
end)
|
2023-10-09 18:38:43 +08:00
|
|
|
Util.track()
|
2023-10-10 05:42:05 +08:00
|
|
|
if not ok then
|
|
|
|
error(ret, 2)
|
|
|
|
end
|
2023-10-09 18:38:43 +08:00
|
|
|
return vim.F.unpack_len(ret)
|
|
|
|
else
|
|
|
|
return r(modname)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-02 16:44:09 +08:00
|
|
|
---@overload fun(opts: LazyConfig)
|
|
|
|
---@overload fun(spec:LazySpec, opts: LazyConfig)
|
2022-12-01 20:33:55 +08:00
|
|
|
function M.setup(spec, opts)
|
2023-01-02 16:44:09 +08:00
|
|
|
if type(spec) == "table" and spec.spec then
|
|
|
|
---@cast spec LazyConfig
|
|
|
|
opts = spec
|
|
|
|
else
|
|
|
|
opts = opts or {}
|
|
|
|
opts.spec = spec
|
|
|
|
end
|
|
|
|
|
2022-12-27 20:34:07 +08:00
|
|
|
M._start = M._start == 0 and vim.loop.hrtime() or M._start
|
2022-12-20 20:47:53 +08:00
|
|
|
if vim.g.lazy_did_setup then
|
|
|
|
return vim.notify(
|
|
|
|
"Re-sourcing your config is not supported with lazy.nvim",
|
|
|
|
vim.log.levels.WARN,
|
|
|
|
{ title = "lazy.nvim" }
|
|
|
|
)
|
|
|
|
end
|
|
|
|
vim.g.lazy_did_setup = true
|
2022-12-15 04:25:11 +08:00
|
|
|
if not vim.go.loadplugins then
|
|
|
|
return
|
|
|
|
end
|
2022-12-18 20:41:02 +08:00
|
|
|
if vim.fn.has("nvim-0.8.0") ~= 1 then
|
|
|
|
return vim.notify("lazy.nvim requires Neovim >= 0.8.0", vim.log.levels.ERROR, { title = "lazy.nvim" })
|
|
|
|
end
|
2022-12-29 15:01:05 +08:00
|
|
|
if not (pcall(require, "ffi") and jit and jit.version) then
|
2022-12-18 20:41:02 +08:00
|
|
|
return vim.notify("lazy.nvim requires Neovim built with LuaJIT", vim.log.levels.ERROR, { title = "lazy.nvim" })
|
|
|
|
end
|
2022-12-01 23:27:52 +08:00
|
|
|
local start = vim.loop.hrtime()
|
2022-12-01 23:37:50 +08:00
|
|
|
|
2023-07-06 22:30:54 +08:00
|
|
|
-- use the Neovim cache if available
|
2023-04-19 18:59:29 +08:00
|
|
|
if vim.loader and vim.fn.has("nvim-0.9.1") == 1 then
|
2023-03-15 22:10:44 +08:00
|
|
|
package.loaded["lazy.core.cache"] = vim.loader
|
2023-03-15 02:45:22 +08:00
|
|
|
end
|
|
|
|
|
2023-03-15 16:01:00 +08:00
|
|
|
local Cache = require("lazy.core.cache")
|
|
|
|
|
2023-10-09 18:38:43 +08:00
|
|
|
local enable_cache = vim.tbl_get(opts, "performance", "cache", "enabled") ~= false
|
2023-03-15 02:45:22 +08:00
|
|
|
-- load module cache before anything else
|
2023-02-14 18:00:56 +08:00
|
|
|
if enable_cache then
|
2023-03-15 16:01:00 +08:00
|
|
|
Cache.enable()
|
2023-02-13 19:01:56 +08:00
|
|
|
end
|
2022-12-02 19:43:34 +08:00
|
|
|
|
2023-10-09 18:38:43 +08:00
|
|
|
if vim.tbl_get(opts, "profiling", "require") then
|
|
|
|
profile_require()
|
|
|
|
end
|
|
|
|
|
2023-01-02 18:28:18 +08:00
|
|
|
require("lazy.stats").track("LazyStart")
|
|
|
|
|
2022-11-23 04:28:08 +08:00
|
|
|
local Util = require("lazy.core.util")
|
|
|
|
local Config = require("lazy.core.config")
|
|
|
|
local Loader = require("lazy.core.loader")
|
2023-02-14 18:00:56 +08:00
|
|
|
|
2023-02-13 19:01:56 +08:00
|
|
|
table.insert(package.loaders, 3, Loader.loader)
|
2022-11-21 05:33:47 +08:00
|
|
|
|
2023-10-09 18:38:43 +08:00
|
|
|
if vim.tbl_get(opts, "profiling", "loader") then
|
|
|
|
if vim.loader then
|
|
|
|
vim.loader._profile({ loaders = true })
|
|
|
|
else
|
|
|
|
Cache._profile_loaders()
|
|
|
|
end
|
2023-02-14 18:00:56 +08:00
|
|
|
end
|
|
|
|
|
2022-12-01 23:37:50 +08:00
|
|
|
Util.track({ plugin = "lazy.nvim" }) -- setup start
|
2022-12-01 23:27:52 +08:00
|
|
|
Util.track("module", vim.loop.hrtime() - start)
|
2022-12-01 23:37:50 +08:00
|
|
|
|
|
|
|
-- load config
|
2022-11-23 04:12:33 +08:00
|
|
|
Util.track("config")
|
2023-01-02 16:44:09 +08:00
|
|
|
Config.setup(opts)
|
2022-11-21 05:34:55 +08:00
|
|
|
Util.track()
|
2022-11-21 05:33:47 +08:00
|
|
|
|
2022-12-01 23:37:50 +08:00
|
|
|
-- setup loader and handlers
|
2022-12-01 18:06:44 +08:00
|
|
|
Loader.setup()
|
2022-11-21 05:33:47 +08:00
|
|
|
|
2022-12-01 23:37:50 +08:00
|
|
|
-- correct time delta and loaded
|
2022-12-01 23:27:52 +08:00
|
|
|
local delta = vim.loop.hrtime() - start
|
|
|
|
Util.track().time = delta -- end setup
|
2022-11-26 20:58:18 +08:00
|
|
|
if Config.plugins["lazy.nvim"] then
|
2022-12-01 23:27:52 +08:00
|
|
|
Config.plugins["lazy.nvim"]._.loaded = { time = delta, source = "init.lua" }
|
2022-11-26 20:58:18 +08:00
|
|
|
end
|
2022-11-21 05:33:47 +08:00
|
|
|
|
2022-12-01 23:37:50 +08:00
|
|
|
-- load plugins with lazy=false or Plugin.init
|
2022-12-15 04:03:53 +08:00
|
|
|
Loader.startup()
|
2022-12-01 23:37:50 +08:00
|
|
|
|
|
|
|
-- all done!
|
2023-01-13 16:00:15 +08:00
|
|
|
vim.api.nvim_exec_autocmds("User", { pattern = "LazyDone", modeline = false })
|
2023-01-02 18:28:18 +08:00
|
|
|
require("lazy.stats").track("LazyDone")
|
2022-11-21 05:33:47 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.stats()
|
2022-12-27 20:34:07 +08:00
|
|
|
return require("lazy.stats").stats()
|
2022-11-21 05:33:47 +08:00
|
|
|
end
|
|
|
|
|
2022-11-29 19:49:15 +08:00
|
|
|
function M.bootstrap()
|
2022-12-15 04:38:40 +08:00
|
|
|
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
|
2022-11-29 19:49:15 +08:00
|
|
|
if not vim.loop.fs_stat(lazypath) then
|
2022-12-31 16:44:17 +08:00
|
|
|
vim.fn.system({
|
|
|
|
"git",
|
|
|
|
"clone",
|
|
|
|
"--filter=blob:none",
|
|
|
|
"https://github.com/folke/lazy.nvim.git",
|
|
|
|
"--branch=stable", -- latest stable release
|
|
|
|
lazypath,
|
|
|
|
})
|
2022-11-29 19:49:15 +08:00
|
|
|
end
|
2022-12-29 23:03:23 +08:00
|
|
|
vim.opt.rtp:prepend(lazypath)
|
2022-11-29 19:49:15 +08:00
|
|
|
end
|
|
|
|
|
2022-12-14 23:07:32 +08:00
|
|
|
---@return LazyPlugin[]
|
|
|
|
function M.plugins()
|
|
|
|
return vim.tbl_values(require("lazy.core.config").plugins)
|
|
|
|
end
|
|
|
|
|
2022-12-18 18:42:27 +08:00
|
|
|
setmetatable(M, {
|
|
|
|
__index = function(_, key)
|
2022-12-19 00:36:32 +08:00
|
|
|
return function(...)
|
|
|
|
return require("lazy.view.commands").commands[key](...)
|
|
|
|
end
|
2022-12-18 18:42:27 +08:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2022-11-21 05:33:47 +08:00
|
|
|
return M
|