TSNode
Methods31
function TSNode.parent() -> TSNode | nil
Get the node's immediate parent. Prefer |TSNode:childwithdescendant()| for iterating over the node's ancestors.
function TSNode.next_sibling() -> TSNode | nil
Get the node's next sibling.
function TSNode.prev_sibling() -> TSNode | nil
Get the node's previous sibling.
function TSNode.next_named_sibling() -> TSNode | nil
Get the node's next named sibling.
function TSNode.prev_named_sibling() -> TSNode | nil
Get the node's previous named sibling.
function TSNode.iter_children() -> fun() -> ...TSNode
Iterates over all the direct children of {TSNode}, regardless of whether they are named or not. Returns the child node plus the eventual field name corresponding to this child node.
function TSNode.field(name: string) -> TSNode[]
Returns a list of all the node's children that have the given field name.
function TSNode.child_count() -> integer
Get the node's number of children.
function TSNode.child(index: integer) -> TSNode | nil
Get the node's child at the given {index}, where zero represents the first child.
function TSNode.named_child_count() -> integer
Get the node's number of named children.
function TSNode.named_children() -> TSNode[]
Returns a list of the node's named children.
function TSNode.__has_ancestor(node_types: string[]) -> boolean
Check if the node has any of the given node types as its ancestor.
function TSNode.named_child(index: integer) -> TSNode | nil
Get the node's named child at the given {index}, where zero represents the first named child.
Get the node's child that contains {descendant} (includes {descendant}).
For example, with the following node hierarchy:
a -> b -> c
a:child_with_descendant(c) == b
a:child_with_descendant(b) == b
a:child_with_descendant(a) == nil
function TSNode.start() -> (integer, integer, integer)
Get the node's start position. Return three values: the row, column and total byte count (all zero-based).
function TSNode.end_() -> (integer, integer, integer)
Get the node's end position. Return three values: the row, column and total byte count (all zero-based).
function TSNode.range(include_bytes: false | nil) -> (integer, integer, integer, integer)
Get the range of the node.
Return four or six values:
- start row
- start column
- start byte (if {include_bytes} is
true) - end row
- end column
- end byte (if {include_bytes} is
true)
function TSNode.range(self: TSNode, include_bytes: true) -> ...integerfunction TSNode.type() -> string
Get the node's type as a string.
function TSNode.symbol() -> integer
Get the node's type as a numerical id.
function TSNode.named() -> boolean
Check if the node is named. Named nodes correspond to named rules in the grammar, whereas anonymous nodes correspond to string literals in the grammar.
function TSNode.missing() -> boolean
Check if the node is missing. Missing nodes are inserted by the parser in order to recover from certain kinds of syntax errors.
function TSNode.extra() -> boolean
Check if the node is extra. Extra nodes represent things like comments, which are not required by the grammar but can appear anywhere.
function TSNode.has_changes() -> boolean
Check if a syntax node has been edited.
function TSNode.has_error() -> boolean
Check if the node is a syntax error or contains any syntax errors.
function TSNode.sexpr() -> string
Get an S-expression representing the node as a string.
function TSNode.id() -> string
Get a unique identifier for the node inside its own tree.
No guarantees are made about this identifier's internal representation, except for being a primitive Lua type with value equality (so not a table). Presently it is a (non-printable) string.
Note: The id is not guaranteed to be unique for nodes from different trees.
function TSNode.tree() -> TSTree
Get the |TSTree| of the node.
function TSNode.descendant_for_range(start_row: integer, start_col: integer, end_row: integer, end_col: integer) -> TSNode | nil
Get the smallest node within this node that spans the given range of (row, column) positions
function TSNode.named_descendant_for_range(start_row: integer, start_col: integer, end_row: integer, end_col: integer) -> TSNode | nil
Get the smallest named node within this node that spans the given range of (row, column) positions
function TSNode.equal(node: TSNode) -> boolean
Check if {node} refers to the same node within the same tree.
function TSNode.byte_length() -> integer
Return the number of bytes spanned by this node.