mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
docs: document TSNode:byte_length() (#26287)
Also update the type annotation of TSNode:id(), which returns a string, not an integer.
This commit is contained in:
@@ -165,6 +165,10 @@ TSNode:named_descendant_for_range({start_row}, {start_col}, {end_row}, {end_col}
|
|||||||
TSNode:equal({node})
|
TSNode:equal({node})
|
||||||
Check if {node} refers to the same node within the same tree.
|
Check if {node} refers to the same node within the same tree.
|
||||||
|
|
||||||
|
*TSNode:byte_length()*
|
||||||
|
TSNode:byte_length()
|
||||||
|
Return the number of bytes spanned by this node.
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
TREESITTER QUERIES *treesitter-query*
|
TREESITTER QUERIES *treesitter-query*
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
---@meta
|
---@meta
|
||||||
|
|
||||||
---@class TSNode: userdata
|
---@class TSNode: userdata
|
||||||
---@field id fun(self: TSNode): integer
|
---@field id fun(self: TSNode): string
|
||||||
---@field tree fun(self: TSNode): TSTree
|
---@field tree fun(self: TSNode): TSTree
|
||||||
---@field range fun(self: TSNode, include_bytes: false?): integer, integer, integer, integer
|
---@field range fun(self: TSNode, include_bytes: false?): integer, integer, integer, integer
|
||||||
---@field range fun(self: TSNode, include_bytes: true): integer, integer, integer, integer, integer, integer
|
---@field range fun(self: TSNode, include_bytes: true): integer, integer, integer, integer, integer, integer
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
---@field equal fun(self: TSNode, other: TSNode): boolean
|
---@field equal fun(self: TSNode, other: TSNode): boolean
|
||||||
---@field iter_children fun(self: TSNode): fun(): TSNode, string
|
---@field iter_children fun(self: TSNode): fun(): TSNode, string
|
||||||
---@field field fun(self: TSNode, name: string): TSNode[]
|
---@field field fun(self: TSNode, name: string): TSNode[]
|
||||||
|
---@field byte_length fun(self: TSNode): integer
|
||||||
local TSNode = {}
|
local TSNode = {}
|
||||||
|
|
||||||
---@param query userdata
|
---@param query userdata
|
||||||
|
@@ -24,6 +24,10 @@ local TSTreeView = {}
|
|||||||
---@field lang string Source language of this node
|
---@field lang string Source language of this node
|
||||||
---@field root TSNode
|
---@field root TSNode
|
||||||
|
|
||||||
|
---@class TSP.Injection
|
||||||
|
---@field lang string Source language of this injection
|
||||||
|
---@field root TSNode Root node of the injection
|
||||||
|
|
||||||
--- Traverse all child nodes starting at {node}.
|
--- Traverse all child nodes starting at {node}.
|
||||||
---
|
---
|
||||||
--- This is a recursive function. The {depth} parameter indicates the current recursion level.
|
--- This is a recursive function. The {depth} parameter indicates the current recursion level.
|
||||||
@@ -39,8 +43,8 @@ local TSTreeView = {}
|
|||||||
---@param node TSNode Starting node to begin traversal |tsnode|
|
---@param node TSNode Starting node to begin traversal |tsnode|
|
||||||
---@param depth integer Current recursion depth
|
---@param depth integer Current recursion depth
|
||||||
---@param lang string Language of the tree currently being traversed
|
---@param lang string Language of the tree currently being traversed
|
||||||
---@param injections table<integer,TSP.Node> Mapping of node ids to root nodes of injected language trees (see
|
---@param injections table<string, TSP.Injection> Mapping of node ids to root nodes
|
||||||
--- explanation above)
|
--- of injected language trees (see explanation above)
|
||||||
---@param tree TSP.Node[] Output table containing a list of tables each representing a node in the tree
|
---@param tree TSP.Node[] Output table containing a list of tables each representing a node in the tree
|
||||||
local function traverse(node, depth, lang, injections, tree)
|
local function traverse(node, depth, lang, injections, tree)
|
||||||
local injection = injections[node:id()]
|
local injection = injections[node:id()]
|
||||||
@@ -104,7 +108,7 @@ function TSTreeView:new(bufnr, lang)
|
|||||||
-- the primary tree that contains that root. Add a mapping from the node in the primary tree to
|
-- the primary tree that contains that root. Add a mapping from the node in the primary tree to
|
||||||
-- the root in the child tree to the {injections} table.
|
-- the root in the child tree to the {injections} table.
|
||||||
local root = parser:parse(true)[1]:root()
|
local root = parser:parse(true)[1]:root()
|
||||||
local injections = {} ---@type table<integer,table>
|
local injections = {} ---@type table<string, TSP.Injection>
|
||||||
|
|
||||||
parser:for_each_tree(function(parent_tree, parent_ltree)
|
parser:for_each_tree(function(parent_tree, parent_ltree)
|
||||||
local parent = parent_tree:root()
|
local parent = parent_tree:root()
|
||||||
|
Reference in New Issue
Block a user