diff --git a/lua/lazy/core/plugin.lua b/lua/lazy/core/plugin.lua index ae04a80..1a45afb 100644 --- a/lua/lazy/core/plugin.lua +++ b/lua/lazy/core/plugin.lua @@ -18,6 +18,7 @@ local M = {} ---@field is_local boolean ---@field is_symlink? boolean ---@field cloned? boolean +---@field dep? boolean True if this plugin is only in the spec as a dependency ---@class LazyPluginRef ---@field branch? string @@ -31,7 +32,6 @@ local M = {} ---@field name string display name and name used for plugin config files ---@field uri string ---@field dir string ----@field dep? boolean True if this plugin is only in the spec as a dependency ---@field enabled? boolean|(fun():boolean) ---@field lazy? boolean ---@field dependencies? string[] @@ -80,7 +80,8 @@ function Spec:add(plugin, is_dep) plugin.name = slash and name:sub(#name - slash + 2) or pkg:gsub("%W+", "_") end - plugin.dep = is_dep + plugin._ = {} + plugin._.dep = is_dep -- check for plugins that should be local for _, pattern in ipairs(Config.options.dev.patterns) do @@ -120,11 +121,11 @@ end ---@param new LazyPlugin ---@return LazyPlugin function Spec:merge(old, new) - local is_dep = old.dep and new.dep + local is_dep = old._.dep and new._.dep ---@diagnostic disable-next-line: no-unknown for k, v in pairs(new) do - if k == "dep" then + if k == "_" then elseif old[k] ~= nil and old[k] ~= v then if Handler.handlers[k] then local values = type(v) == "string" and { v } or v @@ -139,7 +140,7 @@ function Spec:merge(old, new) old[k] = v end end - old.dep = is_dep + old._.dep = is_dep return old end @@ -155,7 +156,12 @@ function M.update_state() for _, plugin in pairs(Config.plugins) do plugin._ = plugin._ or {} if plugin.lazy == nil then - local lazy = plugin.dep or Config.options.defaults.lazy or plugin.event or plugin.keys or plugin.ft or plugin.cmd + local lazy = plugin._.dep + or Config.options.defaults.lazy + or plugin.event + or plugin.keys + or plugin.ft + or plugin.cmd plugin.lazy = lazy and true or false end plugin.dir = Config.root .. "/" .. plugin.name diff --git a/tests/core/plugin_spec.lua b/tests/core/plugin_spec.lua index 6608c03..7562f53 100644 --- a/tests/core/plugin_spec.lua +++ b/tests/core/plugin_spec.lua @@ -19,6 +19,7 @@ describe("plugin spec uri/name", function() } for _, test in ipairs(tests) do + test[2]._ = {} it("parses " .. vim.inspect(test[1]):gsub("%s+", " "), function() local spec = Plugin.Spec.new(test[1]) local plugins = vim.tbl_values(spec.plugins) @@ -42,11 +43,11 @@ describe("plugin spec opt", function() Plugin.update_state() assert(vim.tbl_count(spec.plugins) == 3) assert(#spec.plugins.bar.dependencies == 2) - assert(spec.plugins.bar.dep ~= true) + assert(spec.plugins.bar._.dep ~= true) assert(spec.plugins.bar.lazy == false) - assert(spec.plugins.dep1.dep == true) + assert(spec.plugins.dep1._.dep == true) assert(spec.plugins.dep1.lazy == true) - assert(spec.plugins.dep2.dep == true) + assert(spec.plugins.dep2._.dep == true) assert(spec.plugins.dep2.lazy == true) end end) @@ -57,11 +58,11 @@ describe("plugin spec opt", function() Config.plugins = spec.plugins Plugin.update_state() assert.same(3, vim.tbl_count(spec.plugins)) - assert(spec.plugins.bar.dep ~= true) + assert(spec.plugins.bar._.dep ~= true) assert(spec.plugins.bar.lazy == false) - assert(spec.plugins.dep2.dep == true) + assert(spec.plugins.dep2._.dep == true) assert(spec.plugins.dep2.lazy == true) - assert(spec.plugins.dep1.dep ~= true) + assert(spec.plugins.dep1._.dep ~= true) assert(spec.plugins.dep1.lazy == false) end) @@ -88,7 +89,7 @@ describe("plugin spec opt", function() Config.plugins = spec.plugins Plugin.update_state() assert.same(1, vim.tbl_count(spec.plugins)) - assert(spec.plugins.bar.dep ~= true) + assert(spec.plugins.bar._.dep ~= true) assert(spec.plugins.bar.lazy == true) end)