mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-06-28 19:34:15 +00:00
discard_deps_revisited: performance
act directly while looping, avoiding the vim.list_extend calls.
This commit is contained in:
parent
08fcf83957
commit
2885cf1cba
1 changed files with 27 additions and 41 deletions
|
@ -53,51 +53,37 @@ 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
|
||||||
|
|
||||||
---@return string[]
|
function Spec:fix_active()
|
||||||
function Spec:names_to_repair()
|
|
||||||
---@return LazyPlugin[]
|
|
||||||
local function collect_unused_plugins()
|
|
||||||
local unused = vim.list_extend({}, vim.tbl_values(self.optional_only))
|
|
||||||
return vim.list_extend(unused, vim.tbl_values(self.disabled))
|
|
||||||
end
|
|
||||||
|
|
||||||
---@type string[]
|
|
||||||
local deps_in_unused = {}
|
|
||||||
for _, plugin in pairs(collect_unused_plugins()) do
|
|
||||||
if plugin.dependencies then
|
|
||||||
vim.list_extend(deps_in_unused, plugin.dependencies)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
---@type table<string, boolean>
|
---@type table<string, boolean>
|
||||||
local seen = {}
|
local seen = {}
|
||||||
-- filter: deps that are not active
|
|
||||||
-- filter: duplicate deps
|
---@param name string
|
||||||
return vim.tbl_filter(function(name)
|
local function repair(name)
|
||||||
if not self.plugins[name] or seen[name] then
|
if not seen[name] and self.plugins[name] then
|
||||||
return false
|
seen[name] = true
|
||||||
|
|
||||||
|
self.plugins[name] = self:redo_merge(vim.tbl_filter(function(contrib)
|
||||||
|
if contrib._.parent_name and not self.plugins[contrib._.parent_name] then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return contrib
|
||||||
|
end, self.repair_info[name]))
|
||||||
end
|
end
|
||||||
seen[name] = true
|
|
||||||
return name
|
|
||||||
end, deps_in_unused)
|
|
||||||
end
|
|
||||||
|
|
||||||
function Spec:fix_active()
|
|
||||||
---@type string[]
|
|
||||||
local names = self:names_to_repair()
|
|
||||||
|
|
||||||
-- merge again without contributions from unused plugins
|
|
||||||
for _, name in pairs(names) do
|
|
||||||
---@type LazyPlugin[]
|
|
||||||
local filtered_contributions = vim.tbl_filter(function(contr)
|
|
||||||
if contr._.parent_name and not self.plugins[contr._.parent_name] then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
return contr
|
|
||||||
end, self.repair_info[name])
|
|
||||||
|
|
||||||
self.plugins[name] = self:redo_merge(filtered_contributions)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param originating_from table<string,LazyPlugin>
|
||||||
|
local function remove_contributions(originating_from)
|
||||||
|
for _, plugin in pairs(originating_from) do
|
||||||
|
if plugin.dependencies then
|
||||||
|
for _, dep in pairs(plugin.dependencies) do
|
||||||
|
repair(dep)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
remove_contributions(self.optional_only)
|
||||||
|
remove_contributions(self.disabled)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param contributions LazyPlugin[]
|
---@param contributions LazyPlugin[]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue