local function get_module_root_path(modname) local list = vim.loader.find(modname) if list and #list then return list[1].modpath:sub(0, -9) -- Cut init.lua end end ASTROBOX_ROOT_PATH = get_module_root_path("astrobox") local M = {} ---@param module string ---@param visitor function function M.visit_astrobox_modules(module, visitor) local modpath = ASTROBOX_ROOT_PATH .. module:gsub("%.", "/") local hdl, err, msg = vim.loop.fs_scandir(modpath) if hdl == nil then vim.notify("Astrobox err: " .. err .. " " .. vim.inspect(msg), vim.log.levels.ERROR) return end while true do local entry, type = vim.loop.fs_scandir_next(hdl) if entry == nil then break end if type == "file" and vim.endswith(entry, ".lua") then local mod_name = entry:sub(0, -5) -- cut extension local ok, mod = pcall(require, "astrobox." .. module .. "." .. mod_name) if ok then visitor(mod, mod_name) else vim.notify("AstroBox:Failed to load module " .. mod_name, vim.log.levels.ERROR) end end end end return M