mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-06-28 11:24:14 +00:00
deps_of_all_optional: First, refactor the code responsible for disabling unneeded deps to be more generic
This commit is contained in:
parent
ed15f6b394
commit
bbfcd98ce8
1 changed files with 32 additions and 21 deletions
|
@ -146,6 +146,31 @@ function Spec:warn(msg)
|
|||
self:log(msg, vim.log.levels.WARN)
|
||||
end
|
||||
|
||||
---@param gathered_deps string[]
|
||||
---@param dep_of table<string,string[]>
|
||||
---@param on_disable fun(string):nil
|
||||
function Spec:fix_dependencies(gathered_deps, dep_of, on_disable)
|
||||
local function should_disable(dep_name)
|
||||
for _, parent in ipairs(dep_of[dep_name] or {}) do
|
||||
if self.plugins[parent] then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
for _, dep_name in ipairs(gathered_deps) do
|
||||
-- only check if the plugin is still enabled and it is a dep
|
||||
if self.plugins[dep_name] and self.plugins[dep_name]._.dep then
|
||||
-- check if the dep is still used by another plugin
|
||||
if should_disable(dep_name) then
|
||||
-- disable the dep when no longer needed
|
||||
on_disable(dep_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Spec:fix_cond()
|
||||
for _, plugin in pairs(self.plugins) do
|
||||
local cond = plugin.cond
|
||||
|
@ -209,27 +234,13 @@ function Spec:fix_disabled()
|
|||
end
|
||||
end
|
||||
|
||||
-- check deps of disabled plugins
|
||||
for _, dep in ipairs(disabled_deps) do
|
||||
-- only check if the plugin is still enabled and it is a dep
|
||||
if self.plugins[dep] and self.plugins[dep]._.dep then
|
||||
-- check if the dep is still used by another plugin
|
||||
local keep = false
|
||||
for _, parent in ipairs(dep_of[dep] or {}) do
|
||||
if self.plugins[parent] then
|
||||
keep = true
|
||||
break
|
||||
end
|
||||
end
|
||||
-- disable the dep when no longer needed
|
||||
if not keep then
|
||||
local plugin = self.plugins[dep]
|
||||
-- fix deps of disabled plugins
|
||||
self:fix_dependencies(disabled_deps, dep_of, function(dep_name)
|
||||
local plugin = self.plugins[dep_name]
|
||||
plugin._.kind = "disabled"
|
||||
self.plugins[plugin.name] = nil
|
||||
self.disabled[plugin.name] = plugin
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
---@param msg string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue