Skip to main content

Node and tree operations

TreeWrapper.RootNode() returns a *Node. Walk performs depth-first traversal and passes each node plus its depth to the callback. Returning false from the callback skips that node's children. Filter returns all nodes with a matching grammar type.

Node inspection

Node provides Type, Text, Children, NamedChildren, ChildByFieldName, Parent, ChildCount, IsNamed, IsError, IsMissing, and Raw. The Raw method is an escape hatch to the underlying tree-sitter node.

Coordinates

Position() and EndPosition() return a Position with Row and Column. Both values are zero-based because they preserve tree-sitter coordinates. For example, the first character in a file is row 0, column 0.

This differs from generated Markdown summaries, whose declaration line ranges are converted to one-based human-facing lines.

Resource lifetime

The Node and TreeWrapper values refer to the tree owned by FileResult. Keep the result open while traversing and call FileResult.Close() only after all tree access is complete.