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 = {} 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 print("Astrobox err: " .. err .. " " .. vim.inspect(msg)) 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 print("AstroBox:Failed to load module " .. mod_name) end end end end return M