From b193f96f7b71026f80fd89b6c3fc55fe982bbd1a Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Tue, 20 Dec 2022 23:14:49 +0100 Subject: [PATCH] fix(spec): only process a spec once --- lua/lazy/core/plugin.lua | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lua/lazy/core/plugin.lua b/lua/lazy/core/plugin.lua index 65172da..f510ee8 100644 --- a/lua/lazy/core/plugin.lua +++ b/lua/lazy/core/plugin.lua @@ -37,9 +37,9 @@ local M = {} ---@class LazyPlugin: LazyPluginHandlers,LazyPluginHooks,LazyPluginRef ---@field [1] string? ----@field name string? display name and name used for plugin config files +---@field name string display name and name used for plugin config files ---@field url string? ----@field dir string? +---@field dir string ---@field enabled? boolean|(fun():boolean) ---@field lazy? boolean ---@field dev? boolean If set, then link to the respective folder under your ~/projects @@ -129,9 +129,16 @@ function Spec:normalize(spec, results, is_dep) self:normalize(s, results, is_dep) end elseif spec.enabled == nil or spec.enabled == true or (type(spec.enabled) == "function" and spec.enabled()) then - ---@cast spec LazyPlugin - local plugin = self:add(spec, is_dep) - plugin.dependencies = plugin.dependencies and self:normalize(plugin.dependencies, {}, true) or nil + local plugin + -- check if we already processed this spec. Can happen when a user uses the same instance of a spec in multiple specs + -- see https://github.com/folke/lazy.nvim/issues/45 + if spec._ then + plugin = spec + else + ---@cast spec LazyPlugin + plugin = self:add(spec, is_dep) + plugin.dependencies = plugin.dependencies and self:normalize(plugin.dependencies, {}, true) or nil + end table.insert(results, plugin.name) end return results