From 1643d94a65a66f32b9278829dd3af00883f3852b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 30 Oct 2018 21:26:55 +0300 Subject: [PATCH] switch to TextRange::subrange --- crates/ra_analysis/src/descriptors/mod.rs | 3 +-- crates/ra_editor/src/completion.rs | 3 +-- crates/ra_syntax/src/algo/mod.rs | 4 ++-- crates/ra_syntax/src/text_utils.rs | 4 ---- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/crates/ra_analysis/src/descriptors/mod.rs b/crates/ra_analysis/src/descriptors/mod.rs index 873eb47e498..0220f7d5d30 100644 --- a/crates/ra_analysis/src/descriptors/mod.rs +++ b/crates/ra_analysis/src/descriptors/mod.rs @@ -2,7 +2,6 @@ pub(crate) mod module; use ra_syntax::{ ast::{self, AstNode, NameOwner}, - text_utils::is_subrange, }; #[derive(Debug, Clone)] @@ -23,7 +22,7 @@ impl FnDescriptor { let label: String = node .syntax() .children() - .filter(|child| !is_subrange(body_range, child.range())) + .filter(|child| !child.range().is_subrange(&body_range)) .map(|node| node.text().to_string()) .collect(); label diff --git a/crates/ra_editor/src/completion.rs b/crates/ra_editor/src/completion.rs index 0a36752554b..a0b168bc6da 100644 --- a/crates/ra_editor/src/completion.rs +++ b/crates/ra_editor/src/completion.rs @@ -3,7 +3,6 @@ use rustc_hash::{FxHashMap, FxHashSet}; use ra_syntax::{ algo::visit::{visitor, visitor_ctx, Visitor, VisitorCtx}, ast::{self, AstChildren, LoopBodyOwner, ModuleItemOwner}, - text_utils::is_subrange, AstNode, File, SyntaxKind::*, SyntaxNodeRef, TextUnit, @@ -191,7 +190,7 @@ fn is_in_loop_body(name_ref: ast::NameRef) -> bool { .visit::(LoopBodyOwner::loop_body) .accept(node); if let Some(Some(body)) = loop_body { - if is_subrange(body.syntax().range(), name_ref.syntax().range()) { + if name_ref.syntax().range().is_subrange(&body.syntax().range()) { return true; } } diff --git a/crates/ra_syntax/src/algo/mod.rs b/crates/ra_syntax/src/algo/mod.rs index d82c42b3e46..f92529d3ee4 100644 --- a/crates/ra_syntax/src/algo/mod.rs +++ b/crates/ra_syntax/src/algo/mod.rs @@ -2,7 +2,7 @@ pub mod visit; // pub mod walk; use crate::{ - text_utils::{contains_offset_nonstrict, is_subrange}, + text_utils::{contains_offset_nonstrict}, SyntaxNodeRef, TextRange, TextUnit, }; @@ -91,7 +91,7 @@ impl<'f> Iterator for LeafAtOffset<'f> { pub fn find_covering_node(root: SyntaxNodeRef, range: TextRange) -> SyntaxNodeRef { assert!( - is_subrange(root.range(), range), + range.is_subrange(&root.range()), "node range: {:?}, target range: {:?}", root.range(), range, diff --git a/crates/ra_syntax/src/text_utils.rs b/crates/ra_syntax/src/text_utils.rs index abda5ec3933..a90f8a083d6 100644 --- a/crates/ra_syntax/src/text_utils.rs +++ b/crates/ra_syntax/src/text_utils.rs @@ -4,10 +4,6 @@ pub fn contains_offset_nonstrict(range: TextRange, offset: TextUnit) -> bool { range.start() <= offset && offset <= range.end() } -pub fn is_subrange(range: TextRange, subrange: TextRange) -> bool { - range.start() <= subrange.start() && subrange.end() <= range.end() -} - pub fn intersect(r1: TextRange, r2: TextRange) -> Option { let start = r1.start().max(r2.start()); let end = r1.end().min(r2.end());