use crate::host::MacroExpander;
use crate::host::derived;
pub use crate::host::derived::manifest::{
DecoratorManifestEntry, MacroManifest, MacroManifestEntry,
};
#[cfg(feature = "node")]
use napi_derive::napi;
#[cfg_attr(feature = "node", napi(js_name = "__macroforgeGetManifest"))]
pub fn get_macro_manifest() -> MacroManifest {
derived::get_manifest()
}
#[cfg_attr(feature = "node", napi(js_name = "__macroforgeIsMacroPackage"))]
pub fn is_macro_package() -> bool {
!derived::macro_names().is_empty()
}
#[cfg_attr(feature = "node", napi(js_name = "__macroforgeGetMacroNames"))]
pub fn get_macro_names() -> Vec<String> {
derived::macro_names()
.into_iter()
.map(|s| s.to_string())
.collect()
}
#[cfg_attr(feature = "node", napi(js_name = "__macroforgeDebugGetModules"))]
pub fn debug_get_modules() -> Vec<String> {
crate::host::derived::modules()
.into_iter()
.map(|s| s.to_string())
.collect()
}
#[cfg_attr(feature = "node", napi(js_name = "__macroforgeDebugLookup"))]
pub fn debug_lookup(module: String, name: String) -> String {
match MacroExpander::new() {
Ok(host) => match host.dispatcher.registry().lookup(&module, &name) {
Ok(_) => format!("Found: ({}, {})", module, name),
Err(_) => format!("Not found: ({}, {})", module, name),
},
Err(e) => format!("Host init failed: {}", e),
}
}
#[cfg_attr(feature = "node", napi(js_name = "__macroforgeDebugDescriptors"))]
pub fn debug_descriptors() -> Vec<String> {
inventory::iter::<crate::host::derived::DerivedMacroRegistration>()
.map(|entry| {
format!(
"name={}, module={}, package={}",
entry.descriptor.name, entry.descriptor.module, entry.descriptor.package
)
})
.collect()
}