aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/tokens.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast/tokens.rs')
-rw-r--r--crates/ra_syntax/src/ast/tokens.rs32
1 files changed, 14 insertions, 18 deletions
diff --git a/crates/ra_syntax/src/ast/tokens.rs b/crates/ra_syntax/src/ast/tokens.rs
index aa34b682d..26b8f9c36 100644
--- a/crates/ra_syntax/src/ast/tokens.rs
+++ b/crates/ra_syntax/src/ast/tokens.rs
@@ -2,7 +2,7 @@
2 2
3use crate::{ 3use crate::{
4 ast::{AstToken, Comment, RawString, String, Whitespace}, 4 ast::{AstToken, Comment, RawString, String, Whitespace},
5 TextRange, TextUnit, 5 TextRange, TextSize,
6}; 6};
7 7
8impl Comment { 8impl Comment {
@@ -94,14 +94,14 @@ impl QuoteOffsets {
94 return None; 94 return None;
95 } 95 }
96 96
97 let start = TextUnit::from(0); 97 let start = TextSize::from(0);
98 let left_quote = TextUnit::from_usize(left_quote) + TextUnit::of_char('"'); 98 let left_quote = TextSize::from_usize(left_quote) + TextSize::of('"');
99 let right_quote = TextUnit::from_usize(right_quote); 99 let right_quote = TextSize::from_usize(right_quote);
100 let end = TextUnit::of_str(literal); 100 let end = TextSize::of(literal);
101 101
102 let res = QuoteOffsets { 102 let res = QuoteOffsets {
103 quotes: [TextRange::from_to(start, left_quote), TextRange::from_to(right_quote, end)], 103 quotes: [TextRange::new(start, left_quote), TextRange::new(right_quote, end)],
104 contents: TextRange::from_to(left_quote, right_quote), 104 contents: TextRange::new(left_quote, right_quote),
105 }; 105 };
106 Some(res) 106 Some(res)
107 } 107 }
@@ -168,7 +168,7 @@ impl HasStringValue for RawString {
168impl RawString { 168impl RawString {
169 pub fn map_range_up(&self, range: TextRange) -> Option<TextRange> { 169 pub fn map_range_up(&self, range: TextRange) -> Option<TextRange> {
170 let contents_range = self.text_range_between_quotes()?; 170 let contents_range = self.text_range_between_quotes()?;
171 assert!(range.is_subrange(&TextRange::offset_len(0.into(), contents_range.len()))); 171 assert!(TextRange::up_to(contents_range.len()).contains_range(range));
172 Some(range + contents_range.start()) 172 Some(range + contents_range.start())
173 } 173 }
174} 174}
@@ -459,7 +459,7 @@ pub trait HasFormatSpecifier: AstToken {
459 while let Some((r, Ok(next_char))) = chars.peek() { 459 while let Some((r, Ok(next_char))) = chars.peek() {
460 if next_char.is_ascii_digit() { 460 if next_char.is_ascii_digit() {
461 chars.next(); 461 chars.next();
462 range = range.extend_to(r); 462 range = range.cover(*r);
463 } else { 463 } else {
464 break; 464 break;
465 } 465 }
@@ -477,7 +477,7 @@ pub trait HasFormatSpecifier: AstToken {
477 while let Some((r, Ok(next_char))) = chars.peek() { 477 while let Some((r, Ok(next_char))) = chars.peek() {
478 if *next_char == '_' || next_char.is_ascii_digit() || next_char.is_alphabetic() { 478 if *next_char == '_' || next_char.is_ascii_digit() || next_char.is_alphabetic() {
479 chars.next(); 479 chars.next();
480 range = range.extend_to(r); 480 range = range.cover(*r);
481 } else { 481 } else {
482 break; 482 break;
483 } 483 }
@@ -498,10 +498,8 @@ impl HasFormatSpecifier for String {
498 let mut res = Vec::with_capacity(text.len()); 498 let mut res = Vec::with_capacity(text.len());
499 rustc_lexer::unescape::unescape_str(text, &mut |range, unescaped_char| { 499 rustc_lexer::unescape::unescape_str(text, &mut |range, unescaped_char| {
500 res.push(( 500 res.push((
501 TextRange::from_to( 501 TextRange::new(TextSize::from_usize(range.start), TextSize::from_usize(range.end))
502 TextUnit::from_usize(range.start), 502 + offset,
503 TextUnit::from_usize(range.end),
504 ) + offset,
505 unescaped_char, 503 unescaped_char,
506 )) 504 ))
507 }); 505 });
@@ -521,10 +519,8 @@ impl HasFormatSpecifier for RawString {
521 let mut res = Vec::with_capacity(text.len()); 519 let mut res = Vec::with_capacity(text.len());
522 for (idx, c) in text.char_indices() { 520 for (idx, c) in text.char_indices() {
523 res.push(( 521 res.push((
524 TextRange::from_to( 522 TextRange::new(TextSize::from_usize(idx), TextSize::from_usize(idx + c.len_utf8()))
525 TextUnit::from_usize(idx), 523 + offset,
526 TextUnit::from_usize(idx + c.len_utf8()),
527 ) + offset,
528 Ok(c), 524 Ok(c),
529 )); 525 ));
530 } 526 }