Skip to content

Commit 0c88360

Browse files
committed
add comment
1 parent 13301f2 commit 0c88360

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

crates/ra_syntax/src/algo.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ pub fn find_leaf_at_offset(node: &SyntaxNode, offset: TextUnit) -> LeafAtOffset<
1616
}
1717
}
1818

19+
/// Finds a node of specific Ast type at offset. Note that this is slightly
20+
/// impercise: if the cursor is strictly betwen two nodes of the desired type,
21+
/// as in
22+
///
23+
/// ```no-run
24+
/// struct Foo {}|struct Bar;
25+
/// ```
26+
///
27+
/// then the left node will be silently prefered.
1928
pub fn find_node_at_offset<N: AstNode>(syntax: &SyntaxNode, offset: TextUnit) -> Option<&N> {
2029
find_leaf_at_offset(syntax, offset).find_map(|leaf| leaf.ancestors().find_map(N::cast))
2130
}

0 commit comments

Comments
 (0)