aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_expand/src/db.rs2
-rw-r--r--crates/tt/src/lib.rs47
2 files changed, 49 insertions, 0 deletions
diff --git a/crates/hir_expand/src/db.rs b/crates/hir_expand/src/db.rs
index cb6e23320..9086e6c17 100644
--- a/crates/hir_expand/src/db.rs
+++ b/crates/hir_expand/src/db.rs
@@ -340,6 +340,8 @@ fn parse_macro_with_arg(
340 None => return ExpandResult { value: None, err: result.err }, 340 None => return ExpandResult { value: None, err: result.err },
341 }; 341 };
342 342
343 log::debug!("expanded = {}", tt.as_debug_string());
344
343 let fragment_kind = to_fragment_kind(db, macro_call_id); 345 let fragment_kind = to_fragment_kind(db, macro_call_id);
344 346
345 let (parse, rev_token_map) = match mbe::token_tree_to_syntax_node(&tt, fragment_kind) { 347 let (parse, rev_token_map) = match mbe::token_tree_to_syntax_node(&tt, fragment_kind) {
diff --git a/crates/tt/src/lib.rs b/crates/tt/src/lib.rs
index 8301dc28a..9d9a01e30 100644
--- a/crates/tt/src/lib.rs
+++ b/crates/tt/src/lib.rs
@@ -227,6 +227,53 @@ impl Subtree {
227 } 227 }
228} 228}
229 229
230impl Subtree {
231 /// A simple line string used for debugging
232 pub fn as_debug_string(&self) -> String {
233 let delim = match self.delimiter_kind() {
234 Some(DelimiterKind::Brace) => ("{", "}"),
235 Some(DelimiterKind::Bracket) => ("[", "]"),
236 Some(DelimiterKind::Parenthesis) => ("(", ")"),
237 None => (" ", " "),
238 };
239
240 let mut res = String::new();
241 res.push_str(delim.0);
242 let mut iter = self.token_trees.iter();
243 let mut last = None;
244 while let Some(child) = iter.next() {
245 let s = match child {
246 TokenTree::Leaf(it) => {
247 let s = match it {
248 Leaf::Literal(it) => it.text.to_string(),
249 Leaf::Punct(it) => it.char.to_string(),
250 Leaf::Ident(it) => it.text.to_string(),
251 };
252 match (it, last) {
253 (Leaf::Ident(_), Some(&TokenTree::Leaf(Leaf::Ident(_)))) => {
254 " ".to_string() + &s
255 }
256 (Leaf::Punct(_), Some(&TokenTree::Leaf(Leaf::Punct(punct)))) => {
257 if punct.spacing == Spacing::Alone {
258 " ".to_string() + &s
259 } else {
260 s
261 }
262 }
263 _ => s,
264 }
265 }
266 TokenTree::Subtree(it) => it.as_debug_string(),
267 };
268 res.push_str(&s);
269 last = Some(child);
270 }
271
272 res.push_str(delim.1);
273 res
274 }
275}
276
230pub mod buffer; 277pub mod buffer;
231 278
232#[derive(Debug, PartialEq, Eq, Clone)] 279#[derive(Debug, PartialEq, Eq, Clone)]