Skip to content

Commit dea43af

Browse files
committed
feat(spec): allow import property on a plugin spec
1 parent 3bde7b5 commit dea43af

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

lua/lazy/core/plugin.lua

+18-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ function Spec:add(plugin, results, is_dep)
4545
-- check if we already processed this spec. Can happen when a user uses the same instance of a spec in multiple specs
4646
-- see https://github.com/folke/lazy.nvim/issues/45
4747
if plugin._ then
48-
return results and table.insert(results, plugin.name)
48+
if results then
49+
table.insert(results, plugin.name)
50+
end
51+
return plugin
4952
end
5053

5154
if not plugin.url and plugin[1] then
@@ -76,6 +79,7 @@ function Spec:add(plugin, results, is_dep)
7679
end
7780
else
7881
self:error("Invalid plugin spec " .. vim.inspect(plugin))
82+
return
7983
end
8084

8185
plugin.event = type(plugin.event) == "string" and { plugin.event } or plugin.event
@@ -91,7 +95,10 @@ function Spec:add(plugin, results, is_dep)
9195
plugin = self:merge(self.plugins[plugin.name], plugin)
9296
end
9397
self.plugins[plugin.name] = plugin
94-
return results and table.insert(results, plugin.name)
98+
if results then
99+
table.insert(results, plugin.name)
100+
end
101+
return plugin
95102
end
96103

97104
function Spec:error(msg)
@@ -182,12 +189,19 @@ function Spec:normalize(spec, results, is_dep)
182189
for _, s in ipairs(spec) do
183190
self:normalize(s, results, is_dep)
184191
end
192+
elseif spec[1] or spec.dir or spec.url then
193+
---@cast spec LazyPlugin
194+
local plugin = self:add(spec, results, is_dep)
195+
---@diagnostic disable-next-line: cast-type-mismatch
196+
---@cast plugin LazySpecImport
197+
if plugin and plugin.import then
198+
self:import(plugin)
199+
end
185200
elseif spec.import then
186201
---@cast spec LazySpecImport
187202
self:import(spec)
188203
else
189-
---@cast spec LazyPlugin
190-
self:add(spec, results, is_dep)
204+
self:error("Invalid plugin spec " .. vim.inspect(spec))
191205
end
192206
return results
193207
end

0 commit comments

Comments
 (0)