syntax::algo

Function find_node_at_offset

source
pub fn find_node_at_offset<N: AstNode>(
    syntax: &SyntaxNode,
    offset: TextSize,
) -> Option<N>
Expand description

Finds a node of specific Ast type at offset. Note that this is slightly imprecise: if the cursor is strictly between two nodes of the desired type, as in

struct Foo {}|struct Bar;

then the shorter node will be silently preferred.