From aa8a33218b3f8eec70b2c48851c234aaf1f87ac0 Mon Sep 17 00:00:00 2001 From: abeldekat Date: Fri, 21 Jul 2023 11:54:56 +0200 Subject: [PATCH] deps_of_all_optional: Second, also disable unneeded deps from plugins marked as all optional --- lua/lazy/core/plugin.lua | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lua/lazy/core/plugin.lua b/lua/lazy/core/plugin.lua index b9d3939..ea9a04e 100644 --- a/lua/lazy/core/plugin.lua +++ b/lua/lazy/core/plugin.lua @@ -185,6 +185,7 @@ function Spec:fix_cond() end function Spec:fix_optional() + local all_optional_deps = {} if not self.optional then ---@param plugin LazyPlugin local function all_optional(plugin) @@ -195,9 +196,13 @@ function Spec:fix_optional() for _, plugin in pairs(self.plugins) do if plugin.optional and all_optional(plugin) then self.plugins[plugin.name] = nil + if plugin.dependencies then + vim.list_extend(all_optional_deps, plugin.dependencies) + end end end end + return all_optional_deps end function Spec:fix_disabled() @@ -208,15 +213,16 @@ function Spec:fix_disabled() end end - self:fix_optional() - self:fix_cond() - ---@type table plugin to parent plugin local dep_of = {} ---@type string[] dependencies of disabled plugins local disabled_deps = {} + ---@type string[] dependencies of plugins that are all optional + local all_optional_deps = self:fix_optional() + self:fix_cond() + for _, plugin in pairs(self.plugins) do local enabled = not (plugin.enabled == false or (type(plugin.enabled) == "function" and not plugin.enabled())) if enabled then @@ -234,6 +240,10 @@ function Spec:fix_disabled() end end + -- fix deps of plugins that are all optional + self:fix_dependencies(all_optional_deps, dep_of, function(dep_name) + self.plugins[dep_name] = nil + end) -- fix deps of disabled plugins self:fix_dependencies(disabled_deps, dep_of, function(dep_name) local plugin = self.plugins[dep_name]