aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/algo.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/algo.rs')
-rw-r--r--crates/ra_syntax/src/algo.rs12
1 files changed, 6 insertions, 6 deletions
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;
11 11
12use crate::{ 12use crate::{
13 AstNode, Direction, NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxNodePtr, 13 AstNode, Direction, NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxNodePtr,
14 SyntaxToken, TextRange, TextUnit, 14 SyntaxToken, TextRange, TextSize,
15}; 15};
16 16
17/// Returns ancestors of the node at the offset, sorted by length. This should 17/// Returns ancestors of the node at the offset, sorted by length. This should
@@ -21,7 +21,7 @@ use crate::{
21/// t.parent().ancestors())`. 21/// t.parent().ancestors())`.
22pub fn ancestors_at_offset( 22pub fn ancestors_at_offset(
23 node: &SyntaxNode, 23 node: &SyntaxNode,
24 offset: TextUnit, 24 offset: TextSize,
25) -> impl Iterator<Item = SyntaxNode> { 25) -> impl Iterator<Item = SyntaxNode> {
26 node.token_at_offset(offset) 26 node.token_at_offset(offset)
27 .map(|token| token.parent().ancestors()) 27 .map(|token| token.parent().ancestors())
@@ -37,7 +37,7 @@ pub fn ancestors_at_offset(
37/// ``` 37/// ```
38/// 38///
39/// then the shorter node will be silently preferred. 39/// then the shorter node will be silently preferred.
40pub fn find_node_at_offset<N: AstNode>(syntax: &SyntaxNode, offset: TextUnit) -> Option<N> { 40pub fn find_node_at_offset<N: AstNode>(syntax: &SyntaxNode, offset: TextSize) -> Option<N> {
41 ancestors_at_offset(syntax, offset).find_map(N::cast) 41 ancestors_at_offset(syntax, offset).find_map(N::cast)
42} 42}
43 43
@@ -180,7 +180,7 @@ fn _insert_children(
180 position: InsertPosition<SyntaxElement>, 180 position: InsertPosition<SyntaxElement>,
181 to_insert: &mut dyn Iterator<Item = SyntaxElement>, 181 to_insert: &mut dyn Iterator<Item = SyntaxElement>,
182) -> SyntaxNode { 182) -> SyntaxNode {
183 let mut delta = TextUnit::default(); 183 let mut delta = TextSize::default();
184 let to_insert = to_insert.map(|element| { 184 let to_insert = to_insert.map(|element| {
185 delta += element.text_range().len(); 185 delta += element.text_range().len();
186 to_green_element(element) 186 to_green_element(element)
@@ -347,7 +347,7 @@ fn with_children(
347 parent: &SyntaxNode, 347 parent: &SyntaxNode,
348 new_children: Vec<NodeOrToken<rowan::GreenNode, rowan::GreenToken>>, 348 new_children: Vec<NodeOrToken<rowan::GreenNode, rowan::GreenToken>>,
349) -> SyntaxNode { 349) -> SyntaxNode {
350 let len = new_children.iter().map(|it| it.text_len()).sum::<TextUnit>(); 350 let len = new_children.iter().map(|it| it.text_len()).sum::<TextSize>();
351 let new_node = rowan::GreenNode::new(rowan::SyntaxKind(parent.kind() as u16), new_children); 351 let new_node = rowan::GreenNode::new(rowan::SyntaxKind(parent.kind() as u16), new_children);
352 let new_root_node = parent.replace_with(new_node); 352 let new_root_node = parent.replace_with(new_node);
353 let new_root_node = SyntaxNode::new_root(new_root_node); 353 let new_root_node = SyntaxNode::new_root(new_root_node);
@@ -355,7 +355,7 @@ fn with_children(
355 // FIXME: use a more elegant way to re-fetch the node (#1185), make 355 // FIXME: use a more elegant way to re-fetch the node (#1185), make
356 // `range` private afterwards 356 // `range` private afterwards
357 let mut ptr = SyntaxNodePtr::new(parent); 357 let mut ptr = SyntaxNodePtr::new(parent);
358 ptr.range = TextRange::offset_len(ptr.range.start(), len); 358 ptr.range = TextRange::at(ptr.range.start(), len);
359 ptr.to_node(&new_root_node) 359 ptr.to_node(&new_root_node)
360} 360}
361 361