refactor: moved all plugin state to Plugin._

This commit is contained in:
Folke Lemaitre 2022-11-28 11:19:50 +01:00
parent 352dbadcb6
commit 28af1e1ac3
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
9 changed files with 49 additions and 46 deletions

View file

@ -49,7 +49,7 @@ function M.install(opts)
M.run({
pipeline = { "git.install", { "plugin.docs", "plugin.run" } },
plugins = function(plugin)
return plugin.uri and not plugin.installed
return plugin.uri and not plugin._.installed
end,
}, opts)
end
@ -59,7 +59,7 @@ function M.update(opts)
M.run({
pipeline = { "git.update", { "plugin.docs", "plugin.run" }, "git.log" },
plugins = function(plugin)
return plugin.uri and plugin.installed
return plugin.uri and plugin._.installed
end,
}, opts)
end
@ -69,7 +69,7 @@ function M.log(opts)
M.run({
pipeline = { "git.log" },
plugins = function(plugin)
return plugin.uri and plugin.installed
return plugin.uri and plugin._.installed
end,
}, opts)
end
@ -86,13 +86,13 @@ end
function M.clear()
for _, plugin in pairs(Config.plugins) do
-- clear updated status
plugin.updated = nil
plugin._.updated = nil
-- clear finished tasks
if plugin.tasks then
if plugin._.tasks then
---@param task LazyTask
plugin.tasks = vim.tbl_filter(function(task)
plugin._.tasks = vim.tbl_filter(function(task)
return task:is_running()
end, plugin.tasks)
end, plugin._.tasks)
end
end
vim.cmd([[do User LazyRender]])

View file

@ -8,7 +8,7 @@ M.log = {
if opts.interactive ~= true or not Util.file_exists(plugin.dir .. "/.git") then
return false
end
return plugin.updated == nil or plugin.updated.from ~= plugin.updated.to
return plugin._.updated == nil or plugin._.updated.from ~= plugin._.updated.to
end,
run = function(self)
local args = {
@ -20,8 +20,8 @@ M.log = {
"--color=never",
}
if self.plugin.updated then
table.insert(args, self.plugin.updated.from .. ".." .. (self.plugin.updated.to or "HEAD"))
if self.plugin._.updated then
table.insert(args, self.plugin._.updated.from .. ".." .. (self.plugin._.updated.to or "HEAD"))
else
table.insert(args, "--since=7 days ago")
end
@ -59,11 +59,11 @@ M.update = {
on_exit = function(ok)
if ok then
local git_new = assert(Util.git_info(self.plugin.dir))
self.plugin.updated = {
self.plugin._.updated = {
from = git.hash,
to = git_new.hash,
}
self.plugin.dirty = not vim.deep_equal(git, git_new)
self.plugin._.dirty = not vim.deep_equal(git, git_new)
end
end,
})
@ -103,8 +103,8 @@ M.install = {
args = args,
on_exit = function(ok)
if ok then
self.plugin.installed = true
self.plugin.dirty = true
self.plugin._.installed = true
self.plugin._.dirty = true
end
end,
})

View file

@ -39,8 +39,8 @@ function Task.new(plugin, type, task, opts)
self.type = type
self.output = ""
self.status = ""
plugin.tasks = plugin.tasks or {}
table.insert(plugin.tasks, self)
plugin._.tasks = plugin._.tasks or {}
table.insert(plugin._.tasks, self)
return self
end

View file

@ -6,7 +6,7 @@ local M = {}
M.run = {
needed = function(plugin)
return plugin.dirty and (plugin.opt == false or plugin.run)
return plugin._.dirty and (plugin.opt == false or plugin.run)
end,
run = function(self)
Loader.load(self.plugin, { task = "run" }, { load_start = true })
@ -47,13 +47,13 @@ M.clean = {
vim.loop.fs_unlink(dir)
end
self.plugin.installed = false
self.plugin._.installed = false
end,
}
M.docs = {
needed = function(plugin)
return plugin.dirty
return plugin._.dirty
end,
run = function(self)
local docs = self.plugin.dir .. "/doc/"