diff options
author | Edwin Cheng <[email protected]> | 2019-11-03 17:44:23 +0000 |
---|---|---|
committer | Edwin Cheng <[email protected]> | 2019-11-04 17:38:20 +0000 |
commit | ae609d7953297b355616c7862b8deefe74a8f95f (patch) | |
tree | 4f84d7f24ff59160eb318f527ecf4cf94e4d4cf8 /crates/ra_hir_expand/src | |
parent | 159da285e9d8594a2cc4436b5cee7874b07806c9 (diff) |
Add parent_expansion to HirFileId
Diffstat (limited to 'crates/ra_hir_expand/src')
-rw-r--r-- | crates/ra_hir_expand/src/lib.rs | 19 |
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 | ||
22 | use crate::ast_id_map::FileAstId; | 22 | use crate::ast_id_map::FileAstId; |
23 | use 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)] |