mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
add expand log
This commit is contained in:
parent
f0b7c02f16
commit
f1350dd93c
2 changed files with 49 additions and 0 deletions
|
@ -340,6 +340,8 @@ fn parse_macro_with_arg(
|
||||||
None => return ExpandResult { value: None, err: result.err },
|
None => return ExpandResult { value: None, err: result.err },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
log::debug!("expanded = {}", tt.as_debug_string());
|
||||||
|
|
||||||
let fragment_kind = to_fragment_kind(db, macro_call_id);
|
let fragment_kind = to_fragment_kind(db, macro_call_id);
|
||||||
|
|
||||||
let (parse, rev_token_map) = match mbe::token_tree_to_syntax_node(&tt, fragment_kind) {
|
let (parse, rev_token_map) = match mbe::token_tree_to_syntax_node(&tt, fragment_kind) {
|
||||||
|
|
|
@ -227,6 +227,53 @@ impl Subtree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Subtree {
|
||||||
|
/// A simple line string used for debugging
|
||||||
|
pub fn as_debug_string(&self) -> String {
|
||||||
|
let delim = match self.delimiter_kind() {
|
||||||
|
Some(DelimiterKind::Brace) => ("{", "}"),
|
||||||
|
Some(DelimiterKind::Bracket) => ("[", "]"),
|
||||||
|
Some(DelimiterKind::Parenthesis) => ("(", ")"),
|
||||||
|
None => (" ", " "),
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut res = String::new();
|
||||||
|
res.push_str(delim.0);
|
||||||
|
let mut iter = self.token_trees.iter();
|
||||||
|
let mut last = None;
|
||||||
|
while let Some(child) = iter.next() {
|
||||||
|
let s = match child {
|
||||||
|
TokenTree::Leaf(it) => {
|
||||||
|
let s = match it {
|
||||||
|
Leaf::Literal(it) => it.text.to_string(),
|
||||||
|
Leaf::Punct(it) => it.char.to_string(),
|
||||||
|
Leaf::Ident(it) => it.text.to_string(),
|
||||||
|
};
|
||||||
|
match (it, last) {
|
||||||
|
(Leaf::Ident(_), Some(&TokenTree::Leaf(Leaf::Ident(_)))) => {
|
||||||
|
" ".to_string() + &s
|
||||||
|
}
|
||||||
|
(Leaf::Punct(_), Some(&TokenTree::Leaf(Leaf::Punct(punct)))) => {
|
||||||
|
if punct.spacing == Spacing::Alone {
|
||||||
|
" ".to_string() + &s
|
||||||
|
} else {
|
||||||
|
s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => s,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TokenTree::Subtree(it) => it.as_debug_string(),
|
||||||
|
};
|
||||||
|
res.push_str(&s);
|
||||||
|
last = Some(child);
|
||||||
|
}
|
||||||
|
|
||||||
|
res.push_str(delim.1);
|
||||||
|
res
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub mod buffer;
|
pub mod buffer;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue