Home Explore Blog CI



neovim

11th chunk of `runtime/doc/treesitter.txt`
bc435be503ed875b5b989ef216f6f62760ee4c60b465387e0000000100000fbb
   Return: ~
        (`TSNode?`)

TSNode:end_()                                                  *TSNode:end_()*
    Get the node's end position. Return three values: the row, column and
    total byte count (all zero-based).

    Return (multiple): ~
        (`integer`)
        (`integer`)
        (`integer`)

TSNode:equal({node})                                          *TSNode:equal()*
    Check if {node} refers to the same node within the same tree.

    Parameters: ~
      • {node}  (`TSNode`)

    Return: ~
        (`boolean`)

TSNode:extra()                                                *TSNode:extra()*
    Check if the node is extra. Extra nodes represent things like comments,
    which are not required by the grammar but can appear anywhere.

    Return: ~
        (`boolean`)

TSNode:field({name})                                          *TSNode:field()*
    Returns a list of all the node's children that have the given field name.

    Parameters: ~
      • {name}  (`string`)

    Return: ~
        (`TSNode[]`)

TSNode:has_changes()                                    *TSNode:has_changes()*
    Check if a syntax node has been edited.

    Return: ~
        (`boolean`)

TSNode:has_error()                                        *TSNode:has_error()*
    Check if the node is a syntax error or contains any syntax errors.

    Return: ~
        (`boolean`)

TSNode:id()                                                      *TSNode:id()*
    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.

    Return: ~
        (`string`)

TSNode:iter_children()                                *TSNode:iter_children()*
    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.

    Return: ~
        (`fun(): TSNode, string`)

TSNode:missing()                                            *TSNode:missing()*
    Check if the node is missing. Missing nodes are inserted by the parser in
    order to recover from certain kinds of syntax errors.

    Return: ~
        (`boolean`)

TSNode:named()                                                *TSNode:named()*
    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.

    Return: ~
        (`boolean`)

TSNode:named_child({index})                             *TSNode:named_child()*
    Get the node's named child at the given {index}, where zero represents the
    first named child.

    Parameters: ~
      • {index}  (`integer`)

    Return: ~
        (`TSNode?`)

TSNode:named_child_count()                        *TSNode:named_child_count()*
    Get the node's number of named children.

    Return: ~
        (`integer`)

TSNode:named_children()                              *TSNode:named_children()*
    Returns a list of the node's named children.

    Return: ~
        (`TSNode[]`)

                                         *TSNode:named_descendant_for_range()*
TSNode:named_descendant_for_range({start_row}, {start_col}, {end_row},
                                  {end_col})
    Get the smallest named node within this node that spans the given range of
    (row, column) positions

    Parameters: ~
      • {start_row}  (`integer`)
      • {start_col}  (`integer`)
      • {end_row}    (`integer`)
      • {end_col}    (`integer`)

    Return: ~
        (`TSNode?`)

TSNode:next_named_sibling()                      *TSNode:next_named_sibling()*
    Get the node's next named sibling.

    Return: ~
        (`TSNode?`)

TSNode:next_sibling()                                  *TSNode:next_sibling()*

Title: Treesitter API: TSNode Methods (Continued)
Summary
This section continues listing methods for `TSNode` objects in the Treesitter API. It covers functions such as `field({name})` to get children with a specific field name, `has_changes()` to check if the node has been edited, `has_error()` to detect syntax errors, `id()` to get a unique identifier, `iter_children()` to iterate over children and their field names, `missing()` to check for missing nodes, `named()` to check if a node is named, `named_child({index})` to get a named child by index, `named_child_count()` to get the number of named children, `named_children()` to get a list of named children, `named_descendant_for_range()` to find the smallest named node within a range, and `next_named_sibling()` and `next_sibling()` to retrieve the next named or regular sibling node respectively.