From ee64abc76be2b237b95d241a924b0323005b868a Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Fri, 6 Dec 2024 20:28:50 +0100 Subject: [PATCH] feat(plugin): added support for virtual plugins. Closes #1836 --- lua/lazy/core/loader.lua | 8 ++++++-- lua/lazy/core/meta.lua | 2 ++ lua/lazy/core/plugin.lua | 6 ++++-- lua/lazy/core/util.lua | 2 +- lua/lazy/types.lua | 1 + 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lua/lazy/core/loader.lua b/lua/lazy/core/loader.lua index c6a72718..1501efda 100644 --- a/lua/lazy/core/loader.lua +++ b/lua/lazy/core/loader.lua @@ -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) @@ -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 diff --git a/lua/lazy/core/meta.lua b/lua/lazy/core/meta.lua index 6e781a09..abb25083 100644 --- a/lua/lazy/core/meta.lua +++ b/lua/lazy/core/meta.lua @@ -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 diff --git a/lua/lazy/core/plugin.lua b/lua/lazy/core/plugin.lua index a2821320..37d1a8f4 100644 --- a/lua/lazy/core/plugin.lua +++ b/lua/lazy/core/plugin.lua @@ -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 diff --git a/lua/lazy/core/util.lua b/lua/lazy/core/util.lua index bdd42dd9..9db7f146 100644 --- a/lua/lazy/core/util.lua +++ b/lua/lazy/core/util.lua @@ -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 diff --git a/lua/lazy/types.lua b/lua/lazy/types.lua index 5921169d..0dbba9a0 100644 --- a/lua/lazy/types.lua +++ b/lua/lazy/types.lua @@ -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[]