diff options
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r-- | crates/ra_syntax/src/algo.rs | 7 |
1 files changed, 6 insertions, 1 deletions
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; | |||
2 | 2 | ||
3 | use rowan::TransparentNewType; | 3 | use rowan::TransparentNewType; |
4 | 4 | ||
5 | use crate::{SyntaxNode, TextRange, TextUnit, AstNode}; | 5 | use crate::{SyntaxNode, TextRange, TextUnit, AstNode, Direction}; |
6 | 6 | ||
7 | pub use rowan::LeafAtOffset; | 7 | pub use rowan::LeafAtOffset; |
8 | 8 | ||
@@ -29,6 +29,11 @@ pub fn find_node_at_offset<N: AstNode>(syntax: &SyntaxNode, offset: TextUnit) -> | |||
29 | find_leaf_at_offset(syntax, offset).find_map(|leaf| leaf.ancestors().find_map(N::cast)) | 29 | find_leaf_at_offset(syntax, offset).find_map(|leaf| leaf.ancestors().find_map(N::cast)) |
30 | } | 30 | } |
31 | 31 | ||
32 | /// Finds the first sibling in the given direction which is not `trivia` | ||
33 | pub fn non_trivia_sibling(node: &SyntaxNode, direction: Direction) -> Option<&SyntaxNode> { | ||
34 | node.siblings(direction).skip(1).find(|node| !node.kind().is_trivia()) | ||
35 | } | ||
36 | |||
32 | pub fn find_covering_node(root: &SyntaxNode, range: TextRange) -> &SyntaxNode { | 37 | pub fn find_covering_node(root: &SyntaxNode, range: TextRange) -> &SyntaxNode { |
33 | SyntaxNode::from_repr(root.0.covering_node(range)) | 38 | SyntaxNode::from_repr(root.0.covering_node(range)) |
34 | } | 39 | } |