diff options
Diffstat (limited to 'crates/ra_mbe')
-rw-r--r-- | crates/ra_mbe/src/syntax_bridge.rs | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs index 540afc87c..a3715b1d4 100644 --- a/crates/ra_mbe/src/syntax_bridge.rs +++ b/crates/ra_mbe/src/syntax_bridge.rs | |||
@@ -237,12 +237,16 @@ impl TokenIdAlloc { | |||
237 | fn open_delim(&mut self, open_abs_range: TextRange) -> tt::TokenId { | 237 | fn open_delim(&mut self, open_abs_range: TextRange) -> tt::TokenId { |
238 | let token_id = tt::TokenId(self.next_id); | 238 | let token_id = tt::TokenId(self.next_id); |
239 | self.next_id += 1; | 239 | self.next_id += 1; |
240 | self.map.insert_delim(token_id, open_abs_range, open_abs_range); | 240 | self.map.insert_delim( |
241 | token_id, | ||
242 | open_abs_range - self.global_offset, | ||
243 | open_abs_range - self.global_offset, | ||
244 | ); | ||
241 | token_id | 245 | token_id |
242 | } | 246 | } |
243 | 247 | ||
244 | fn close_delim(&mut self, id: tt::TokenId, close_abs_range: TextRange) { | 248 | fn close_delim(&mut self, id: tt::TokenId, close_abs_range: TextRange) { |
245 | self.map.update_close_delim(id, close_abs_range); | 249 | self.map.update_close_delim(id, close_abs_range - self.global_offset); |
246 | } | 250 | } |
247 | } | 251 | } |
248 | 252 | ||
@@ -297,6 +301,7 @@ trait TokenConvertor { | |||
297 | } | 301 | } |
298 | 302 | ||
299 | result.push(if k.is_punct() { | 303 | result.push(if k.is_punct() { |
304 | assert_eq!(range.len().to_usize(), 1); | ||
300 | let delim = match k { | 305 | let delim = match k { |
301 | T!['('] => Some((tt::DelimiterKind::Parenthesis, T![')'])), | 306 | T!['('] => Some((tt::DelimiterKind::Parenthesis, T![')'])), |
302 | T!['{'] => Some((tt::DelimiterKind::Brace, T!['}'])), | 307 | T!['{'] => Some((tt::DelimiterKind::Brace, T!['}'])), |
@@ -461,25 +466,25 @@ impl TokenConvertor for Convertor { | |||
461 | } | 466 | } |
462 | 467 | ||
463 | fn bump(&mut self) -> Option<(Self::Token, TextRange)> { | 468 | fn bump(&mut self) -> Option<(Self::Token, TextRange)> { |
464 | let curr = self.current.clone()?; | ||
465 | if !curr.text_range().is_subrange(&self.range) { | ||
466 | return None; | ||
467 | } | ||
468 | |||
469 | if let Some((punct, offset)) = self.punct_offset.clone() { | 469 | if let Some((punct, offset)) = self.punct_offset.clone() { |
470 | if offset.to_usize() + 1 < punct.text().len() { | 470 | if offset.to_usize() + 1 < punct.text().len() { |
471 | let offset = offset + TextUnit::from_usize(1); | 471 | let offset = offset + TextUnit::from_usize(1); |
472 | let range = punct.text_range(); | 472 | let range = punct.text_range(); |
473 | self.punct_offset = Some((punct, offset)); | 473 | self.punct_offset = Some((punct.clone(), offset)); |
474 | let range = TextRange::offset_len(range.start() + offset, TextUnit::from_usize(1)); | 474 | let range = TextRange::offset_len(range.start() + offset, TextUnit::from_usize(1)); |
475 | return Some((SynToken::Punch(curr, offset), range)); | 475 | return Some((SynToken::Punch(punct, offset), range)); |
476 | } | 476 | } |
477 | } | 477 | } |
478 | 478 | ||
479 | let curr = self.current.clone()?; | ||
480 | if !curr.text_range().is_subrange(&self.range) { | ||
481 | return None; | ||
482 | } | ||
479 | self.current = curr.next_token(); | 483 | self.current = curr.next_token(); |
480 | 484 | ||
481 | let token = if curr.kind().is_punct() { | 485 | let token = if curr.kind().is_punct() { |
482 | let range = curr.text_range(); | 486 | let range = curr.text_range(); |
487 | let range = TextRange::offset_len(range.start(), TextUnit::from_usize(1)); | ||
483 | self.punct_offset = Some((curr.clone(), TextUnit::from_usize(0))); | 488 | self.punct_offset = Some((curr.clone(), TextUnit::from_usize(0))); |
484 | (SynToken::Punch(curr, TextUnit::from_usize(0)), range) | 489 | (SynToken::Punch(curr, TextUnit::from_usize(0)), range) |
485 | } else { | 490 | } else { |
@@ -492,11 +497,6 @@ impl TokenConvertor for Convertor { | |||
492 | } | 497 | } |
493 | 498 | ||
494 | fn peek(&self) -> Option<Self::Token> { | 499 | fn peek(&self) -> Option<Self::Token> { |
495 | let curr = self.current.clone()?; | ||
496 | if !curr.text_range().is_subrange(&self.range) { | ||
497 | return None; | ||
498 | } | ||
499 | |||
500 | if let Some((punct, mut offset)) = self.punct_offset.clone() { | 500 | if let Some((punct, mut offset)) = self.punct_offset.clone() { |
501 | offset = offset + TextUnit::from_usize(1); | 501 | offset = offset + TextUnit::from_usize(1); |
502 | if offset.to_usize() < punct.text().len() { | 502 | if offset.to_usize() < punct.text().len() { |
@@ -504,6 +504,11 @@ impl TokenConvertor for Convertor { | |||
504 | } | 504 | } |
505 | } | 505 | } |
506 | 506 | ||
507 | let curr = self.current.clone()?; | ||
508 | if !curr.text_range().is_subrange(&self.range) { | ||
509 | return None; | ||
510 | } | ||
511 | |||
507 | let token = if curr.kind().is_punct() { | 512 | let token = if curr.kind().is_punct() { |
508 | SynToken::Punch(curr, TextUnit::from_usize(0)) | 513 | SynToken::Punch(curr, TextUnit::from_usize(0)) |
509 | } else { | 514 | } else { |