mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-06-28 19:34:15 +00:00
discard_deps_revisited: better naming
This commit is contained in:
parent
cfd070278c
commit
b8cc7b96cb
2 changed files with 19 additions and 16 deletions
|
@ -38,11 +38,11 @@ end
|
||||||
function Spec:parse(spec)
|
function Spec:parse(spec)
|
||||||
-- spec -> self.plugins
|
-- spec -> self.plugins
|
||||||
self:normalize(spec)
|
self:normalize(spec)
|
||||||
-- self.plugins -> self.optional_only, self.disabled
|
-- self.plugins -> self.plugins, self.optional_only, self.disabled
|
||||||
self:fix_disabled()
|
self:fix_disabled()
|
||||||
|
|
||||||
if self:has_unused_plugins() then
|
if self:has_unused_plugins() then
|
||||||
self:fix_active()
|
self:fix_enabled()
|
||||||
end
|
end
|
||||||
|
|
||||||
self:calculate_handlers(self.plugins)
|
self:calculate_handlers(self.plugins)
|
||||||
|
@ -53,44 +53,46 @@ 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()
|
function Spec:fix_enabled()
|
||||||
---@type table<string, boolean>
|
---@type table<string, boolean>
|
||||||
local seen = {}
|
local seen = {}
|
||||||
|
|
||||||
---@param name string
|
---@param name string
|
||||||
local function repair(name)
|
local function repair(name)
|
||||||
|
-- only repair a plugin once
|
||||||
|
-- only repair when its enabled
|
||||||
if not seen[name] and self.plugins[name] then
|
if not seen[name] and self.plugins[name] then
|
||||||
seen[name] = true
|
seen[name] = true
|
||||||
|
|
||||||
self.plugins[name] = self:redo_merge(vim.tbl_filter(function(contrib)
|
self.plugins[name] = self:redo_merge(vim.tbl_filter(function(partial)
|
||||||
if contrib._.parent_name and not self.plugins[contrib._.parent_name] then
|
if partial._.parent_name and not self.plugins[partial._.parent_name] then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
return contrib
|
return partial
|
||||||
end, self.repair_info[name]))
|
end, self.repair_info[name]))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param originating_from table<string,LazyPlugin>
|
---@param originating_from table<string,LazyPlugin>
|
||||||
local function remove_contributions(originating_from)
|
local function remove_partials(originating_from)
|
||||||
for _, plugin in pairs(originating_from) do
|
for _, plugin in pairs(originating_from) do
|
||||||
if plugin.dependencies then
|
if plugin.dependencies then
|
||||||
for _, dep in pairs(plugin.dependencies) do
|
for _, dep_name in pairs(plugin.dependencies) do
|
||||||
repair(dep)
|
repair(dep_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
remove_contributions(self.optional_only)
|
remove_partials(self.optional_only)
|
||||||
remove_contributions(self.disabled)
|
remove_partials(self.disabled)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param contributions LazyPlugin[]
|
---@param partials LazyPlugin[]
|
||||||
---@return LazyPlugin
|
---@return LazyPlugin
|
||||||
function Spec:redo_merge(contributions)
|
function Spec:redo_merge(partials)
|
||||||
local last
|
local last
|
||||||
for index, inst in ipairs(contributions) do
|
for index, inst in ipairs(partials) do
|
||||||
if index == 1 then
|
if index == 1 then
|
||||||
last = inst
|
last = inst
|
||||||
else
|
else
|
||||||
|
@ -195,6 +197,7 @@ function Spec:add(plugin, results, parent_name)
|
||||||
|
|
||||||
plugin.dependencies = plugin.dependencies and self:normalize(plugin.dependencies, {}, plugin.name) or nil
|
plugin.dependencies = plugin.dependencies and self:normalize(plugin.dependencies, {}, plugin.name) or nil
|
||||||
self:add_repair_info(plugin, parent_name)
|
self:add_repair_info(plugin, parent_name)
|
||||||
|
|
||||||
if self.plugins[plugin.name] then
|
if self.plugins[plugin.name] then
|
||||||
plugin = self:merge(self.plugins[plugin.name], plugin)
|
plugin = self:merge(self.plugins[plugin.name], plugin)
|
||||||
end
|
end
|
||||||
|
@ -208,7 +211,7 @@ end
|
||||||
---@param plugin LazyPlugin
|
---@param plugin LazyPlugin
|
||||||
---@param parent_name? string
|
---@param parent_name? string
|
||||||
function Spec:add_repair_info(plugin, parent_name)
|
function Spec:add_repair_info(plugin, parent_name)
|
||||||
local copy = vim.deepcopy(plugin) -- copy this plugin contribution
|
local copy = vim.deepcopy(plugin) -- copy this partial plugin spec
|
||||||
copy._.parent_name = parent_name
|
copy._.parent_name = parent_name
|
||||||
self.repair_info[copy.name] = self.repair_info[copy.name] or {}
|
self.repair_info[copy.name] = self.repair_info[copy.name] or {}
|
||||||
table.insert(self.repair_info[copy.name], copy)
|
table.insert(self.repair_info[copy.name], copy)
|
||||||
|
|
|
@ -337,7 +337,7 @@ describe("plugin opts", function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe("plugin spec", function()
|
describe("plugin spec", function()
|
||||||
it("discards contributions from unused plugins", function()
|
it("only includes partials from enabled plugins", function()
|
||||||
local tests = {
|
local tests = {
|
||||||
{
|
{
|
||||||
spec = {
|
spec = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue