switch to TextRange::subrange

This commit is contained in:
Aleksey Kladov 2018-10-30 21:26:55 +03:00
parent 950e8b8182
commit 1643d94a65
4 changed files with 4 additions and 10 deletions

View file

@ -2,7 +2,6 @@ pub(crate) mod module;
use ra_syntax::{ use ra_syntax::{
ast::{self, AstNode, NameOwner}, ast::{self, AstNode, NameOwner},
text_utils::is_subrange,
}; };
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -23,7 +22,7 @@ impl FnDescriptor {
let label: String = node let label: String = node
.syntax() .syntax()
.children() .children()
.filter(|child| !is_subrange(body_range, child.range())) .filter(|child| !child.range().is_subrange(&body_range))
.map(|node| node.text().to_string()) .map(|node| node.text().to_string())
.collect(); .collect();
label label

View file

@ -3,7 +3,6 @@ use rustc_hash::{FxHashMap, FxHashSet};
use ra_syntax::{ use ra_syntax::{
algo::visit::{visitor, visitor_ctx, Visitor, VisitorCtx}, algo::visit::{visitor, visitor_ctx, Visitor, VisitorCtx},
ast::{self, AstChildren, LoopBodyOwner, ModuleItemOwner}, ast::{self, AstChildren, LoopBodyOwner, ModuleItemOwner},
text_utils::is_subrange,
AstNode, File, AstNode, File,
SyntaxKind::*, SyntaxKind::*,
SyntaxNodeRef, TextUnit, SyntaxNodeRef, TextUnit,
@ -191,7 +190,7 @@ fn is_in_loop_body(name_ref: ast::NameRef) -> bool {
.visit::<ast::LoopExpr, _>(LoopBodyOwner::loop_body) .visit::<ast::LoopExpr, _>(LoopBodyOwner::loop_body)
.accept(node); .accept(node);
if let Some(Some(body)) = loop_body { 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; return true;
} }
} }

View file

@ -2,7 +2,7 @@ pub mod visit;
// pub mod walk; // pub mod walk;
use crate::{ use crate::{
text_utils::{contains_offset_nonstrict, is_subrange}, text_utils::{contains_offset_nonstrict},
SyntaxNodeRef, TextRange, TextUnit, SyntaxNodeRef, TextRange, TextUnit,
}; };
@ -91,7 +91,7 @@ impl<'f> Iterator for LeafAtOffset<'f> {
pub fn find_covering_node(root: SyntaxNodeRef, range: TextRange) -> SyntaxNodeRef { pub fn find_covering_node(root: SyntaxNodeRef, range: TextRange) -> SyntaxNodeRef {
assert!( assert!(
is_subrange(root.range(), range), range.is_subrange(&root.range()),
"node range: {:?}, target range: {:?}", "node range: {:?}, target range: {:?}",
root.range(), root.range(),
range, range,

View file

@ -4,10 +4,6 @@ pub fn contains_offset_nonstrict(range: TextRange, offset: TextUnit) -> bool {
range.start() <= offset && offset <= range.end() 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<TextRange> { pub fn intersect(r1: TextRange, r2: TextRange) -> Option<TextRange> {
let start = r1.start().max(r2.start()); let start = r1.start().max(r2.start());
let end = r1.end().min(r2.end()); let end = r1.end().min(r2.end());