aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir_def/src/body.rs8
-rw-r--r--crates/ra_hir_def/src/body/lower.rs12
2 files changed, 11 insertions, 9 deletions
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs
index 5d8c299ba..1c9c86449 100644
--- a/crates/ra_hir_def/src/body.rs
+++ b/crates/ra_hir_def/src/body.rs
@@ -18,6 +18,7 @@ use crate::{
18 18
19pub struct Expander { 19pub struct Expander {
20 crate_def_map: Arc<CrateDefMap>, 20 crate_def_map: Arc<CrateDefMap>,
21 original_file_id: HirFileId,
21 current_file_id: HirFileId, 22 current_file_id: HirFileId,
22 module: ModuleId, 23 module: ModuleId,
23} 24}
@@ -25,7 +26,12 @@ pub struct Expander {
25impl Expander { 26impl Expander {
26 pub fn new(db: &impl DefDatabase2, current_file_id: HirFileId, module: ModuleId) -> Expander { 27 pub fn new(db: &impl DefDatabase2, current_file_id: HirFileId, module: ModuleId) -> Expander {
27 let crate_def_map = db.crate_def_map(module.krate); 28 let crate_def_map = db.crate_def_map(module.krate);
28 Expander { crate_def_map, current_file_id, module } 29 Expander { crate_def_map, original_file_id: current_file_id, current_file_id, module }
30 }
31
32 // FIXME: remove this.
33 fn is_in_expansion(&self) -> bool {
34 self.original_file_id != self.current_file_id
29 } 35 }
30 36
31 fn resolve_path_as_macro(&self, db: &impl DefDatabase2, path: &Path) -> Option<MacroDefId> { 37 fn resolve_path_as_macro(&self, db: &impl DefDatabase2, path: &Path) -> Option<MacroDefId> {
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index cc4bbe11a..602bcb220 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -4,7 +4,7 @@ use hir_expand::{
4 either::Either, 4 either::Either,
5 hygiene::Hygiene, 5 hygiene::Hygiene,
6 name::{self, AsName, Name}, 6 name::{self, AsName, Name},
7 AstId, HirFileId, MacroCallLoc, MacroFileKind, Source, 7 AstId, MacroCallLoc, MacroFileKind, Source,
8}; 8};
9use ra_arena::Arena; 9use ra_arena::Arena;
10use ra_syntax::{ 10use ra_syntax::{
@@ -34,12 +34,9 @@ pub(super) fn lower(
34 params: Option<ast::ParamList>, 34 params: Option<ast::ParamList>,
35 body: Option<ast::Expr>, 35 body: Option<ast::Expr>,
36) -> (Body, BodySourceMap) { 36) -> (Body, BodySourceMap) {
37 let original_file_id = expander.current_file_id;
38
39 ExprCollector { 37 ExprCollector {
40 expander, 38 expander,
41 db, 39 db,
42 original_file_id,
43 source_map: BodySourceMap::default(), 40 source_map: BodySourceMap::default(),
44 body: Body { 41 body: Body {
45 exprs: Arena::default(), 42 exprs: Arena::default(),
@@ -54,7 +51,6 @@ pub(super) fn lower(
54struct ExprCollector<DB> { 51struct ExprCollector<DB> {
55 db: DB, 52 db: DB,
56 expander: Expander, 53 expander: Expander,
57 original_file_id: HirFileId,
58 54
59 body: Body, 55 body: Body,
60 source_map: BodySourceMap, 56 source_map: BodySourceMap,
@@ -100,7 +96,7 @@ where
100 fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId { 96 fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId {
101 let ptr = Either::A(ptr); 97 let ptr = Either::A(ptr);
102 let id = self.body.exprs.alloc(expr); 98 let id = self.body.exprs.alloc(expr);
103 if self.expander.current_file_id == self.original_file_id { 99 if !self.expander.is_in_expansion() {
104 self.source_map.expr_map.insert(ptr, id); 100 self.source_map.expr_map.insert(ptr, id);
105 } 101 }
106 self.source_map 102 self.source_map
@@ -116,7 +112,7 @@ where
116 fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr<ast::RecordField>) -> ExprId { 112 fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr<ast::RecordField>) -> ExprId {
117 let ptr = Either::B(ptr); 113 let ptr = Either::B(ptr);
118 let id = self.body.exprs.alloc(expr); 114 let id = self.body.exprs.alloc(expr);
119 if self.expander.current_file_id == self.original_file_id { 115 if !self.expander.is_in_expansion() {
120 self.source_map.expr_map.insert(ptr, id); 116 self.source_map.expr_map.insert(ptr, id);
121 } 117 }
122 self.source_map 118 self.source_map
@@ -126,7 +122,7 @@ where
126 } 122 }
127 fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId { 123 fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId {
128 let id = self.body.pats.alloc(pat); 124 let id = self.body.pats.alloc(pat);
129 if self.expander.current_file_id == self.original_file_id { 125 if !self.expander.is_in_expansion() {
130 self.source_map.pat_map.insert(ptr, id); 126 self.source_map.pat_map.insert(ptr, id);
131 } 127 }
132 self.source_map 128 self.source_map