mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 04:23:25 +00:00
add comment
This commit is contained in:
parent
13301f284c
commit
0c88360eb4
1 changed files with 9 additions and 0 deletions
|
@ -16,6 +16,15 @@ pub fn find_leaf_at_offset(node: &SyntaxNode, offset: TextUnit) -> LeafAtOffset<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Finds a node of specific Ast type at offset. Note that this is slightly
|
||||||
|
/// impercise: if the cursor is strictly betwen two nodes of the desired type,
|
||||||
|
/// as in
|
||||||
|
///
|
||||||
|
/// ```no-run
|
||||||
|
/// struct Foo {}|struct Bar;
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// then the left node will be silently prefered.
|
||||||
pub fn find_node_at_offset<N: AstNode>(syntax: &SyntaxNode, offset: TextUnit) -> Option<&N> {
|
pub fn find_node_at_offset<N: AstNode>(syntax: &SyntaxNode, offset: TextUnit) -> Option<&N> {
|
||||||
find_leaf_at_offset(syntax, offset).find_map(|leaf| leaf.ancestors().find_map(N::cast))
|
find_leaf_at_offset(syntax, offset).find_map(|leaf| leaf.ancestors().find_map(N::cast))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue