tree-sitter - v0.25.1
    Preparing search index...

    Interface TreeCursor

    A stateful object for walking a syntax Tree efficiently

    interface TreeCursor {
        currentDepth: number;
        currentDescendantIndex: number;
        currentFieldId: number;
        currentFieldName: string;
        currentNode: SyntaxNode;
        endIndex: number;
        endPosition: Point;
        nodeIsMissing: boolean;
        nodeIsNamed: boolean;
        nodeStateId: number;
        nodeText: string;
        nodeType: string;
        nodeTypeId: number;
        startIndex: number;
        startPosition: Point;
        gotoDescendant(goalDescendantIndex: number): void;
        gotoFirstChild(): boolean;
        gotoFirstChildForIndex(goalIndex: number): boolean;
        gotoFirstChildForPosition(goalPosition: Point): boolean;
        gotoLastChild(): boolean;
        gotoNextSibling(): boolean;
        gotoParent(): boolean;
        gotoPreviousSibling(): boolean;
        reset(node: SyntaxNode): void;
        resetTo(cursor: TreeCursor): void;
    }
    Index

    Properties

    currentDepth: number

    The depth of the current node relative to the node where the cursor was created

    currentDescendantIndex: number

    The index of the current node among all descendants of the original node

    currentFieldId: number

    The numerical field ID of the current node

    currentFieldName: string

    The field name of the current node

    currentNode: SyntaxNode

    The current node that the cursor is pointing to

    endIndex: number

    The end byte index of the current node

    endPosition: Point

    The end position of the current node

    nodeIsMissing: boolean

    Whether the current node is missing from the source code

    nodeIsNamed: boolean

    Whether the current node is named

    nodeStateId: number

    The parse state of the current node

    nodeText: string

    The text of the current node

    nodeType: string

    The type of the current node as a string

    nodeTypeId: number

    The type of the current node as a numeric ID

    startIndex: number

    The start byte index of the current node

    startPosition: Point

    The start position of the current node

    Methods

    • Move the cursor to the descendant node at the given index, where zero represents the original node the cursor was created with.

      Parameters

      • goalDescendantIndex: number

        The index of the descendant to move to

      Returns void

    • Move this cursor to the first child of its current node.

      Returns boolean

      true if cursor successfully moved, false if there were no children

    • Move this cursor to the first child that extends beyond the given byte offset

      Parameters

      • goalIndex: number

        The byte offset to search for

      Returns boolean

      true if a child was found and cursor moved, false otherwise

    • Move this cursor to the first child that extends beyond the given position

      Parameters

      • goalPosition: Point

        The position to search for

      Returns boolean

      true if a child was found and cursor moved, false otherwise

    • Move this cursor to the last child of its current node. Note: This may be slower than gotoFirstChild() as it needs to iterate through all children to compute the position.

      Returns boolean

      true if cursor successfully moved, false if there were no children

    • Move this cursor to the next sibling of its current node

      Returns boolean

      true if cursor successfully moved, false if there was no next sibling

    • Move this cursor to the parent of its current node.

      Returns boolean

      true if cursor successfully moved, false if there was no parent (cursor was already at the root node)

    • Move this cursor to the previous sibling of its current node. Note: This may be slower than gotoNextSibling() due to how node positions are stored. In the worst case, it will need to iterate through all previous siblings to recalculate positions.

      Returns boolean

      true if cursor successfully moved, false if there was no previous sibling

    • Re-initialize this cursor to the same position as another cursor. Unlike reset(), this will not lose parent information and allows reusing already created cursors.

      Parameters

      • cursor: TreeCursor

        The cursor to copy the position from

      Returns void