@@ -146,6 +146,31 @@ function Spec:warn(msg)
146
146
self :log (msg , vim .log .levels .WARN )
147
147
end
148
148
149
+ --- @param gathered_deps string[]
150
+ --- @param dep_of table<string,string[]>
151
+ --- @param on_disable fun ( string ): nil
152
+ function Spec :fix_dependencies (gathered_deps , dep_of , on_disable )
153
+ local function should_disable (dep_name )
154
+ for _ , parent in ipairs (dep_of [dep_name ] or {}) do
155
+ if self .plugins [parent ] then
156
+ return false
157
+ end
158
+ end
159
+ return true
160
+ end
161
+
162
+ for _ , dep_name in ipairs (gathered_deps ) do
163
+ -- only check if the plugin is still enabled and it is a dep
164
+ if self .plugins [dep_name ] and self .plugins [dep_name ]._ .dep then
165
+ -- check if the dep is still used by another plugin
166
+ if should_disable (dep_name ) then
167
+ -- disable the dep when no longer needed
168
+ on_disable (dep_name )
169
+ end
170
+ end
171
+ end
172
+ end
173
+
149
174
function Spec :fix_cond ()
150
175
for _ , plugin in pairs (self .plugins ) do
151
176
local cond = plugin .cond
@@ -159,7 +184,9 @@ function Spec:fix_cond()
159
184
end
160
185
end
161
186
187
+ --- @return string[]
162
188
function Spec :fix_optional ()
189
+ local all_optional_deps = {}
163
190
if not self .optional then
164
191
--- @param plugin LazyPlugin
165
192
local function all_optional (plugin )
@@ -170,9 +197,13 @@ function Spec:fix_optional()
170
197
for _ , plugin in pairs (self .plugins ) do
171
198
if plugin .optional and all_optional (plugin ) then
172
199
self .plugins [plugin .name ] = nil
200
+ if plugin .dependencies then
201
+ vim .list_extend (all_optional_deps , plugin .dependencies )
202
+ end
173
203
end
174
204
end
175
205
end
206
+ return all_optional_deps
176
207
end
177
208
178
209
function Spec :fix_disabled ()
@@ -183,15 +214,16 @@ function Spec:fix_disabled()
183
214
end
184
215
end
185
216
186
- self :fix_optional ()
187
- self :fix_cond ()
188
-
189
217
--- @type table<string,string[]> plugin to parent plugin
190
218
local dep_of = {}
191
219
192
220
--- @type string[] dependencies of disabled plugins
193
221
local disabled_deps = {}
194
222
223
+ --- @type string[] dependencies of plugins that are completely optional
224
+ local all_optional_deps = self :fix_optional ()
225
+ self :fix_cond ()
226
+
195
227
for _ , plugin in pairs (self .plugins ) do
196
228
local enabled = not (plugin .enabled == false or (type (plugin .enabled ) == " function" and not plugin .enabled ()))
197
229
if enabled then
@@ -209,27 +241,17 @@ function Spec:fix_disabled()
209
241
end
210
242
end
211
243
212
- -- check deps of disabled plugins
213
- for _ , dep in ipairs (disabled_deps ) do
214
- -- only check if the plugin is still enabled and it is a dep
215
- if self .plugins [dep ] and self .plugins [dep ]._ .dep then
216
- -- check if the dep is still used by another plugin
217
- local keep = false
218
- for _ , parent in ipairs (dep_of [dep ] or {}) do
219
- if self .plugins [parent ] then
220
- keep = true
221
- break
222
- end
223
- end
224
- -- disable the dep when no longer needed
225
- if not keep then
226
- local plugin = self .plugins [dep ]
227
- plugin ._ .kind = " disabled"
228
- self .plugins [plugin .name ] = nil
229
- self .disabled [plugin .name ] = plugin
230
- end
231
- end
232
- end
244
+ -- fix deps of plugins that are completely optional
245
+ self :fix_dependencies (all_optional_deps , dep_of , function (dep_name )
246
+ self .plugins [dep_name ] = nil
247
+ end )
248
+ -- fix deps of disabled plugins
249
+ self :fix_dependencies (disabled_deps , dep_of , function (dep_name )
250
+ local plugin = self .plugins [dep_name ]
251
+ plugin ._ .kind = " disabled"
252
+ self .plugins [plugin .name ] = nil
253
+ self .disabled [plugin .name ] = plugin
254
+ end )
233
255
end
234
256
235
257
--- @param msg string
0 commit comments