From b1d5817dd18b7b5fc102a63b084b1ee7ff4f9996 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 24 Apr 2020 23:40:41 +0200 Subject: Convert code to text-size --- crates/ra_syntax/src/algo.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'crates/ra_syntax/src/algo.rs') diff --git a/crates/ra_syntax/src/algo.rs b/crates/ra_syntax/src/algo.rs index 06df8495c..2a8dac757 100644 --- a/crates/ra_syntax/src/algo.rs +++ b/crates/ra_syntax/src/algo.rs @@ -11,7 +11,7 @@ use rustc_hash::FxHashMap; use crate::{ AstNode, Direction, NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxNodePtr, - SyntaxToken, TextRange, TextUnit, + SyntaxToken, TextRange, TextSize, }; /// Returns ancestors of the node at the offset, sorted by length. This should @@ -21,7 +21,7 @@ use crate::{ /// t.parent().ancestors())`. pub fn ancestors_at_offset( node: &SyntaxNode, - offset: TextUnit, + offset: TextSize, ) -> impl Iterator { node.token_at_offset(offset) .map(|token| token.parent().ancestors()) @@ -37,7 +37,7 @@ pub fn ancestors_at_offset( /// ``` /// /// then the shorter node will be silently preferred. -pub fn find_node_at_offset(syntax: &SyntaxNode, offset: TextUnit) -> Option { +pub fn find_node_at_offset(syntax: &SyntaxNode, offset: TextSize) -> Option { ancestors_at_offset(syntax, offset).find_map(N::cast) } @@ -180,7 +180,7 @@ fn _insert_children( position: InsertPosition, to_insert: &mut dyn Iterator, ) -> SyntaxNode { - let mut delta = TextUnit::default(); + let mut delta = TextSize::default(); let to_insert = to_insert.map(|element| { delta += element.text_range().len(); to_green_element(element) @@ -347,7 +347,7 @@ fn with_children( parent: &SyntaxNode, new_children: Vec>, ) -> SyntaxNode { - let len = new_children.iter().map(|it| it.text_len()).sum::(); + let len = new_children.iter().map(|it| it.text_len()).sum::(); let new_node = rowan::GreenNode::new(rowan::SyntaxKind(parent.kind() as u16), new_children); let new_root_node = parent.replace_with(new_node); let new_root_node = SyntaxNode::new_root(new_root_node); @@ -355,7 +355,7 @@ fn with_children( // FIXME: use a more elegant way to re-fetch the node (#1185), make // `range` private afterwards let mut ptr = SyntaxNodePtr::new(parent); - ptr.range = TextRange::offset_len(ptr.range.start(), len); + ptr.range = TextRange::at(ptr.range.start(), len); ptr.to_node(&new_root_node) } -- cgit v1.2.3