aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ids.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-04-21 11:34:07 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-04-21 11:34:07 +0100
commitfa15c4d75e87bd3bf761c91f030c76aec59308ae (patch)
treeba7a3495b13e41231076d5a0e491132bbdb0670e /crates/ra_hir/src/ids.rs
parent493bf20b3d1a0a890514d5252901f13d2878ff34 (diff)
parent9e35bf91b827900b089a7ea937cb73707bebc420 (diff)
Merge #1175
1175: Fix bugs and add error log about macro expansion r=matklad a=edwin0cheng This PR fixed / add following things: * Add a fused count which stop recursion of macro expansion in name resolution. * Add some logs when macro expansion fails * Add `$crate` meta variable support in mbe, which create a `$crate` ident token in token tree. * Fixed matching a `$REPEAT` pattern inside a subtree, e.g. `(fn $name:ident {$($i:ident)*} ) => {...}` * Remove composite-able punct token in syntax node to token conversion. Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ids.rs')
-rw-r--r--crates/ra_hir/src/ids.rs24
1 files changed, 22 insertions, 2 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index 141c9072f..2a1ed9b81 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -63,8 +63,15 @@ impl HirFileId {
63 match file_id.0 { 63 match file_id.0 {
64 HirFileIdRepr::File(file_id) => db.parse(file_id), 64 HirFileIdRepr::File(file_id) => db.parse(file_id),
65 HirFileIdRepr::Macro(macro_call_id) => { 65 HirFileIdRepr::Macro(macro_call_id) => {
66 // returning an empty string looks fishy... 66 parse_macro(db, macro_call_id).unwrap_or_else(|| {
67 parse_macro(db, macro_call_id).unwrap_or_else(|| SourceFile::parse("")) 67 // Note:
68 // The final goal we would like to make all parse_macro success,
69 // such that the following log will not call anyway.
70 log::warn!("fail on macro_parse: {}", macro_call_id.debug_dump(db));
71
72 // returning an empty string looks fishy...
73 SourceFile::parse("")
74 })
68 } 75 }
69 } 76 }
70 } 77 }
@@ -299,3 +306,16 @@ impl AstItemDef<ast::TypeAliasDef> for TypeAliasId {
299 db.lookup_intern_type_alias(self) 306 db.lookup_intern_type_alias(self)
300 } 307 }
301} 308}
309
310impl MacroCallId {
311 pub fn debug_dump(&self, db: &impl DefDatabase) -> String {
312 let loc = self.clone().loc(db);
313 let node = loc.ast_id.to_node(db);
314 let syntax_str = node.syntax().to_string();
315
316 // dump the file name
317 let file_id: HirFileId = self.clone().into();
318 let original = file_id.original_file(db);
319 format!("macro call [file: {:#?}] : {}", db.file_relative_path(original), syntax_str)
320 }
321}