feat(util): has_extra now also checks for manual imports in lazy.lua

This commit is contained in:
Folke Lemaitre 2025-02-08 12:48:24 +01:00
parent 83988ea46e
commit 0416376733
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -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()