Skip to content

Commit

Permalink
feat(plugin): added support for virtual plugins. Closes #1836
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Dec 6, 2024
1 parent 3388a26 commit ee64abc
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
8 changes: 6 additions & 2 deletions lua/lazy/core/loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,9 @@ function M._load(plugin, reason, opts)
Util.track({ plugin = plugin.name, start = reason.start })
Handler.disable(plugin)

M.add_to_rtp(plugin)
if not plugin.virtual then
M.add_to_rtp(plugin)
end

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

M.packadd(plugin.dir)
if not plugin.virtual then
M.packadd(plugin.dir)
end
if plugin.config or plugin.opts then
M.config(plugin)
end
Expand Down
2 changes: 2 additions & 0 deletions lua/lazy/core/meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ function M:_rebuild(name)
plugin.dir = super.dir
if plugin.dir then
plugin.dir = Util.norm(plugin.dir)
elseif super.virtual then
plugin.dir = Util.norm("/dev/null/" .. plugin.name)
else
if plugin.dev == nil and plugin.url then
for _, pattern in ipairs(Config.options.dev.patterns) do
Expand Down
6 changes: 4 additions & 2 deletions lua/lazy/core/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,14 @@ function M.update_state()
or plugin.cmd
plugin.lazy = lazy and true or false
end
if plugin.dir:find(Config.options.root, 1, true) == 1 then
if plugin.virtual then
plugin._.is_local = true
plugin._.installed = true -- local plugins are managed by the user
elseif plugin.dir:find(Config.options.root, 1, true) == 1 then
plugin._.installed = installed[plugin.name] ~= nil
installed[plugin.name] = nil
else
plugin._.is_local = true
plugin._.installed = true -- local plugins are managed by the user
plugin._.installed = vim.fn.isdirectory(plugin.dir) == 1
end
end
Expand Down
2 changes: 1 addition & 1 deletion lua/lazy/core/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ function M.get_unloaded_rtp(modname, opts)
local Config = require("lazy.core.config")
if Config.spec then
for _, plugin in pairs(Config.spec.plugins) do
if not (plugin._.loaded or plugin.module == false) then
if not (plugin._.loaded or plugin.module == false or plugin.virtual) then
if norm == M.normname(plugin.name) then
table.insert(rtp, 1, plugin.dir)
else
Expand Down
1 change: 1 addition & 0 deletions lua/lazy/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
---@field priority? number Only useful for lazy=false plugins to force loading certain plugins first. Default priority is 50
---@field dev? boolean If set, then link to the respective folder under your ~/projects
---@field rocks? string[]
---@field virtual? boolean virtual plugins won't be installed or added to the rtp.

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

0 comments on commit ee64abc

Please sign in to comment.