Skip to content

Commit fbb0bea

Browse files
committed
feat(plugin)!: cond is now the same as enabled, but skips clean
1 parent f861163 commit fbb0bea

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

lua/lazy/core/loader.lua

+2-9
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,8 @@ function M._load(plugin, reason, opts)
297297
return Util.error("Plugin " .. plugin.name .. " is not installed")
298298
end
299299

300-
local cond = plugin.cond
301-
if cond == nil then
302-
cond = Config.options.defaults.cond
303-
end
304-
if cond ~= nil and not (opts and opts.force) then
305-
if cond == false or (type(cond) == "function" and not cond(plugin)) then
306-
plugin._.cond = false
307-
return
308-
end
300+
if plugin._.cond == false and not (opts and opts.force) then
301+
return
309302
end
310303

311304
---@diagnostic disable-next-line: assign-type-mismatch

lua/lazy/core/plugin.lua

+29-4
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,20 @@ function Spec:warn(msg)
146146
self:log(msg, vim.log.levels.WARN)
147147
end
148148

149-
function Spec:fix_disabled()
149+
function Spec:fix_cond()
150150
for _, plugin in pairs(self.plugins) do
151-
if not plugin.name or not plugin.dir then
152-
self:error("Plugin spec for **" .. plugin.name .. "** not found.\n```lua\n" .. vim.inspect(plugin) .. "\n```")
153-
self.plugins[plugin.name] = nil
151+
local cond = plugin.cond
152+
if cond == nil then
153+
cond = Config.options.defaults.cond
154+
end
155+
if cond == false or (type(cond) == "function" and not cond(plugin)) then
156+
plugin._.cond = false
157+
plugin.enabled = false
154158
end
155159
end
160+
end
161+
162+
function Spec:fix_optional()
156163
if not self.optional then
157164
---@param plugin LazyPlugin
158165
local function all_optional(plugin)
@@ -166,6 +173,18 @@ function Spec:fix_disabled()
166173
end
167174
end
168175
end
176+
end
177+
178+
function Spec:fix_disabled()
179+
for _, plugin in pairs(self.plugins) do
180+
if not plugin.name or not plugin.dir then
181+
self:error("Plugin spec for **" .. plugin.name .. "** not found.\n```lua\n" .. vim.inspect(plugin) .. "\n```")
182+
self.plugins[plugin.name] = nil
183+
end
184+
end
185+
186+
self:fix_optional()
187+
self:fix_cond()
169188

170189
---@type table<string,string[]> plugin to parent plugin
171190
local dep_of = {}
@@ -384,6 +403,12 @@ function M.update_state()
384403
end
385404
end
386405

406+
for _, plugin in pairs(Config.spec.disabled) do
407+
if plugin._.cond == false then
408+
installed[plugin.name] = nil
409+
end
410+
end
411+
387412
Config.to_clean = {}
388413
for pack, dir_type in pairs(installed) do
389414
table.insert(Config.to_clean, {

0 commit comments

Comments
 (0)