aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_expand/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_expand/src')
-rw-r--r--crates/ra_hir_expand/src/lib.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs
index 194020b45..180cd1f57 100644
--- a/crates/ra_hir_expand/src/lib.rs
+++ b/crates/ra_hir_expand/src/lib.rs
@@ -20,6 +20,7 @@ use ra_syntax::{
20}; 20};
21 21
22use crate::ast_id_map::FileAstId; 22use crate::ast_id_map::FileAstId;
23use std::sync::Arc;
23 24
24/// Input to the analyzer is a set of files, where each file is identified by 25/// Input to the analyzer is a set of files, where each file is identified by
25/// `FileId` and contains source code. However, another source of source code in 26/// `FileId` and contains source code. However, another source of source code in
@@ -66,6 +67,24 @@ impl HirFileId {
66 } 67 }
67 } 68 }
68 } 69 }
70
71 /// Return expansion information if it is a macro-expansion file
72 pub fn parent_expansion(
73 self,
74 db: &dyn db::AstDatabase,
75 ) -> Option<((HirFileId, HirFileId), Arc<ExpansionInfo>)> {
76 match self.0 {
77 HirFileIdRepr::FileId(_) => None,
78 HirFileIdRepr::MacroFile(macro_file) => {
79 let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
80
81 let def_file = loc.def.ast_id.file_id;
82 let arg_file = loc.ast_id.file_id;
83
84 db.macro_expansion_info(macro_file).map(|ex| ((arg_file, def_file), ex))
85 }
86 }
87 }
69} 88}
70 89
71#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 90#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]