mirror of https://github.com/folke/lazy.nvim.git
feat(plugin)!: `cond` is now the same as `enabled`, but skips clean
This commit is contained in:
parent
f8611632d0
commit
fbb0bea2db
|
@ -297,15 +297,8 @@ 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
|
return
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@diagnostic disable-next-line: assign-type-mismatch
|
---@diagnostic disable-next-line: assign-type-mismatch
|
||||||
|
|
|
@ -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, {
|
||||||
|
|
Loading…
Reference in New Issue