Skip to content

Commit 756b484

Browse files
committed
refactor: Plugin.dep => Plugin._.dep
1 parent 330dbe7 commit 756b484

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

lua/lazy/core/plugin.lua

+12-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ local M = {}
1818
---@field is_local boolean
1919
---@field is_symlink? boolean
2020
---@field cloned? boolean
21+
---@field dep? boolean True if this plugin is only in the spec as a dependency
2122

2223
---@class LazyPluginRef
2324
---@field branch? string
@@ -31,7 +32,6 @@ local M = {}
3132
---@field name string display name and name used for plugin config files
3233
---@field uri string
3334
---@field dir string
34-
---@field dep? boolean True if this plugin is only in the spec as a dependency
3535
---@field enabled? boolean|(fun():boolean)
3636
---@field lazy? boolean
3737
---@field dependencies? string[]
@@ -80,7 +80,8 @@ function Spec:add(plugin, is_dep)
8080
plugin.name = slash and name:sub(#name - slash + 2) or pkg:gsub("%W+", "_")
8181
end
8282

83-
plugin.dep = is_dep
83+
plugin._ = {}
84+
plugin._.dep = is_dep
8485

8586
-- check for plugins that should be local
8687
for _, pattern in ipairs(Config.options.dev.patterns) do
@@ -120,11 +121,11 @@ end
120121
---@param new LazyPlugin
121122
---@return LazyPlugin
122123
function Spec:merge(old, new)
123-
local is_dep = old.dep and new.dep
124+
local is_dep = old._.dep and new._.dep
124125

125126
---@diagnostic disable-next-line: no-unknown
126127
for k, v in pairs(new) do
127-
if k == "dep" then
128+
if k == "_" then
128129
elseif old[k] ~= nil and old[k] ~= v then
129130
if Handler.handlers[k] then
130131
local values = type(v) == "string" and { v } or v
@@ -139,7 +140,7 @@ function Spec:merge(old, new)
139140
old[k] = v
140141
end
141142
end
142-
old.dep = is_dep
143+
old._.dep = is_dep
143144
return old
144145
end
145146

@@ -155,7 +156,12 @@ function M.update_state()
155156
for _, plugin in pairs(Config.plugins) do
156157
plugin._ = plugin._ or {}
157158
if plugin.lazy == nil then
158-
local lazy = plugin.dep or Config.options.defaults.lazy or plugin.event or plugin.keys or plugin.ft or plugin.cmd
159+
local lazy = plugin._.dep
160+
or Config.options.defaults.lazy
161+
or plugin.event
162+
or plugin.keys
163+
or plugin.ft
164+
or plugin.cmd
159165
plugin.lazy = lazy and true or false
160166
end
161167
plugin.dir = Config.root .. "/" .. plugin.name

tests/core/plugin_spec.lua

+8-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe("plugin spec uri/name", function()
1919
}
2020

2121
for _, test in ipairs(tests) do
22+
test[2]._ = {}
2223
it("parses " .. vim.inspect(test[1]):gsub("%s+", " "), function()
2324
local spec = Plugin.Spec.new(test[1])
2425
local plugins = vim.tbl_values(spec.plugins)
@@ -42,11 +43,11 @@ describe("plugin spec opt", function()
4243
Plugin.update_state()
4344
assert(vim.tbl_count(spec.plugins) == 3)
4445
assert(#spec.plugins.bar.dependencies == 2)
45-
assert(spec.plugins.bar.dep ~= true)
46+
assert(spec.plugins.bar._.dep ~= true)
4647
assert(spec.plugins.bar.lazy == false)
47-
assert(spec.plugins.dep1.dep == true)
48+
assert(spec.plugins.dep1._.dep == true)
4849
assert(spec.plugins.dep1.lazy == true)
49-
assert(spec.plugins.dep2.dep == true)
50+
assert(spec.plugins.dep2._.dep == true)
5051
assert(spec.plugins.dep2.lazy == true)
5152
end
5253
end)
@@ -57,11 +58,11 @@ describe("plugin spec opt", function()
5758
Config.plugins = spec.plugins
5859
Plugin.update_state()
5960
assert.same(3, vim.tbl_count(spec.plugins))
60-
assert(spec.plugins.bar.dep ~= true)
61+
assert(spec.plugins.bar._.dep ~= true)
6162
assert(spec.plugins.bar.lazy == false)
62-
assert(spec.plugins.dep2.dep == true)
63+
assert(spec.plugins.dep2._.dep == true)
6364
assert(spec.plugins.dep2.lazy == true)
64-
assert(spec.plugins.dep1.dep ~= true)
65+
assert(spec.plugins.dep1._.dep ~= true)
6566
assert(spec.plugins.dep1.lazy == false)
6667
end)
6768

@@ -88,7 +89,7 @@ describe("plugin spec opt", function()
8889
Config.plugins = spec.plugins
8990
Plugin.update_state()
9091
assert.same(1, vim.tbl_count(spec.plugins))
91-
assert(spec.plugins.bar.dep ~= true)
92+
assert(spec.plugins.bar._.dep ~= true)
9293
assert(spec.plugins.bar.lazy == true)
9394
end)
9495

0 commit comments

Comments
 (0)