2022-11-22 20:28:08 +00:00
|
|
|
local Config = require("lazy.core.config")
|
2022-11-25 21:48:17 +00:00
|
|
|
local Plugin = require("lazy.core.plugin")
|
2023-10-09 10:25:42 +01:00
|
|
|
local Runner = require("lazy.manage.runner")
|
2022-11-20 21:33:47 +00:00
|
|
|
|
|
|
|
local M = {}
|
|
|
|
|
2022-11-28 10:04:32 +00:00
|
|
|
---@class ManagerOpts
|
|
|
|
---@field wait? boolean
|
|
|
|
---@field clear? boolean
|
2022-11-30 22:07:09 +00:00
|
|
|
---@field show? boolean
|
2022-11-29 09:30:14 +00:00
|
|
|
---@field mode? string
|
2022-12-24 10:15:57 +00:00
|
|
|
---@field plugins? (LazyPlugin|string)[]
|
2022-12-05 19:36:49 +00:00
|
|
|
---@field concurrency? number
|
2022-12-30 08:17:46 +00:00
|
|
|
---@field lockfile? boolean
|
2022-11-20 21:33:47 +00:00
|
|
|
|
2022-11-28 10:04:32 +00:00
|
|
|
---@param ropts RunnerOpts
|
2022-11-20 21:33:47 +00:00
|
|
|
---@param opts? ManagerOpts
|
2022-11-28 10:04:32 +00:00
|
|
|
function M.run(ropts, opts)
|
2022-11-20 21:34:55 +00:00
|
|
|
opts = opts or {}
|
|
|
|
|
2023-06-17 07:37:33 +01:00
|
|
|
local mode = opts.mode
|
|
|
|
local event = mode and ("Lazy" .. mode:sub(1, 1):upper() .. mode:sub(2))
|
|
|
|
|
|
|
|
if event then
|
|
|
|
vim.api.nvim_exec_autocmds("User", { pattern = event .. "Pre", modeline = false })
|
|
|
|
end
|
|
|
|
|
2022-11-29 09:56:17 +00:00
|
|
|
if opts.plugins then
|
2022-12-24 10:15:57 +00:00
|
|
|
---@param plugin string|LazyPlugin
|
|
|
|
opts.plugins = vim.tbl_map(function(plugin)
|
|
|
|
return type(plugin) == "string" and Config.plugins[plugin] or plugin
|
|
|
|
end, vim.tbl_values(opts.plugins))
|
2022-11-29 09:56:17 +00:00
|
|
|
ropts.plugins = opts.plugins
|
|
|
|
end
|
|
|
|
|
2022-12-05 19:36:49 +00:00
|
|
|
ropts.concurrency = ropts.concurrency or opts.concurrency or Config.options.concurrency
|
2022-11-30 22:14:31 +00:00
|
|
|
|
2022-11-20 21:34:55 +00:00
|
|
|
if opts.clear then
|
2022-12-24 10:16:24 +00:00
|
|
|
M.clear(opts.plugins)
|
2022-11-20 21:34:55 +00:00
|
|
|
end
|
|
|
|
|
2022-11-30 22:07:09 +00:00
|
|
|
if opts.show ~= false then
|
2022-11-29 06:56:29 +00:00
|
|
|
vim.schedule(function()
|
2022-11-29 09:30:14 +00:00
|
|
|
require("lazy.view").show(opts.mode)
|
2022-11-29 06:56:29 +00:00
|
|
|
end)
|
2022-11-20 21:34:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
---@type Runner
|
2022-11-28 10:04:32 +00:00
|
|
|
local runner = Runner.new(ropts)
|
|
|
|
runner:start()
|
2022-11-20 21:34:55 +00:00
|
|
|
|
2023-01-13 08:00:15 +00:00
|
|
|
vim.api.nvim_exec_autocmds("User", { pattern = "LazyRender", modeline = false })
|
2022-11-20 21:34:55 +00:00
|
|
|
|
2022-11-28 10:04:32 +00:00
|
|
|
-- wait for post-install to finish
|
2022-11-20 21:34:55 +00:00
|
|
|
runner:wait(function()
|
2023-01-13 08:00:15 +00:00
|
|
|
vim.api.nvim_exec_autocmds("User", { pattern = "LazyRender", modeline = false })
|
2022-11-30 22:06:26 +00:00
|
|
|
Plugin.update_state()
|
2022-12-23 06:43:58 +00:00
|
|
|
require("lazy.manage.checker").fast_check({ report = false })
|
2023-06-17 07:37:33 +01:00
|
|
|
if event then
|
2023-01-13 08:00:15 +00:00
|
|
|
vim.api.nvim_exec_autocmds("User", { pattern = event, modeline = false })
|
2022-12-24 10:55:42 +00:00
|
|
|
end
|
2022-11-20 21:34:55 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
if opts.wait then
|
|
|
|
runner:wait()
|
|
|
|
end
|
2022-11-28 23:15:13 +00:00
|
|
|
return runner
|
2022-11-20 21:33:47 +00:00
|
|
|
end
|
|
|
|
|
2022-12-21 21:27:36 +00:00
|
|
|
---@generic O: ManagerOpts
|
|
|
|
---@param opts? O
|
|
|
|
---@param defaults? ManagerOpts
|
|
|
|
---@return O
|
|
|
|
function M.opts(opts, defaults)
|
|
|
|
return vim.tbl_deep_extend("force", { clear = true }, defaults or {}, opts or {})
|
|
|
|
end
|
|
|
|
|
2022-11-20 21:33:47 +00:00
|
|
|
---@param opts? ManagerOpts
|
|
|
|
function M.install(opts)
|
2022-12-21 21:27:36 +00:00
|
|
|
opts = M.opts(opts, { mode = "install" })
|
2022-12-05 19:36:49 +00:00
|
|
|
return M.run({
|
2022-11-28 21:03:44 +00:00
|
|
|
pipeline = {
|
|
|
|
"git.clone",
|
2022-12-30 08:17:46 +00:00
|
|
|
{ "git.checkout", lockfile = opts.lockfile },
|
2022-11-28 21:03:44 +00:00
|
|
|
"plugin.docs",
|
2024-06-24 18:38:33 +01:00
|
|
|
{
|
|
|
|
"wait",
|
|
|
|
sync = function()
|
|
|
|
require("lazy.pkg").update()
|
|
|
|
Plugin.load()
|
|
|
|
end,
|
|
|
|
},
|
2022-12-01 06:43:28 +00:00
|
|
|
"plugin.build",
|
2022-11-28 21:03:44 +00:00
|
|
|
},
|
2022-11-28 10:04:32 +00:00
|
|
|
plugins = function(plugin)
|
2024-06-24 13:14:41 +01:00
|
|
|
return plugin.url and not (plugin._.installed and not plugin._.build)
|
2022-11-28 10:04:32 +00:00
|
|
|
end,
|
2022-12-15 13:07:37 +00:00
|
|
|
}, opts):wait(function()
|
2022-12-21 22:18:35 +00:00
|
|
|
require("lazy.manage.lock").update()
|
2022-12-15 13:07:37 +00:00
|
|
|
require("lazy.help").update()
|
|
|
|
end)
|
2022-11-20 21:33:47 +00:00
|
|
|
end
|
|
|
|
|
2022-12-30 08:17:46 +00:00
|
|
|
---@param opts? ManagerOpts
|
2022-11-20 21:33:47 +00:00
|
|
|
function M.update(opts)
|
2022-12-21 21:27:36 +00:00
|
|
|
opts = M.opts(opts, { mode = "update" })
|
2022-12-05 19:36:49 +00:00
|
|
|
return M.run({
|
2022-11-28 21:03:44 +00:00
|
|
|
pipeline = {
|
2023-01-08 07:32:03 +00:00
|
|
|
"git.origin",
|
2022-11-28 21:03:44 +00:00
|
|
|
"git.branch",
|
|
|
|
"git.fetch",
|
2023-10-10 10:41:32 +01:00
|
|
|
"git.status",
|
2022-11-28 23:15:13 +00:00
|
|
|
{ "git.checkout", lockfile = opts.lockfile },
|
2022-11-28 21:03:44 +00:00
|
|
|
"plugin.docs",
|
2024-06-24 18:38:33 +01:00
|
|
|
{
|
|
|
|
"wait",
|
|
|
|
sync = function()
|
|
|
|
require("lazy.pkg").update()
|
|
|
|
Plugin.load()
|
|
|
|
end,
|
|
|
|
},
|
2022-12-01 06:43:28 +00:00
|
|
|
"plugin.build",
|
2022-11-28 21:03:44 +00:00
|
|
|
{ "git.log", updated = true },
|
|
|
|
},
|
2022-11-28 10:04:32 +00:00
|
|
|
plugins = function(plugin)
|
2022-12-06 10:12:54 +00:00
|
|
|
return plugin.url and plugin._.installed
|
2022-11-28 10:04:32 +00:00
|
|
|
end,
|
2022-11-28 23:15:13 +00:00
|
|
|
}, opts):wait(function()
|
|
|
|
require("lazy.manage.lock").update()
|
2022-12-15 13:07:37 +00:00
|
|
|
require("lazy.help").update()
|
2022-11-28 23:15:13 +00:00
|
|
|
end)
|
2022-11-20 21:33:47 +00:00
|
|
|
end
|
2022-12-21 21:27:36 +00:00
|
|
|
--
|
|
|
|
---@param opts? ManagerOpts
|
|
|
|
function M.restore(opts)
|
|
|
|
opts = M.opts(opts, { mode = "restore", lockfile = true })
|
|
|
|
return M.update(opts)
|
|
|
|
end
|
2022-11-20 21:33:47 +00:00
|
|
|
|
2022-12-05 19:36:49 +00:00
|
|
|
---@param opts? ManagerOpts
|
2022-11-29 07:23:23 +00:00
|
|
|
function M.check(opts)
|
2022-12-21 21:27:36 +00:00
|
|
|
opts = M.opts(opts, { mode = "check" })
|
2022-11-29 07:23:23 +00:00
|
|
|
opts = opts or {}
|
2022-12-05 19:36:49 +00:00
|
|
|
return M.run({
|
2022-11-29 07:23:23 +00:00
|
|
|
pipeline = {
|
2023-01-08 07:32:03 +00:00
|
|
|
{ "git.origin", check = true },
|
2022-11-29 07:23:23 +00:00
|
|
|
"git.fetch",
|
2023-10-10 10:41:32 +01:00
|
|
|
"git.status",
|
2022-11-29 07:23:23 +00:00
|
|
|
"wait",
|
|
|
|
{ "git.log", check = true },
|
|
|
|
},
|
|
|
|
plugins = function(plugin)
|
2022-12-06 10:12:54 +00:00
|
|
|
return plugin.url and plugin._.installed
|
2022-11-29 07:23:23 +00:00
|
|
|
end,
|
|
|
|
}, opts)
|
|
|
|
end
|
|
|
|
|
2023-01-22 13:30:12 +00:00
|
|
|
---@param opts? ManagerOpts | {check?:boolean}
|
2022-11-22 20:12:50 +00:00
|
|
|
function M.log(opts)
|
2022-12-21 21:27:36 +00:00
|
|
|
opts = M.opts(opts, { mode = "log" })
|
2022-12-05 19:36:49 +00:00
|
|
|
return M.run({
|
2023-01-08 07:32:03 +00:00
|
|
|
pipeline = {
|
|
|
|
{ "git.origin", check = true },
|
2023-01-22 13:30:12 +00:00
|
|
|
{ "git.log", check = opts.check },
|
2023-01-08 07:32:03 +00:00
|
|
|
},
|
2022-11-28 10:04:32 +00:00
|
|
|
plugins = function(plugin)
|
2022-12-06 10:12:54 +00:00
|
|
|
return plugin.url and plugin._.installed
|
2022-11-28 10:04:32 +00:00
|
|
|
end,
|
|
|
|
}, opts)
|
2022-11-23 15:12:43 +00:00
|
|
|
end
|
|
|
|
|
2023-01-01 08:41:43 +00:00
|
|
|
---@param opts? ManagerOpts
|
|
|
|
function M.build(opts)
|
|
|
|
opts = M.opts(opts, { mode = "build" })
|
|
|
|
return M.run({
|
|
|
|
pipeline = { { "plugin.build", force = true } },
|
|
|
|
plugins = function()
|
|
|
|
return false
|
|
|
|
end,
|
|
|
|
}, opts)
|
|
|
|
end
|
|
|
|
|
2022-12-21 21:27:36 +00:00
|
|
|
---@param opts? ManagerOpts
|
|
|
|
function M.sync(opts)
|
2022-12-24 10:55:42 +00:00
|
|
|
opts = M.opts(opts)
|
2022-12-21 21:27:36 +00:00
|
|
|
if opts.clear then
|
|
|
|
M.clear()
|
|
|
|
opts.clear = false
|
|
|
|
end
|
2022-12-24 10:55:42 +00:00
|
|
|
if opts.show ~= false then
|
|
|
|
vim.schedule(function()
|
|
|
|
require("lazy.view").show("sync")
|
|
|
|
end)
|
|
|
|
opts.show = false
|
|
|
|
end
|
2023-02-01 07:06:48 +00:00
|
|
|
|
2023-06-18 21:38:05 +01:00
|
|
|
vim.api.nvim_exec_autocmds("User", { pattern = "LazySyncPre", modeline = false })
|
|
|
|
|
2023-02-01 07:06:48 +00:00
|
|
|
local clean_opts = vim.deepcopy(opts)
|
|
|
|
clean_opts.plugins = nil
|
|
|
|
local clean = M.clean(clean_opts)
|
2022-12-24 10:55:42 +00:00
|
|
|
local install = M.install(opts)
|
|
|
|
local update = M.update(opts)
|
|
|
|
clean:wait(function()
|
|
|
|
install:wait(function()
|
|
|
|
update:wait(function()
|
2023-01-13 08:00:15 +00:00
|
|
|
vim.api.nvim_exec_autocmds("User", { pattern = "LazySync", modeline = false })
|
2022-12-24 10:55:42 +00:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|
2022-12-21 21:27:36 +00:00
|
|
|
end
|
|
|
|
|
2022-11-20 21:33:47 +00:00
|
|
|
---@param opts? ManagerOpts
|
|
|
|
function M.clean(opts)
|
2022-12-21 21:27:36 +00:00
|
|
|
opts = M.opts(opts, { mode = "clean" })
|
2022-12-05 19:36:49 +00:00
|
|
|
return M.run({
|
2022-11-28 21:03:44 +00:00
|
|
|
pipeline = { "fs.clean" },
|
2022-11-28 10:04:32 +00:00
|
|
|
plugins = Config.to_clean,
|
2022-12-22 07:09:28 +00:00
|
|
|
}, opts):wait(function()
|
|
|
|
require("lazy.manage.lock").update()
|
|
|
|
end)
|
2022-11-20 21:33:47 +00:00
|
|
|
end
|
|
|
|
|
2022-12-24 10:16:24 +00:00
|
|
|
---@param plugins? LazyPlugin[]
|
|
|
|
function M.clear(plugins)
|
|
|
|
for _, plugin in pairs(plugins or Config.plugins) do
|
2022-12-31 15:01:59 +00:00
|
|
|
plugin._.updates = nil
|
2022-11-28 10:19:50 +00:00
|
|
|
plugin._.updated = nil
|
2022-11-28 23:15:13 +00:00
|
|
|
plugin._.cloned = nil
|
|
|
|
plugin._.dirty = nil
|
2022-11-20 21:34:55 +00:00
|
|
|
-- clear finished tasks
|
2022-11-28 10:19:50 +00:00
|
|
|
if plugin._.tasks then
|
2022-11-20 22:25:56 +00:00
|
|
|
---@param task LazyTask
|
2022-11-28 10:19:50 +00:00
|
|
|
plugin._.tasks = vim.tbl_filter(function(task)
|
2024-06-26 17:31:31 +01:00
|
|
|
return task:is_running() or task:has_errors()
|
2022-11-28 10:19:50 +00:00
|
|
|
end, plugin._.tasks)
|
2022-11-20 21:34:55 +00:00
|
|
|
end
|
|
|
|
end
|
2023-01-13 08:00:15 +00:00
|
|
|
vim.api.nvim_exec_autocmds("User", { pattern = "LazyRender", modeline = false })
|
2022-11-20 21:33:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|