use futures::FutureExt; use itertools::Itertools; use orchid_base::{NameLike, VPath, fmt}; use orchid_host::tree::{MemKind, Mod, RootData}; pub async fn print_mod(module: &Mod, path: VPath, root: &RootData) { let indent = " ".repeat(path.len()); for (key, tgt) in &module.imports { match tgt { Ok(tgt) => println!("{indent}import {key} => {}", tgt.target), Err(opts) => println!( "{indent}import {key} conflicts between {}", opts.iter().map(|i| &i.target).join(" ") ), } } for (key, mem) in &module.members { let new_path = path.clone().name_with_suffix(key.clone()).to_sym().await; match mem.kind(root.ctx.clone(), &root.consts).await { MemKind::Module(module) => { println!("{indent}module {key} {{"); print_mod(module, VPath::new(new_path.segs()), root).boxed_local().await; println!("{indent}}}") }, MemKind::Const => { let value = root.consts.get(&new_path).expect("Missing const!"); println!("{indent}const {key} = {}", fmt(value).await) }, } } }