Home Explore Blog CI



neovim

26th chunk of `runtime/doc/treesitter.txt`
f2b0cbf2f1b1c1014c4f3ccea99e9ac6f916aa2c11ed914f0000000100000c85
             a string representing the error type, in case of a failure
                    (currently only possible for timeouts). The second
                    argument is the list of trees returned by the parse (upon
                    success), or `nil` if the parse timed out (determined by
                    'redrawtime').

                    If parsing was still able to finish synchronously (within
                    3ms), `parse()` returns the list of trees. Otherwise, it
                    returns `nil`.

    Return: ~
        (`table<integer, TSTree>?`)

                                                 *LanguageTree:register_cbs()*
LanguageTree:register_cbs({cbs}, {recursive})
    Registers callbacks for the |LanguageTree|.

    Parameters: ~
      • {cbs}        (`table<TSCallbackNameOn,function>`) An
                     |nvim_buf_attach()|-like table argument with the
                     following handlers:
                     • `on_bytes` : see |nvim_buf_attach()|.
                     • `on_changedtree` : a callback that will be called every
                       time the tree has syntactical changes. It will be
                       passed two arguments: a table of the ranges (as node
                       ranges) that changed and the changed tree.
                     • `on_child_added` : emitted when a child is added to the
                       tree.
                     • `on_child_removed` : emitted when a child is removed
                       from the tree.
                     • `on_detach` : emitted when the buffer is detached, see
                       |nvim_buf_detach_event|. Takes one argument, the number
                       of the buffer.
      • {recursive}  (`boolean?`) Apply callbacks recursively for all
                     children. Any new children will also inherit the
                     callbacks.

LanguageTree:source()                                  *LanguageTree:source()*
    Returns the source content of the language tree (bufnr or string).

    Return: ~
        (`integer|string`)

                                               *LanguageTree:tree_for_range()*
LanguageTree:tree_for_range({range}, {opts})
    Gets the tree that contains {range}.

    Parameters: ~
      • {range}  (`table`) A table with the following fields:
                 • {[1]} (`integer`) start row
                 • {[2]} (`integer`) start column
                 • {[3]} (`integer`) end row
                 • {[4]} (`integer`) end column
      • {opts}   (`table?`) A table with the following fields:
                 • {ignore_injections}? (`boolean`, default: `true`) Ignore
                   injected languages

    Return: ~
        (`TSTree?`)

LanguageTree:trees()                                    *LanguageTree:trees()*
    Returns all trees of the regions parsed by this parser. Does not include
    child languages. The result is list-like if
    • this LanguageTree is the root, in which case the result is empty or a
      singleton list; or
    • the root LanguageTree is fully parsed.

    Return: ~
        (`table<integer, TSTree>`)


 vim:tw=78:ts=8:sw=4:sts=4:et:ft=help:norl:

Title: LanguageTree Functions: register_cbs, source, tree_for_range, and trees
Summary
This section details several functions related to the LanguageTree. `LanguageTree:register_cbs()` registers callbacks for the LanguageTree, similar to `nvim_buf_attach()`, including handlers for `on_bytes`, `on_changedtree`, `on_child_added`, `on_child_removed`, and `on_detach`. The recursive option applies callbacks to children. `LanguageTree:source()` returns the source content (buffer number or string). `LanguageTree:tree_for_range()` retrieves the tree containing a specified range, with an option to ignore injected languages. `LanguageTree:trees()` returns all trees parsed by the parser, excluding child languages.