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,16 +297,9 @@ function M._load(plugin, reason, opts)
return Util.error("Plugin " .. plugin.name .. " is not installed") return Util.error("Plugin " .. plugin.name .. " is not installed")
end end
local cond = plugin.cond if plugin._.cond == false and not (opts and opts.force) then
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 return
end end
end
---@diagnostic disable-next-line: assign-type-mismatch ---@diagnostic disable-next-line: assign-type-mismatch
plugin._.loaded = {} plugin._.loaded = {}

View File

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