aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir_expand/src/lib.rs11
1 files changed, 5 insertions, 6 deletions
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs
index 6bfbb2f79..1774cb58b 100644
--- a/crates/ra_hir_expand/src/lib.rs
+++ b/crates/ra_hir_expand/src/lib.rs
@@ -83,14 +83,13 @@ impl HirFileId {
83 loc.def.ast_id.to_node(db).token_tree()?.syntax().text_range().start(); 83 loc.def.ast_id.to_node(db).token_tree()?.syntax().text_range().start();
84 84
85 let macro_def = db.macro_def(loc.def)?; 85 let macro_def = db.macro_def(loc.def)?;
86 let shift = macro_def.0.shift();
87 let exp_map = db.parse_macro(macro_file)?.1; 86 let exp_map = db.parse_macro(macro_file)?.1;
88 let macro_arg = db.macro_arg(macro_file.macro_call_id)?; 87 let macro_arg = db.macro_arg(macro_file.macro_call_id)?;
89 88
90 let arg_start = (loc.ast_id.file_id, arg_start); 89 let arg_start = (loc.ast_id.file_id, arg_start);
91 let def_start = (loc.def.ast_id.file_id, def_start); 90 let def_start = (loc.def.ast_id.file_id, def_start);
92 91
93 Some(ExpansionInfo { arg_start, def_start, macro_arg, macro_def, exp_map, shift }) 92 Some(ExpansionInfo { arg_start, def_start, macro_arg, macro_def, exp_map })
94 } 93 }
95 } 94 }
96 } 95 }
@@ -152,7 +151,6 @@ impl MacroCallId {
152pub struct ExpansionInfo { 151pub struct ExpansionInfo {
153 pub(crate) arg_start: (HirFileId, TextUnit), 152 pub(crate) arg_start: (HirFileId, TextUnit),
154 pub(crate) def_start: (HirFileId, TextUnit), 153 pub(crate) def_start: (HirFileId, TextUnit),
155 pub(crate) shift: u32,
156 154
157 pub(crate) macro_def: Arc<(db::TokenExpander, mbe::TokenMap)>, 155 pub(crate) macro_def: Arc<(db::TokenExpander, mbe::TokenMap)>,
158 pub(crate) macro_arg: Arc<(tt::Subtree, mbe::TokenMap)>, 156 pub(crate) macro_arg: Arc<(tt::Subtree, mbe::TokenMap)>,
@@ -163,7 +161,7 @@ impl ExpansionInfo {
163 pub fn translate_offset(&self, offset: TextUnit) -> Option<TextUnit> { 161 pub fn translate_offset(&self, offset: TextUnit) -> Option<TextUnit> {
164 let offset = offset.checked_sub(self.arg_start.1)?; 162 let offset = offset.checked_sub(self.arg_start.1)?;
165 let token_id = self.macro_arg.1.token_by_offset(offset)?; 163 let token_id = self.macro_arg.1.token_by_offset(offset)?;
166 let token_id = tt::TokenId(token_id.0 + self.shift); 164 let token_id = tt::TokenId(token_id.0 + self.macro_def.0.shift());
167 165
168 let (r, _) = self.exp_map.ranges.iter().find(|(_, tid)| *tid == token_id)?; 166 let (r, _) = self.exp_map.ranges.iter().find(|(_, tid)| *tid == token_id)?;
169 Some(r.start()) 167 Some(r.start())
@@ -172,8 +170,9 @@ impl ExpansionInfo {
172 pub fn find_range(&self, from: TextRange) -> Option<(HirFileId, TextRange)> { 170 pub fn find_range(&self, from: TextRange) -> Option<(HirFileId, TextRange)> {
173 let token_id = look_in_rev_map(&self.exp_map, from)?; 171 let token_id = look_in_rev_map(&self.exp_map, from)?;
174 172
175 let (token_map, (file_id, start_offset), token_id) = if token_id.0 >= self.shift { 173 let shift = self.macro_def.0.shift();
176 (&self.macro_arg.1, self.arg_start, tt::TokenId(token_id.0 - self.shift).into()) 174 let (token_map, (file_id, start_offset), token_id) = if token_id.0 >= shift {
175 (&self.macro_arg.1, self.arg_start, tt::TokenId(token_id.0 - shift).into())
177 } else { 176 } else {
178 (&self.macro_def.1, self.def_start, token_id) 177 (&self.macro_def.1, self.def_start, token_id)
179 }; 178 };