mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-06-28 19:34:15 +00:00
discard_deps_revisited: finetuning and performance
finetuning: the algorithm marking an active plugin as dirty performance: instead of vim.tbl_merge, use vim.list_extend
This commit is contained in:
parent
f95c7a8be1
commit
a1574d8d03
1 changed files with 31 additions and 15 deletions
|
@ -53,37 +53,53 @@ function Spec:has_unused_plugins()
|
||||||
return not (vim.tbl_isempty(self.optional_only) and vim.tbl_isempty(self.disabled))
|
return not (vim.tbl_isempty(self.optional_only) and vim.tbl_isempty(self.disabled))
|
||||||
end
|
end
|
||||||
|
|
||||||
function Spec:fix_active()
|
---@return string[]
|
||||||
---@type table<string,LazyPlugin>
|
function Spec:collect_dirty()
|
||||||
local unused_plugins = vim.tbl_extend("keep", self.optional_only, self.disabled)
|
---@return LazyPlugin[]
|
||||||
|
local function collect_unused_plugins()
|
||||||
|
local unused_plugins = vim.list_extend({}, vim.tbl_values(self.optional_only))
|
||||||
|
return vim.list_extend(unused_plugins, vim.tbl_values(self.disabled))
|
||||||
|
end
|
||||||
|
|
||||||
---@type string[]
|
---@type string[]
|
||||||
local candidates = {}
|
local candidates = {}
|
||||||
for _, plugin in pairs(unused_plugins) do
|
for _, plugin in pairs(collect_unused_plugins()) do
|
||||||
if plugin.dependencies then
|
if plugin.dependencies then
|
||||||
vim.list_extend(candidates, plugin.dependencies)
|
vim.list_extend(candidates, plugin.dependencies)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- merge candidate again without instances supplied by unused plugins
|
---@type table<string, boolean>
|
||||||
for _, candidate in pairs(candidates) do
|
local seen = {}
|
||||||
local fix = false
|
-- filter: candidates that are not active
|
||||||
local instances = vim.tbl_filter(function(instance)
|
-- filter: duplicate candidates
|
||||||
if instance._.parent_name and unused_plugins[instance._.parent_name] then
|
return vim.tbl_filter(function(candidate)
|
||||||
fix = true
|
if not self.plugins[candidate] or seen[candidate] then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
seen[candidate] = true
|
||||||
|
return candidate
|
||||||
|
end, candidates)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Spec:fix_active()
|
||||||
|
-- merge again without instance contributions by unused plugins
|
||||||
|
local dirty_plugins = self:collect_dirty()
|
||||||
|
for _, plugin_name in pairs(dirty_plugins) do
|
||||||
|
local filtered_instances = vim.tbl_filter(function(instance)
|
||||||
|
if instance._.parent_name and not self.plugins[instance._.parent_name] then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
return instance
|
return instance
|
||||||
end, self.repair_info[candidate])
|
end, self.repair_info[plugin_name])
|
||||||
if fix then
|
|
||||||
self.plugins[candidate] = self:fix_merge(instances)
|
self.plugins[plugin_name] = self:redo_merge(filtered_instances)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param instances_of_plugin LazyPlugin[]
|
---@param instances_of_plugin LazyPlugin[]
|
||||||
---@return LazyPlugin
|
---@return LazyPlugin
|
||||||
function Spec:fix_merge(instances_of_plugin)
|
function Spec:redo_merge(instances_of_plugin)
|
||||||
local last
|
local last
|
||||||
for index, inst in ipairs(instances_of_plugin) do
|
for index, inst in ipairs(instances_of_plugin) do
|
||||||
if index == 1 then
|
if index == 1 then
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue