prioritize plugin cond

- loader: Don't enable plugin's lazy loaders if plugin's condition isn't met
- manage: Only Check for updates if plugin's condition is met
- view: Don't show lazy loader details for disabled plugins
This commit is contained in:
MurdeRM3L0DY 2023-02-20 20:11:41 +01:00
commit 916ac4a4b0
4 changed files with 20 additions and 11 deletions

View file

@ -42,9 +42,20 @@ end
---@param plugin LazyPlugin
function M.enable(plugin)
if not plugin._.loaded then
for type, handler in pairs(M.handlers) do
if plugin[type] then
handler:add(plugin)
local cond = type(plugin.cond) == "function" and plugin.cond
or function()
if plugin.cond == nil then
return true
end
return plugin.cond
end
plugin._.cond = cond()
if plugin._.cond then
for type, handler in pairs(M.handlers) do
if plugin[type] then
handler:add(plugin)
end
end
end
end

View file

@ -131,7 +131,7 @@ function M.check(opts)
{ "git.log", check = true },
},
plugins = function(plugin)
return plugin.url and plugin._.installed
return plugin.url and plugin._.installed and plugin._.cond
end,
}, opts)
end

View file

@ -397,7 +397,7 @@ function M:plugin(plugin)
local plugin_start = self:row()
if plugin._.loaded then
self:reason(plugin._.loaded)
else
elseif plugin._.cond then
self:append(" ")
local reason = {}
for handler in pairs(Handler.types) do

View file

@ -13,7 +13,7 @@ end
---@alias LazySection {title:string, filter:fun(plugin:LazyPlugin):boolean?}
---@type LazySection[]
return {
local sections = {
{
filter = function(plugin)
return has_task(plugin, function(task)
@ -47,21 +47,18 @@ return {
title = "Breaking Changes",
},
{
---@param plugin LazyPlugin
filter = function(plugin)
return plugin._.updated and plugin._.updated.from ~= plugin._.updated.to
end,
title = "Updated",
},
{
---@param plugin LazyPlugin
filter = function(plugin)
return plugin._.cloned
end,
title = "Installed",
},
{
---@param plugin LazyPlugin
filter = function(plugin)
return plugin._.updates
end,
@ -95,14 +92,15 @@ return {
},
{
filter = function(plugin)
return plugin._.installed
return plugin._.installed and plugin._.cond
end,
title = "Not Loaded",
},
{
filter = function(plugin)
return plugin._.kind == "disabled"
return plugin._.kind == "disabled" or not plugin._.cond
end,
title = "Disabled",
},
}
return sections