aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir_expand/src/db.rs3
-rw-r--r--crates/ra_mbe/src/syntax_bridge.rs15
2 files changed, 7 insertions, 11 deletions
diff --git a/crates/ra_hir_expand/src/db.rs b/crates/ra_hir_expand/src/db.rs
index 72c728c93..e2860371f 100644
--- a/crates/ra_hir_expand/src/db.rs
+++ b/crates/ra_hir_expand/src/db.rs
@@ -151,8 +151,7 @@ pub(crate) fn parse_macro_with_info(
151 let arg_start = arg_tt.map(|t| t.syntax().text_range().start()); 151 let arg_start = arg_tt.map(|t| t.syntax().text_range().start());
152 let def_start = def_tt.map(|t| t.syntax().text_range().start()); 152 let def_start = def_tt.map(|t| t.syntax().text_range().start());
153 153
154 let macro_rules = db.macro_def(loc.def).ok_or("Fail to find macro definition").ok()?.0; 154 let shift = db.macro_def(loc.def)?.0.shift();
155 let shift = macro_rules.shift();
156 155
157 let arg_map = arg_start 156 let arg_map = arg_start
158 .map(|start| exp_map.map_ranges(&expand_info.arg_map, start, shift)) 157 .map(|start| exp_map.map_ranges(&expand_info.arg_map, start, shift))
diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs
index 0c499cd03..02ddd25e7 100644
--- a/crates/ra_mbe/src/syntax_bridge.rs
+++ b/crates/ra_mbe/src/syntax_bridge.rs
@@ -133,7 +133,7 @@ impl TokenMap {
133} 133}
134 134
135impl ExpandedRangeMap { 135impl ExpandedRangeMap {
136 fn set(&mut self, relative_range: TextRange, token_id: &tt::TokenId) { 136 fn add(&mut self, relative_range: TextRange, token_id: &tt::TokenId) {
137 self.ranges.push((relative_range, token_id.clone())) 137 self.ranges.push((relative_range, token_id.clone()))
138 } 138 }
139 139
@@ -145,13 +145,11 @@ impl ExpandedRangeMap {
145 ) -> Vec<(TextRange, TextRange)> { 145 ) -> Vec<(TextRange, TextRange)> {
146 self.ranges 146 self.ranges
147 .iter() 147 .iter()
148 .filter_map(|(r, tid)| if shift <= tid.0 { Some((r, tid.0 - shift)) } else { None })
149 .filter_map(|(r, tid)| { 148 .filter_map(|(r, tid)| {
150 if let Some(to_range) = to.relative_range_of(tt::TokenId(tid)) { 149 let adjusted_id = tt::TokenId(tid.0.checked_sub(shift)?);
151 Some((*r, TextRange::from_to(to_range.start() + start, to_range.end() + start))) 150 let to_range = to.relative_range_of(adjusted_id)?;
152 } else { 151
153 None 152 Some((*r, TextRange::offset_len(to_range.start() + start, to_range.len())))
154 }
155 }) 153 })
156 .collect() 154 .collect()
157 } 155 }
@@ -361,8 +359,7 @@ impl<'a> TreeSink for TtTreeSink<'a> {
361 self.text_pos + TextUnit::of_str(&self.buf), 359 self.text_pos + TextUnit::of_str(&self.buf),
362 TextUnit::of_str(&ident.text), 360 TextUnit::of_str(&ident.text),
363 ); 361 );
364 let token_id = ident.id; 362 self.range_map.add(range, &ident.id);
365 self.range_map.set(range, &token_id);
366 } 363 }
367 } 364 }
368 365