lazy.nvim/lua/lazy/manage/init.lua

143 lines
2.8 KiB
Lua
Raw Normal View History

local Config = require("lazy.core.config")
local Runner = require("lazy.manage.runner")
local Plugin = require("lazy.core.plugin")
2022-11-21 05:33:47 +08:00
local M = {}
2022-11-28 18:04:32 +08:00
---@class ManagerOpts
---@field wait? boolean
---@field clear? boolean
---@field interactive? boolean
2022-11-29 17:30:14 +08:00
---@field mode? string
---@field plugins? LazyPlugin[]
2022-11-21 05:33:47 +08:00
2022-11-28 18:04:32 +08:00
---@param ropts RunnerOpts
2022-11-21 05:33:47 +08:00
---@param opts? ManagerOpts
2022-11-28 18:04:32 +08:00
function M.run(ropts, opts)
2022-11-21 05:34:55 +08:00
opts = opts or {}
2022-11-28 18:04:32 +08:00
if opts.interactive == nil then
opts.interactive = Config.options.interactive
end
2022-11-21 05:34:55 +08:00
if opts.plugins then
ropts.plugins = opts.plugins
end
2022-11-21 05:34:55 +08:00
if opts.clear then
M.clear()
end
2022-11-28 18:04:32 +08:00
if opts.interactive then
vim.schedule(function()
2022-11-29 17:30:14 +08:00
require("lazy.view").show(opts.mode)
end)
2022-11-21 05:34:55 +08:00
end
---@type Runner
2022-11-28 18:04:32 +08:00
local runner = Runner.new(ropts)
runner:start()
2022-11-21 05:34:55 +08:00
vim.cmd([[do User LazyRender]])
2022-11-28 18:04:32 +08:00
-- wait for post-install to finish
2022-11-21 05:34:55 +08:00
runner:wait(function()
2022-11-28 18:04:32 +08:00
vim.cmd([[do User LazyRender]])
2022-11-21 05:34:55 +08:00
end)
if opts.wait then
runner:wait()
end
2022-11-29 07:15:13 +08:00
return runner
2022-11-21 05:33:47 +08:00
end
---@param opts? ManagerOpts
function M.install(opts)
2022-11-28 18:04:32 +08:00
M.run({
pipeline = {
"fs.symlink",
"git.clone",
"git.checkout",
"plugin.docs",
"wait",
"plugin.run",
},
2022-11-28 18:04:32 +08:00
plugins = function(plugin)
return plugin.uri and not plugin._.installed
2022-11-28 18:04:32 +08:00
end,
}, opts)
2022-11-21 05:33:47 +08:00
end
2022-11-29 07:15:13 +08:00
---@param opts? ManagerOpts|{lockfile?:boolean}
2022-11-21 05:33:47 +08:00
function M.update(opts)
2022-11-29 07:15:13 +08:00
opts = opts or {}
2022-11-28 18:04:32 +08:00
M.run({
pipeline = {
"fs.symlink",
"git.branch",
"git.fetch",
2022-11-29 07:15:13 +08:00
{ "git.checkout", lockfile = opts.lockfile },
"plugin.docs",
"wait",
2022-11-29 07:15:13 +08:00
"plugin.run",
{ "git.log", updated = true },
},
2022-11-28 18:04:32 +08:00
plugins = function(plugin)
return plugin.uri and plugin._.installed
2022-11-28 18:04:32 +08:00
end,
2022-11-29 07:15:13 +08:00
}, opts):wait(function()
require("lazy.manage.lock").update()
end)
2022-11-21 05:33:47 +08:00
end
function M.check(opts)
opts = opts or {}
M.run({
pipeline = {
"git.fetch",
"wait",
{ "git.log", check = true },
},
plugins = function(plugin)
return plugin.uri and plugin._.installed
end,
}, opts)
end
2022-11-23 04:12:50 +08:00
---@param opts? ManagerOpts
function M.log(opts)
2022-11-28 18:04:32 +08:00
M.run({
pipeline = { "git.log" },
plugins = function(plugin)
return plugin.uri and plugin._.installed
2022-11-28 18:04:32 +08:00
end,
}, opts)
2022-11-23 23:12:43 +08:00
end
2022-11-21 05:33:47 +08:00
---@param opts? ManagerOpts
function M.clean(opts)
Plugin.update_state()
2022-11-28 18:04:32 +08:00
M.run({
pipeline = { "fs.clean" },
2022-11-28 18:04:32 +08:00
plugins = Config.to_clean,
}, opts)
2022-11-21 05:33:47 +08:00
end
function M.clear()
Plugin.update_state()
2022-11-21 07:27:28 +08:00
for _, plugin in pairs(Config.plugins) do
plugin._.updated = nil
2022-11-29 07:15:13 +08:00
plugin._.cloned = nil
plugin._.dirty = nil
2022-11-21 05:34:55 +08:00
-- clear finished tasks
if plugin._.tasks then
2022-11-21 06:25:56 +08:00
---@param task LazyTask
plugin._.tasks = vim.tbl_filter(function(task)
2022-11-28 18:04:32 +08:00
return task:is_running()
end, plugin._.tasks)
2022-11-21 05:34:55 +08:00
end
end
2022-11-23 23:12:43 +08:00
vim.cmd([[do User LazyRender]])
2022-11-21 05:33:47 +08:00
end
return M