mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-21 08:35:53 +02:00
feat(util): has_extra
now also checks for manual imports in lazy.lua
This commit is contained in:
parent
83988ea46e
commit
0416376733
1 changed files with 23 additions and 2 deletions
|
@ -55,12 +55,33 @@ function M.has(plugin)
|
||||||
return M.get_plugin(plugin) ~= nil
|
return M.get_plugin(plugin) ~= nil
|
||||||
end
|
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
|
---@param extra string
|
||||||
function M.has_extra(extra)
|
function M.has_extra(extra)
|
||||||
local Config = require("lazyvim.config")
|
local Config = require("lazyvim.config")
|
||||||
local modname = "lazyvim.plugins.extras." .. extra
|
local modname = "lazyvim.plugins.extras." .. extra
|
||||||
return vim.tbl_contains(require("lazy.core.config").spec.modules, modname)
|
local LazyConfig = require("lazy.core.config")
|
||||||
or vim.tbl_contains(Config.json.data.extras, modname)
|
-- 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
|
end
|
||||||
|
|
||||||
---@param fn fun()
|
---@param fn fun()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue