aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_mbe')
-rw-r--r--crates/ra_mbe/src/syntax_bridge.rs15
1 files changed, 6 insertions, 9 deletions
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