From f553837c1ca30a52bf5091689c21d3c3e3362395 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 8 Jan 2019 21:50:04 +0300 Subject: upstream text-utils to text_unit --- crates/ra_syntax/Cargo.toml | 2 +- crates/ra_syntax/src/text_utils.rs | 10 ---------- crates/ra_syntax/src/yellow/syntax_text.rs | 14 +++++--------- 3 files changed, 6 insertions(+), 20 deletions(-) (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/Cargo.toml b/crates/ra_syntax/Cargo.toml index eea0e251a..7c8e5b696 100644 --- a/crates/ra_syntax/Cargo.toml +++ b/crates/ra_syntax/Cargo.toml @@ -14,7 +14,7 @@ itertools = "0.8.0" drop_bomb = "0.1.4" parking_lot = "0.7.0" rowan = "0.2.0" -text_unit = "0.1.5" +text_unit = "0.1.6" ra_text_edit = { path = "../ra_text_edit" } [dev-dependencies] diff --git a/crates/ra_syntax/src/text_utils.rs b/crates/ra_syntax/src/text_utils.rs index 417d43e1b..7aaf4c223 100644 --- a/crates/ra_syntax/src/text_utils.rs +++ b/crates/ra_syntax/src/text_utils.rs @@ -1,15 +1,5 @@ use crate::TextRange; -pub fn intersect(r1: TextRange, r2: TextRange) -> Option { - let start = r1.start().max(r2.start()); - let end = r1.end().min(r2.end()); - if start <= end { - Some(TextRange::from_to(start, end)) - } else { - None - } -} - pub fn replace_range(mut text: String, range: TextRange, replace_with: &str) -> String { let start = u32::from(range.start()) as usize; let end = u32::from(range.end()) as usize; 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 @@ use std::{fmt, ops}; -use ra_text_edit::text_utils::contains_offset_nonstrict; -use crate::{ - text_utils::intersect, - SyntaxNode, TextRange, TextUnit, -}; +use crate::{SyntaxNode, TextRange, TextUnit}; #[derive(Clone)] pub struct SyntaxText<'a> { @@ -23,7 +19,7 @@ impl<'a> SyntaxText<'a> { let range = self.range; self.node.descendants().filter_map(move |node| { let text = node.leaf_text()?; - let range = intersect(range, node.range())?; + let range = range.intersection(&node.range())?; let range = range - node.range().start(); Some(&text[range]) }) @@ -92,13 +88,13 @@ pub trait SyntaxTextSlice: fmt::Debug { impl SyntaxTextSlice for TextRange { fn restrict(&self, range: TextRange) -> Option { - intersect(*self, range) + self.intersection(&range) } } impl SyntaxTextSlice for ops::RangeTo { fn restrict(&self, range: TextRange) -> Option { - if !contains_offset_nonstrict(range, self.end) { + if !range.contains_inclusive(self.end) { return None; } Some(TextRange::from_to(range.start(), self.end)) @@ -107,7 +103,7 @@ impl SyntaxTextSlice for ops::RangeTo { impl SyntaxTextSlice for ops::RangeFrom { fn restrict(&self, range: TextRange) -> Option { - if !contains_offset_nonstrict(range, self.start) { + if !range.contains_inclusive(self.start) { return None; } Some(TextRange::from_to(self.start, range.end())) -- cgit v1.2.3