aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2023-02-26 16:53:33 +0000
committerGitHub <noreply@github.com>2023-02-26 16:53:33 +0000
commit774e59f3f9bf50c8350857c6722bb58df2dd940a (patch)
tree926658914fe8be2464ffab876a0ffdfbcb9f4427 /runtime
parented58580dfe51faba6a35adb43322e0991e48e4c6 (diff)
downloadrneovim-774e59f3f9bf50c8350857c6722bb58df2dd940a.tar.gz
rneovim-774e59f3f9bf50c8350857c6722bb58df2dd940a.tar.bz2
rneovim-774e59f3f9bf50c8350857c6722bb58df2dd940a.zip
feat(treesitter): expand the API
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/news.txt8
-rw-r--r--runtime/doc/treesitter.txt25
-rw-r--r--runtime/lua/vim/treesitter/_meta.lua8
3 files changed, 37 insertions, 4 deletions
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index 23bb6d4343..c5261b739d 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -171,6 +171,14 @@ The following new APIs or features were added.
• |vim.treesitter.foldexpr()| can be used for 'foldexpr' to use treesitter for folding.
+• Expanded the TSNode API with:
+ - |TSNode:tree()|
+ - |TSNode:has_changes()|
+ - |TSNode:extra()|
+ - |TSNode:equal()|
+
+ Additionally |TSNode:range()| now takes an optional {include_bytes} argument.
+
==============================================================================
CHANGED FEATURES *news-changes*
diff --git a/runtime/doc/treesitter.txt b/runtime/doc/treesitter.txt
index 76cde91920..fdea84282f 100644
--- a/runtime/doc/treesitter.txt
+++ b/runtime/doc/treesitter.txt
@@ -136,9 +136,16 @@ TSNode:end_() *TSNode:end_()*
Get the node's end position. Return three values: the row, column and
total byte count (all zero-based).
-TSNode:range() *TSNode:range()*
- Get the range of the node. Return four values: the row, column of the
- start position, then the row, column of the end position.
+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`)
TSNode:type() *TSNode:type()*
Get the node's type as a string.
@@ -155,6 +162,13 @@ 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.
+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.
+
+TSNode:has_changes() *TSNode:has_changes()*
+ Check if a syntax node has been edited.
+
TSNode:has_error() *TSNode:has_error()*
Check if the node is a syntax error or contains any syntax errors.
@@ -171,6 +185,8 @@ TSNode:id() *TSNode:id()*
Note: The `id` is not guaranteed to be unique for nodes from different
trees.
+TSNode:tree() *TSNode:tree()*
+ Get the |TSTree| of the node.
*TSNode:descendant_for_range()*
TSNode:descendant_for_range({start_row}, {start_col}, {end_row}, {end_col})
Get the smallest node within this node that spans the given range of (row,
@@ -180,6 +196,9 @@ TSNode:descendant_for_range({start_row}, {start_col}, {end_row}, {end_col})
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
+ *TSNode:equal()*
+TSNode:equal({node})
+ Check if {node} refers to the same node within the same tree.
==============================================================================
TREESITTER QUERIES *treesitter-query*
diff --git a/runtime/lua/vim/treesitter/_meta.lua b/runtime/lua/vim/treesitter/_meta.lua
index 87b4560798..731a5ebf9f 100644
--- a/runtime/lua/vim/treesitter/_meta.lua
+++ b/runtime/lua/vim/treesitter/_meta.lua
@@ -2,6 +2,7 @@
---@class TSNode
---@field id fun(self: TSNode): integer
+---@field tree fun(self: TSNode): TSTree
---@field range fun(self: TSNode): integer, integer, integer, integer
---@field start fun(self: TSNode): integer, integer, integer
---@field end_ fun(self: TSNode): integer, integer, integer
@@ -9,6 +10,7 @@
---@field symbol fun(self: TSNode): integer
---@field named fun(self: TSNode): boolean
---@field missing fun(self: TSNode): boolean
+---@field extra fun(self: TSNode): boolean
---@field child_count fun(self: TSNode): integer
---@field named_child_count fun(self: TSNode): integer
---@field child fun(self: TSNode, integer): TSNode
@@ -21,7 +23,8 @@
---@field next_named_sibling fun(self: TSNode): TSNode
---@field prev_named_sibling fun(self: TSNode): TSNode
---@field named_children fun(self: TSNode): TSNode[]
----@field has_error fun(self: TSNode): boolean
+---@field has_changes fun(self: TSNode): boolean
+---@field equal fun(self: TSNode, other: TSNode): boolean
---@field iter_children fun(self: TSNode): fun(): TSNode, string
local TSNode = {}
@@ -41,8 +44,11 @@ function TSNode:_rawquery(query, captures, start, end_) end
---@class TSParser
---@field parse fun(self: TSParser, tree, source: integer|string): TSTree, integer[]
+---@field reset fun(self: TSParser)
---@field included_ranges fun(self: TSParser): integer[]
---@field set_included_ranges fun(self: TSParser, ranges: integer[][])
+---@field set_timeout fun(self: TSParser, timeout: integer)
+---@field timeout fun(self: TSParser): integer
---@class TSTree
---@field root fun(self: TSTree): TSNode