feat(plugin)!: `cond` is now the same as `enabled`, but skips clean

This commit is contained in:
Folke Lemaitre 2023-07-06 15:30:01 +02:00
parent f8611632d0
commit fbb0bea2db
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
2 changed files with 31 additions and 13 deletions

View File

@ -297,15 +297,8 @@ function M._load(plugin, reason, opts)
return Util.error("Plugin " .. plugin.name .. " is not installed")
end
local cond = plugin.cond
if cond == nil then
cond = Config.options.defaults.cond
end
if cond ~= nil and not (opts and opts.force) then
if cond == false or (type(cond) == "function" and not cond(plugin)) then
plugin._.cond = false
return
end
if plugin._.cond == false and not (opts and opts.force) then
return
end
---@diagnostic disable-next-line: assign-type-mismatch

View File

@ -146,13 +146,20 @@ function Spec:warn(msg)
self:log(msg, vim.log.levels.WARN)
end
function Spec:fix_disabled()
function Spec:fix_cond()
for _, plugin in pairs(self.plugins) do
if not plugin.name or not plugin.dir then
self:error("Plugin spec for **" .. plugin.name .. "** not found.\n```lua\n" .. vim.inspect(plugin) .. "\n```")
self.plugins[plugin.name] = nil
local cond = plugin.cond
if cond == nil then
cond = Config.options.defaults.cond
end
if cond == false or (type(cond) == "function" and not cond(plugin)) then
plugin._.cond = false
plugin.enabled = false
end
end
end
function Spec:fix_optional()
if not self.optional then
---@param plugin LazyPlugin
local function all_optional(plugin)
@ -166,6 +173,18 @@ function Spec:fix_disabled()
end
end
end
end
function Spec:fix_disabled()
for _, plugin in pairs(self.plugins) do
if not plugin.name or not plugin.dir then
self:error("Plugin spec for **" .. plugin.name .. "** not found.\n```lua\n" .. vim.inspect(plugin) .. "\n```")
self.plugins[plugin.name] = nil
end
end
self:fix_optional()
self:fix_cond()
---@type table<string,string[]> plugin to parent plugin
local dep_of = {}
@ -384,6 +403,12 @@ function M.update_state()
end
end
for _, plugin in pairs(Config.spec.disabled) do
if plugin._.cond == false then
installed[plugin.name] = nil
end
end
Config.to_clean = {}
for pack, dir_type in pairs(installed) do
table.insert(Config.to_clean, {