diff options
Diffstat (limited to 'crates/ra_syntax/src/yellow')
-rw-r--r-- | crates/ra_syntax/src/yellow/syntax_text.rs | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/crates/ra_syntax/src/yellow/syntax_text.rs b/crates/ra_syntax/src/yellow/syntax_text.rs index 31db0fdab..08dbe57a2 100644 --- a/crates/ra_syntax/src/yellow/syntax_text.rs +++ b/crates/ra_syntax/src/yellow/syntax_text.rs | |||
@@ -1,10 +1,6 @@ | |||
1 | use std::{fmt, ops}; | 1 | use std::{fmt, ops}; |
2 | 2 | ||
3 | use ra_text_edit::text_utils::contains_offset_nonstrict; | 3 | use crate::{SyntaxNode, TextRange, TextUnit}; |
4 | use crate::{ | ||
5 | text_utils::intersect, | ||
6 | SyntaxNode, TextRange, TextUnit, | ||
7 | }; | ||
8 | 4 | ||
9 | #[derive(Clone)] | 5 | #[derive(Clone)] |
10 | pub struct SyntaxText<'a> { | 6 | pub struct SyntaxText<'a> { |
@@ -23,7 +19,7 @@ impl<'a> SyntaxText<'a> { | |||
23 | let range = self.range; | 19 | let range = self.range; |
24 | self.node.descendants().filter_map(move |node| { | 20 | self.node.descendants().filter_map(move |node| { |
25 | let text = node.leaf_text()?; | 21 | let text = node.leaf_text()?; |
26 | let range = intersect(range, node.range())?; | 22 | let range = range.intersection(&node.range())?; |
27 | let range = range - node.range().start(); | 23 | let range = range - node.range().start(); |
28 | Some(&text[range]) | 24 | Some(&text[range]) |
29 | }) | 25 | }) |
@@ -92,13 +88,13 @@ pub trait SyntaxTextSlice: fmt::Debug { | |||
92 | 88 | ||
93 | impl SyntaxTextSlice for TextRange { | 89 | impl SyntaxTextSlice for TextRange { |
94 | fn restrict(&self, range: TextRange) -> Option<TextRange> { | 90 | fn restrict(&self, range: TextRange) -> Option<TextRange> { |
95 | intersect(*self, range) | 91 | self.intersection(&range) |
96 | } | 92 | } |
97 | } | 93 | } |
98 | 94 | ||
99 | impl SyntaxTextSlice for ops::RangeTo<TextUnit> { | 95 | impl SyntaxTextSlice for ops::RangeTo<TextUnit> { |
100 | fn restrict(&self, range: TextRange) -> Option<TextRange> { | 96 | fn restrict(&self, range: TextRange) -> Option<TextRange> { |
101 | if !contains_offset_nonstrict(range, self.end) { | 97 | if !range.contains_inclusive(self.end) { |
102 | return None; | 98 | return None; |
103 | } | 99 | } |
104 | Some(TextRange::from_to(range.start(), self.end)) | 100 | Some(TextRange::from_to(range.start(), self.end)) |
@@ -107,7 +103,7 @@ impl SyntaxTextSlice for ops::RangeTo<TextUnit> { | |||
107 | 103 | ||
108 | impl SyntaxTextSlice for ops::RangeFrom<TextUnit> { | 104 | impl SyntaxTextSlice for ops::RangeFrom<TextUnit> { |
109 | fn restrict(&self, range: TextRange) -> Option<TextRange> { | 105 | fn restrict(&self, range: TextRange) -> Option<TextRange> { |
110 | if !contains_offset_nonstrict(range, self.start) { | 106 | if !range.contains_inclusive(self.start) { |
111 | return None; | 107 | return None; |
112 | } | 108 | } |
113 | Some(TextRange::from_to(self.start, range.end())) | 109 | Some(TextRange::from_to(self.start, range.end())) |