diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-08 19:03:35 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-08 19:03:35 +0000 |
commit | 4f4f7933b1b7ff34f8633b1686b18b2d1b994c47 (patch) | |
tree | a390d74ee5272a4a0070f5d4ea5281a04d4ba56a /crates/ra_syntax/src/yellow/syntax_text.rs | |
parent | c9e42fcf245be16958dca6571e4bccc6c29199df (diff) | |
parent | 921689b70da39160dd381e9716472827e36b03b8 (diff) |
Merge #469
469: kill text utils r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/yellow/syntax_text.rs')
-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())) |