From 041637673371db7866f8bf00d77fc2fb6cc673c6 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Sat, 8 Feb 2025 12:48:24 +0100 Subject: [PATCH] feat(util): `has_extra` now also checks for manual imports in `lazy.lua` --- lua/lazyvim/util/init.lua | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/lua/lazyvim/util/init.lua b/lua/lazyvim/util/init.lua index 188544c3..66e6e18b 100644 --- a/lua/lazyvim/util/init.lua +++ b/lua/lazyvim/util/init.lua @@ -55,12 +55,33 @@ function M.has(plugin) return M.get_plugin(plugin) ~= nil end +--- Checks if the extras is enabled: +--- * If the module was imported +--- * If the module was added by LazyExtras +--- * If the module is in the user's lazy imports ---@param extra string function M.has_extra(extra) local Config = require("lazyvim.config") local modname = "lazyvim.plugins.extras." .. extra - return vim.tbl_contains(require("lazy.core.config").spec.modules, modname) - or vim.tbl_contains(Config.json.data.extras, modname) + local LazyConfig = require("lazy.core.config") + -- check if it was imported already + if vim.tbl_contains(LazyConfig.spec.modules, modname) then + return true + end + -- check if it was added by LazyExtras + if vim.tbl_contains(Config.json.data.extras, modname) then + return true + end + -- check if it's in the imports + local spec = LazyConfig.options.spec + if type(spec) == "table" then + for _, s in ipairs(spec) do + if type(s) == "table" and s.import == modname then + return true + end + end + end + return false end ---@param fn fun()