2022-12-18 10:42:27 +00:00
|
|
|
---@type LazyCommands
|
2022-11-20 21:33:47 +00:00
|
|
|
local M = {}
|
2022-12-27 12:34:07 +00:00
|
|
|
M._start = 0
|
2022-11-20 21:33:47 +00:00
|
|
|
|
2022-12-01 12:33:55 +00:00
|
|
|
---@param spec LazySpec Should be a module name to load, or a plugin spec
|
2022-11-20 21:33:47 +00:00
|
|
|
---@param opts? LazyConfig
|
2022-12-01 12:33:55 +00:00
|
|
|
function M.setup(spec, opts)
|
2022-12-27 12:34:07 +00:00
|
|
|
M._start = M._start == 0 and vim.loop.hrtime() or M._start
|
2022-12-20 12:47:53 +00: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-14 20:25:11 +00:00
|
|
|
if not vim.go.loadplugins then
|
|
|
|
return
|
|
|
|
end
|
2022-12-18 12:41:02 +00: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 07:01:05 +00:00
|
|
|
if not (pcall(require, "ffi") and jit and jit.version) then
|
2022-12-18 12:41:02 +00:00
|
|
|
return vim.notify("lazy.nvim requires Neovim built with LuaJIT", vim.log.levels.ERROR, { title = "lazy.nvim" })
|
|
|
|
end
|
2022-12-01 15:27:52 +00:00
|
|
|
local start = vim.loop.hrtime()
|
2022-12-01 15:37:50 +00:00
|
|
|
|
2022-12-28 16:57:59 +00:00
|
|
|
-- load module cache before anything else
|
|
|
|
require("lazy.core.cache").setup(opts)
|
2022-12-02 11:43:34 +00:00
|
|
|
|
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-25 21:48:17 +00:00
|
|
|
local Plugin = require("lazy.core.plugin")
|
2022-11-20 21:33:47 +00:00
|
|
|
|
2022-12-01 15:37:50 +00:00
|
|
|
Util.track({ plugin = "lazy.nvim" }) -- setup start
|
2022-12-01 15:27:52 +00:00
|
|
|
Util.track("module", vim.loop.hrtime() - start)
|
2022-12-01 15:37:50 +00:00
|
|
|
|
|
|
|
-- load config
|
2022-11-22 20:12:33 +00:00
|
|
|
Util.track("config")
|
2022-12-01 12:33:55 +00:00
|
|
|
Config.setup(spec, opts)
|
2022-11-20 21:34:55 +00:00
|
|
|
Util.track()
|
2022-11-20 21:33:47 +00:00
|
|
|
|
2022-12-01 15:37:50 +00:00
|
|
|
-- load the plugins
|
2022-11-25 21:48:17 +00:00
|
|
|
Plugin.load()
|
2022-11-20 21:33:47 +00:00
|
|
|
|
2022-12-01 15:37:50 +00:00
|
|
|
-- setup loader and handlers
|
2022-12-01 10:06:44 +00:00
|
|
|
Loader.setup()
|
2022-11-20 21:33:47 +00:00
|
|
|
|
2022-12-01 15:37:50 +00:00
|
|
|
-- correct time delta and loaded
|
2022-12-01 15:27:52 +00:00
|
|
|
local delta = vim.loop.hrtime() - start
|
|
|
|
Util.track().time = delta -- end setup
|
2022-11-26 12:58:18 +00:00
|
|
|
if Config.plugins["lazy.nvim"] then
|
2022-12-01 15:27:52 +00:00
|
|
|
Config.plugins["lazy.nvim"]._.loaded = { time = delta, source = "init.lua" }
|
2022-11-26 12:58:18 +00:00
|
|
|
end
|
2022-11-20 21:33:47 +00:00
|
|
|
|
2022-12-01 15:37:50 +00:00
|
|
|
-- load plugins with lazy=false or Plugin.init
|
2022-12-14 20:03:53 +00:00
|
|
|
Loader.startup()
|
2022-12-01 15:37:50 +00:00
|
|
|
|
|
|
|
-- all done!
|
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-12-27 12:34:07 +00:00
|
|
|
return require("lazy.stats").stats()
|
2022-11-20 21:33:47 +00:00
|
|
|
end
|
|
|
|
|
2022-11-29 11:49:15 +00:00
|
|
|
function M.bootstrap()
|
2022-12-14 20:38:40 +00:00
|
|
|
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
|
2022-11-29 11:49:15 +00:00
|
|
|
if not vim.loop.fs_stat(lazypath) then
|
2022-12-30 13:46:18 +00:00
|
|
|
if not vim.loop.fs_stat(lazypath) then
|
|
|
|
vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath })
|
|
|
|
vim.fn.system({ "git", "-C", lazypath, "checkout", "tags/stable" }) -- last stable release
|
|
|
|
end
|
2022-11-29 11:49:15 +00:00
|
|
|
end
|
2022-12-29 15:03:23 +00:00
|
|
|
vim.opt.rtp:prepend(lazypath)
|
2022-11-29 11:49:15 +00:00
|
|
|
end
|
|
|
|
|
2022-12-14 15:07:32 +00:00
|
|
|
---@return LazyPlugin[]
|
|
|
|
function M.plugins()
|
|
|
|
return vim.tbl_values(require("lazy.core.config").plugins)
|
|
|
|
end
|
|
|
|
|
2022-12-18 10:42:27 +00:00
|
|
|
setmetatable(M, {
|
|
|
|
__index = function(_, key)
|
2022-12-18 16:36:32 +00:00
|
|
|
return function(...)
|
|
|
|
return require("lazy.view.commands").commands[key](...)
|
|
|
|
end
|
2022-12-18 10:42:27 +00:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2022-11-20 21:33:47 +00:00
|
|
|
return M
|