Skip to content

Commit

Permalink
feat(plugin)!: cond is now the same as enabled, but skips clean
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jul 6, 2023
1 parent f861163 commit fbb0bea
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
11 changes: 2 additions & 9 deletions lua/lazy/core/loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 29 additions & 4 deletions lua/lazy/core/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 = {}
Expand Down Expand Up @@ -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, {
Expand Down

5 comments on commit fbb0bea

@Fau818
Copy link

@Fau818 Fau818 commented on fbb0bea Jul 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this can be reverted?
I use lazy.nvim to manage repo like python-type-stubs.
This plugin manager could help me follow up with the latest repo commit by set cond = false.

@folke
Copy link
Owner Author

@folke folke commented on fbb0bea Jul 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want to have the plugin as active, but never load? Just use event="User Whatever". Condition will never be met. Would act the same as privious cond

@Fau818
Copy link

@Fau818 Fau818 commented on fbb0bea Jul 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want to have the plugin as active, but never load? Just use event="User Whatever". Condition will never be met. Would act the same as privious cond

Thanks! : )

@aarondill
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fau818 or, just set lazy=true. This should never be loaded, unless required in lua

@Fau818
Copy link

@Fau818 Fau818 commented on fbb0bea Jul 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fau818 or, just set lazy=true. This should never be loaded, unless required in lua

Thank you, and your solution is also great!
It's my fault, there are indeed many ways to solve this problem.

Please sign in to comment.