workspacer_syntax/
generate_macro_signature.rs

1// ---------------- [ File: workspacer-syntax/src/generate_macro_signature.rs ]
2crate::ix!();
3
4#[derive(Debug, Clone)]
5pub struct MacroRulesSignatureGenerator(ast::MacroRules);
6
7impl GenerateSignature for ast::MacroRules {
8    fn generate_signature_with_opts(&self, opts: &SignatureOptions) -> String {
9        trace!("Generating signature for ast::MacroRules with opts: {:?}", opts);
10
11        let doc_text = if *opts.include_docs() {
12            extract_docs(&self.syntax())
13                .map(|d| format!("{}\n", d))
14                .unwrap_or_default()
15        } else {
16            "".to_string()
17        };
18
19        let name = self
20            .name()
21            .map(|n| n.to_string())
22            .unwrap_or_else(|| "<unknown_macro>".to_string());
23
24        let body_text = if *opts.fully_expand() {
25            trace!("Fully expanding macro body");
26            if let Some(tt) = self.token_tree() {
27                let body_str = tt.syntax().text().to_string();
28                debug!("Macro body content: {}", body_str);
29                format!("{{ {body_str} }}")
30            } else {
31                warn!("No macro token tree found");
32                "{ /* macro body not available */ }".to_string()
33            }
34        } else {
35            "{ /* macro body omitted */ }".to_string()
36        };
37
38        let core = format!("macro_rules! {name} {body_text}");
39
40        let final_sig = format!("{doc_text}{core}");
41        post_process_spacing(&final_sig)
42    }
43}