From 82173c8de4b1283b6b54bd0def25b9c432614841 Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Thu, 21 Feb 2019 18:49:03 +0200 Subject: Move `non_trivia_sibling` to `ra_syntax::algo` --- crates/ra_syntax/src/algo.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/algo.rs b/crates/ra_syntax/src/algo.rs index e8cf0d4b5..e2b4f0388 100644 --- a/crates/ra_syntax/src/algo.rs +++ b/crates/ra_syntax/src/algo.rs @@ -2,7 +2,7 @@ pub mod visit; use rowan::TransparentNewType; -use crate::{SyntaxNode, TextRange, TextUnit, AstNode}; +use crate::{SyntaxNode, TextRange, TextUnit, AstNode, Direction}; pub use rowan::LeafAtOffset; @@ -29,6 +29,11 @@ pub fn find_node_at_offset(syntax: &SyntaxNode, offset: TextUnit) -> find_leaf_at_offset(syntax, offset).find_map(|leaf| leaf.ancestors().find_map(N::cast)) } +/// Finds the first sibling in the given direction which is not `trivia` +pub fn non_trivia_sibling(node: &SyntaxNode, direction: Direction) -> Option<&SyntaxNode> { + node.siblings(direction).skip(1).find(|node| !node.kind().is_trivia()) +} + pub fn find_covering_node(root: &SyntaxNode, range: TextRange) -> &SyntaxNode { SyntaxNode::from_repr(root.0.covering_node(range)) } -- cgit v1.2.3