Skip to content

Commit ee64abc

Browse files
committed
feat(plugin): added support for virtual plugins. Closes #1836
1 parent 3388a26 commit ee64abc

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

lua/lazy/core/loader.lua

+6-2
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,9 @@ function M._load(plugin, reason, opts)
341341
Util.track({ plugin = plugin.name, start = reason.start })
342342
Handler.disable(plugin)
343343

344-
M.add_to_rtp(plugin)
344+
if not plugin.virtual then
345+
M.add_to_rtp(plugin)
346+
end
345347

346348
if plugin._.pkg and plugin._.pkg.source == "rockspec" then
347349
M.add_to_luapath(plugin)
@@ -353,7 +355,9 @@ function M._load(plugin, reason, opts)
353355
end, "Failed to load deps for " .. plugin.name)
354356
end
355357

356-
M.packadd(plugin.dir)
358+
if not plugin.virtual then
359+
M.packadd(plugin.dir)
360+
end
357361
if plugin.config or plugin.opts then
358362
M.config(plugin)
359363
end

lua/lazy/core/meta.lua

+2
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ function M:_rebuild(name)
213213
plugin.dir = super.dir
214214
if plugin.dir then
215215
plugin.dir = Util.norm(plugin.dir)
216+
elseif super.virtual then
217+
plugin.dir = Util.norm("/dev/null/" .. plugin.name)
216218
else
217219
if plugin.dev == nil and plugin.url then
218220
for _, pattern in ipairs(Config.options.dev.patterns) do

lua/lazy/core/plugin.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,14 @@ function M.update_state()
237237
or plugin.cmd
238238
plugin.lazy = lazy and true or false
239239
end
240-
if plugin.dir:find(Config.options.root, 1, true) == 1 then
240+
if plugin.virtual then
241+
plugin._.is_local = true
242+
plugin._.installed = true -- local plugins are managed by the user
243+
elseif plugin.dir:find(Config.options.root, 1, true) == 1 then
241244
plugin._.installed = installed[plugin.name] ~= nil
242245
installed[plugin.name] = nil
243246
else
244247
plugin._.is_local = true
245-
plugin._.installed = true -- local plugins are managed by the user
246248
plugin._.installed = vim.fn.isdirectory(plugin.dir) == 1
247249
end
248250
end

lua/lazy/core/util.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ function M.get_unloaded_rtp(modname, opts)
270270
local Config = require("lazy.core.config")
271271
if Config.spec then
272272
for _, plugin in pairs(Config.spec.plugins) do
273-
if not (plugin._.loaded or plugin.module == false) then
273+
if not (plugin._.loaded or plugin.module == false or plugin.virtual) then
274274
if norm == M.normname(plugin.name) then
275275
table.insert(rtp, 1, plugin.dir)
276276
else

lua/lazy/types.lua

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
---@field priority? number Only useful for lazy=false plugins to force loading certain plugins first. Default priority is 50
6161
---@field dev? boolean If set, then link to the respective folder under your ~/projects
6262
---@field rocks? string[]
63+
---@field virtual? boolean virtual plugins won't be installed or added to the rtp.
6364

6465
---@class LazyPlugin: LazyPluginBase,LazyPluginHandlers,LazyPluginHooks,LazyPluginRef
6566
---@field dependencies? string[]

0 commit comments

Comments
 (0)