Home Explore Blog CI



neovim

25th chunk of `runtime/doc/treesitter.txt`
4d093b8baf818b83e333360c8f5f3659b120d1dd707f9ac800000001000008ac
 (`vim.treesitter.LanguageTree?`)

LanguageTree:parse({range}, {on_parse})                 *LanguageTree:parse()*
    Recursively parse all regions in the language tree using
    |treesitter-parsers| for the corresponding languages and run injection
    queries on the parsed trees to determine whether child trees should be
    created and parsed.

    Any region with empty range (`{}`, typically only the root tree) is always
    parsed; otherwise (typically injections) only if it intersects {range} (or
    if {range} is `true`).

    Parameters: ~
      • {range}     (`boolean|Range?`) Parse this range in the parser's
                    source. Set to `true` to run a complete parse of the
                    source (Note: Can be slow!) Set to `false|nil` to only
                    parse regions with empty ranges (typically only the root
                    tree without injections).
      • {on_parse}  (`fun(err?: string, trees?: table<integer, TSTree>)?`)
                    Function invoked when parsing completes. When provided and
                    `vim.g._ts_force_sync_parsing` is not set, parsing will
                    run asynchronously. The first argument to the function is
                    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()|.

Title: LanguageTree:parse and LanguageTree:register_cbs - Parsing and Callback Registration
Summary
This section describes the `LanguageTree:parse()` function, which recursively parses regions in the language tree using treesitter-parsers and injection queries to determine the creation and parsing of child trees. It details the parameters for specifying the parse range and the callback function to be invoked upon parsing completion. It also describes `LanguageTree:register_cbs()`, which registers callbacks for the LanguageTree, similar to `nvim_buf_attach()` with an `on_bytes` handler.