Home Explore Blog CI



neovim

12th chunk of `runtime/doc/treesitter.txt`
1e0ec2b1c523ea0695b00948cd33733611983c778c5c33760000000100000fbd
    *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()*
    Get the node's next sibling.

    Return: ~
        (`TSNode?`)

TSNode:parent()                                              *TSNode:parent()*
    Get the node's immediate parent. Prefer |TSNode:child_with_descendant()|
    for iterating over the node's ancestors.

    Return: ~
        (`TSNode?`)

TSNode:prev_named_sibling()                      *TSNode:prev_named_sibling()*
    Get the node's previous named sibling.

    Return: ~
        (`TSNode?`)

TSNode:prev_sibling()                                  *TSNode:prev_sibling()*
    Get the node's previous sibling.

    Return: ~
        (`TSNode?`)

TSNode:range({include_bytes})                                 *TSNode:range()*
    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`)

    Parameters: ~
      • {include_bytes}  (`false?`)

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

TSNode:sexpr()                                                *TSNode:sexpr()*
    Get an S-expression representing the node as a string.

    Return: ~
        (`string`)

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

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

TSNode:symbol()                                              *TSNode:symbol()*
    Get the node's type as a numerical id.

    Return: ~
        (`integer`)

TSNode:tree()                                                  *TSNode:tree()*
    Get the |TSTree| of the node.

    Return: ~
        (`TSTree`)

TSNode:type()                                                  *TSNode:type()*
    Get the node's type as a string.

    Return: ~
        (`string`)


==============================================================================
Lua module: vim.treesitter                               *lua-treesitter-core*

foldexpr({lnum})                                   *vim.treesitter.foldexpr()*
    Returns the fold level for {lnum} in the current buffer. Can be set
    directly to 'foldexpr': >lua
        vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
<

    Attributes: ~
        Since: 0.9.0

    Parameters: ~
      • {lnum}  (`integer?`) Line number to calculate fold level for

    Return: ~
        (`string`)

                                     *vim.treesitter.get_captures_at_cursor()*
get_captures_at_cursor({winnr})
    Returns a list of highlight capture names under the cursor

    Parameters: ~
      • {winnr}  (`integer?`) |window-ID| or 0 for current window (default)

    Return: ~
        (`string[]`) List of capture names

                                        *vim.treesitter.get_captures_at_pos()*
get_captures_at_pos({bufnr}, {row},

Title: Treesitter API: TSNode Methods (Cont.) and vim.treesitter Lua Module
Summary
This section details further methods for `TSNode` objects and introduces the `vim.treesitter` Lua module. TSNode methods covered include retrieval of named children/siblings (`named_children`, `named_descendant_for_range`, `next_named_sibling`, `prev_named_sibling`), general sibling/parent node retrieval (`next_sibling`, `prev_sibling`, `parent`), node range information (`range`), S-expression representation (`sexpr`), start position (`start`), node type as numerical ID or string (`symbol`, `type`), and the tree associated with the node (`tree`). The `vim.treesitter` module is introduced with functions for calculating fold level (`foldexpr`), and getting highlight capture names at the cursor or at a specific position (`get_captures_at_cursor`, `get_captures_at_pos`).