aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/body.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/body.rs')
-rw-r--r--crates/ra_hir_def/src/body.rs22
1 files changed, 16 insertions, 6 deletions
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs
index 8ab92b23a..142c52d35 100644
--- a/crates/ra_hir_def/src/body.rs
+++ b/crates/ra_hir_def/src/body.rs
@@ -26,7 +26,7 @@ use crate::{
26 DefWithBodyId, HasModule, Lookup, ModuleId, 26 DefWithBodyId, HasModule, Lookup, ModuleId,
27}; 27};
28 28
29pub struct Expander { 29pub(crate) struct Expander {
30 crate_def_map: Arc<CrateDefMap>, 30 crate_def_map: Arc<CrateDefMap>,
31 current_file_id: HirFileId, 31 current_file_id: HirFileId,
32 hygiene: Hygiene, 32 hygiene: Hygiene,
@@ -35,14 +35,18 @@ pub struct Expander {
35} 35}
36 36
37impl Expander { 37impl Expander {
38 pub fn new(db: &impl DefDatabase, current_file_id: HirFileId, module: ModuleId) -> Expander { 38 pub(crate) fn new(
39 db: &impl DefDatabase,
40 current_file_id: HirFileId,
41 module: ModuleId,
42 ) -> Expander {
39 let crate_def_map = db.crate_def_map(module.krate); 43 let crate_def_map = db.crate_def_map(module.krate);
40 let hygiene = Hygiene::new(db, current_file_id); 44 let hygiene = Hygiene::new(db, current_file_id);
41 let ast_id_map = db.ast_id_map(current_file_id); 45 let ast_id_map = db.ast_id_map(current_file_id);
42 Expander { crate_def_map, current_file_id, hygiene, ast_id_map, module } 46 Expander { crate_def_map, current_file_id, hygiene, ast_id_map, module }
43 } 47 }
44 48
45 pub fn enter_expand<T: ast::AstNode, DB: DefDatabase>( 49 pub(crate) fn enter_expand<T: ast::AstNode, DB: DefDatabase>(
46 &mut self, 50 &mut self,
47 db: &DB, 51 db: &DB,
48 macro_call: ast::MacroCall, 52 macro_call: ast::MacroCall,
@@ -80,14 +84,14 @@ impl Expander {
80 None 84 None
81 } 85 }
82 86
83 pub fn exit(&mut self, db: &impl DefDatabase, mut mark: Mark) { 87 pub(crate) fn exit(&mut self, db: &impl DefDatabase, mut mark: Mark) {
84 self.hygiene = Hygiene::new(db, mark.file_id); 88 self.hygiene = Hygiene::new(db, mark.file_id);
85 self.current_file_id = mark.file_id; 89 self.current_file_id = mark.file_id;
86 self.ast_id_map = mem::take(&mut mark.ast_id_map); 90 self.ast_id_map = mem::take(&mut mark.ast_id_map);
87 mark.bomb.defuse(); 91 mark.bomb.defuse();
88 } 92 }
89 93
90 pub fn to_source<T>(&self, value: T) -> InFile<T> { 94 pub(crate) fn to_source<T>(&self, value: T) -> InFile<T> {
91 InFile { file_id: self.current_file_id, value } 95 InFile { file_id: self.current_file_id, value }
92 } 96 }
93 97
@@ -112,7 +116,7 @@ impl Expander {
112 } 116 }
113} 117}
114 118
115pub struct Mark { 119pub(crate) struct Mark {
116 file_id: HirFileId, 120 file_id: HirFileId,
117 ast_id_map: Arc<AstIdMap>, 121 ast_id_map: Arc<AstIdMap>,
118 bomb: DropBomb, 122 bomb: DropBomb,
@@ -159,6 +163,7 @@ pub struct BodySourceMap {
159 pat_map: FxHashMap<PatSource, PatId>, 163 pat_map: FxHashMap<PatSource, PatId>,
160 pat_map_back: ArenaMap<PatId, PatSource>, 164 pat_map_back: ArenaMap<PatId, PatSource>,
161 field_map: FxHashMap<(ExprId, usize), AstPtr<ast::RecordField>>, 165 field_map: FxHashMap<(ExprId, usize), AstPtr<ast::RecordField>>,
166 expansions: FxHashMap<InFile<AstPtr<ast::MacroCall>>, HirFileId>,
162} 167}
163 168
164impl Body { 169impl Body {
@@ -233,6 +238,11 @@ impl BodySourceMap {
233 self.expr_map.get(&src).cloned() 238 self.expr_map.get(&src).cloned()
234 } 239 }
235 240
241 pub fn node_macro_file(&self, node: InFile<&ast::MacroCall>) -> Option<HirFileId> {
242 let src = node.map(|it| AstPtr::new(it));
243 self.expansions.get(&src).cloned()
244 }
245
236 pub fn field_init_shorthand_expr(&self, node: InFile<&ast::RecordField>) -> Option<ExprId> { 246 pub fn field_init_shorthand_expr(&self, node: InFile<&ast::RecordField>) -> Option<ExprId> {
237 let src = node.map(|it| Either::Right(AstPtr::new(it))); 247 let src = node.map(|it| Either::Right(AstPtr::new(it)));
238 self.expr_map.get(&src).cloned() 248 self.expr_map.get(&src).cloned()