lazy.nvim/lua/lazy/init.lua

91 lines
2.3 KiB
Lua
Raw Permalink Normal View History

2022-11-20 21:33:47 +00:00
local M = {}
---@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
function M.setup(spec, opts)
2022-12-14 20:25:11 +00:00
if vim.fn.has("nvim-0.8.0") ~= 1 then
vim.notify("lazy.nvim requires Neovim >= 0.8.0", vim.log.levels.ERROR, { title = "lazy.nvim" })
return
end
if not vim.go.loadplugins then
return
end
if vim.g.lazy_did_setup then
vim.notify("Re-sourcing your config is not supported with lazy.nvim", vim.log.levels.WARN, { title = "lazy.nvim" })
2022-12-02 09:02:34 +00:00
return
end
vim.g.lazy_did_setup = true
local start = vim.loop.hrtime()
2022-12-01 15:37:50 +00:00
if not (opts and opts.performance and opts.performance.cache and opts.performance.cache.enabled == false) then
-- load module cache before anything else
require("lazy.core.cache").setup(opts)
end
local Util = require("lazy.core.util")
local Config = require("lazy.core.config")
local Loader = require("lazy.core.loader")
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
Util.track("module", vim.loop.hrtime() - start)
2022-12-01 15:37:50 +00:00
-- load config
Util.track("config")
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
Plugin.load()
2022-11-20 21:33:47 +00:00
2022-12-01 15:37:50 +00:00
-- setup loader and handlers
Loader.setup()
2022-11-20 21:33:47 +00:00
2022-12-01 15:37:50 +00:00
-- correct time delta and loaded
local delta = vim.loop.hrtime() - start
Util.track().time = delta -- end setup
if Config.plugins["lazy.nvim"] then
Config.plugins["lazy.nvim"]._.loaded = { time = delta, source = "init.lua" }
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
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()
local ret = { count = 0, loaded = 0 }
for _, plugin in pairs(require("lazy.core.config").plugins) do
2022-11-20 21:34:55 +00:00
ret.count = ret.count + 1
if plugin._.loaded then
2022-11-20 21:34:55 +00:00
ret.loaded = ret.loaded + 1
end
end
return ret
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
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"--single-branch",
"git@github.com:folke/lazy.nvim.git",
2022-11-29 11:49:15 +00:00
lazypath,
})
end
vim.opt.runtimepath: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-11-20 21:33:47 +00:00
return M