From fbb0bea2db1963b4b83a3cb1f0c09d78a2ab286f Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 6 Jul 2023 15:30:01 +0200 Subject: [PATCH] feat(plugin)!: `cond` is now the same as `enabled`, but skips clean --- lua/lazy/core/loader.lua | 11 ++--------- lua/lazy/core/plugin.lua | 33 +++++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/lua/lazy/core/loader.lua b/lua/lazy/core/loader.lua index 3065040..91a3f3a 100644 --- a/lua/lazy/core/loader.lua +++ b/lua/lazy/core/loader.lua @@ -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 diff --git a/lua/lazy/core/plugin.lua b/lua/lazy/core/plugin.lua index c373f6d..3019d8a 100644 --- a/lua/lazy/core/plugin.lua +++ b/lua/lazy/core/plugin.lua @@ -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 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, {