2022-12-18 18:42:27 +08:00
|
|
|
---@type LazyCommands
|
2022-11-21 05:33:47 +08:00
|
|
|
local M = {}
|
|
|
|
|
2022-12-01 20:33:55 +08:00
|
|
|
---@param spec LazySpec Should be a module name to load, or a plugin spec
|
2022-11-21 05:33:47 +08:00
|
|
|
---@param opts? LazyConfig
|
2022-12-01 20:33:55 +08:00
|
|
|
function M.setup(spec, opts)
|
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
|
|
|
|
if not pcall(require, "ffi") then
|
|
|
|
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
|
|
|
|
2022-12-02 19:43:34 +08:00
|
|
|
if not (opts and opts.performance and opts.performance.cache and opts.performance.cache.enabled == false) then
|
|
|
|
-- load module cache before anything else
|
2022-12-04 01:59:28 +08:00
|
|
|
require("lazy.core.cache").setup(opts)
|
2022-12-02 19:43:34 +08:00
|
|
|
end
|
|
|
|
|
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")
|
2022-11-26 05:48:17 +08:00
|
|
|
local Plugin = require("lazy.core.plugin")
|
2022-11-21 05:33:47 +08:00
|
|
|
|
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")
|
2022-12-01 20:33:55 +08:00
|
|
|
Config.setup(spec, 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
|
|
|
-- load the plugins
|
2022-11-26 05:48:17 +08:00
|
|
|
Plugin.load()
|
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!
|
2022-11-21 05:34:55 +08:00
|
|
|
vim.cmd("do User LazyDone")
|
2022-11-21 05:33:47 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.stats()
|
2022-11-30 07:18:59 +08:00
|
|
|
local ret = { count = 0, loaded = 0 }
|
2022-11-23 04:28:08 +08:00
|
|
|
for _, plugin in pairs(require("lazy.core.config").plugins) do
|
2022-11-21 05:34:55 +08:00
|
|
|
ret.count = ret.count + 1
|
2022-11-28 18:19:50 +08:00
|
|
|
if plugin._.loaded then
|
2022-11-21 05:34:55 +08:00
|
|
|
ret.loaded = ret.loaded + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return ret
|
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
|
|
|
|
vim.fn.system({
|
|
|
|
"git",
|
|
|
|
"clone",
|
|
|
|
"--filter=blob:none",
|
|
|
|
"--single-branch",
|
2022-12-20 19:34:05 +08:00
|
|
|
"https://github.com/folke/lazy.nvim.git",
|
2022-11-29 19:49:15 +08:00
|
|
|
lazypath,
|
|
|
|
})
|
|
|
|
end
|
2022-12-16 06:24:16 +08:00
|
|
|
vim.opt.runtimepath: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
|