refactor(treesitter): {start,stop} are optional in Query:iter_* methods

Document that the `start` and `stop` parameters in
`Query:iter_captures()` and `Query:iter_matches()` are optional.

The tree-sitter lib has been bumped up to 0.20.9, so we also no longer
need "Requires treesitter >= 0.20.9".
This commit is contained in:
Jongwook Choi
2024-02-02 01:51:35 -05:00
committed by Lewis Russell
parent 800134ea5e
commit d0e9e36a78
2 changed files with 22 additions and 18 deletions

View File

@@ -1086,8 +1086,10 @@ Query:iter_captures({node}, {source}, {start}, {stop})
• {node} (`TSNode`) under which the search will occur • {node} (`TSNode`) under which the search will occur
• {source} (`integer|string`) Source buffer or string to extract text • {source} (`integer|string`) Source buffer or string to extract text
from from
• {start} (`integer`) Starting line for the search • {start} (`integer?`) Starting line for the search. Defaults to
• {stop} (`integer`) Stopping line for the search (end-exclusive) `node:start()`.
• {stop} (`integer?`) Stopping line for the search (end-exclusive).
Defaults to `node:end_()`.
Return: ~ Return: ~
(`fun(end_line: integer?): integer, TSNode, TSMetadata`) capture id, (`fun(end_line: integer?): integer, TSNode, TSMetadata`) capture id,
@@ -1119,13 +1121,14 @@ Query:iter_matches({node}, {source}, {start}, {stop}, {opts})
Parameters: ~ Parameters: ~
• {node} (`TSNode`) under which the search will occur • {node} (`TSNode`) under which the search will occur
• {source} (`integer|string`) Source buffer or string to search • {source} (`integer|string`) Source buffer or string to search
• {start} (`integer`) Starting line for the search • {start} (`integer?`) Starting line for the search. Defaults to
• {stop} (`integer`) Stopping line for the search (end-exclusive) `node:start()`.
• {opts} (`table?`) Options: • {stop} (`integer?`) Stopping line for the search (end-exclusive).
Defaults to `node:end_()`.
• {opts} (`table?`) Optional keyword arguments:
• max_start_depth (integer) if non-zero, sets the maximum • max_start_depth (integer) if non-zero, sets the maximum
start depth for each match. This is used to prevent start depth for each match. This is used to prevent
traversing too deep into a tree. Requires treesitter >= traversing too deep into a tree.
0.20.9.
Return: ~ Return: ~
(`fun(): integer, table<integer,TSNode>, table`) pattern id, match, (`fun(): integer, table<integer,TSNode>, table`) pattern id, match,

View File

@@ -672,14 +672,16 @@ end
--- Returns the start and stop value if set else the node's range. --- Returns the start and stop value if set else the node's range.
-- When the node's range is used, the stop is incremented by 1 -- When the node's range is used, the stop is incremented by 1
-- to make the search inclusive. -- to make the search inclusive.
---@param start integer ---@param start integer|nil
---@param stop integer ---@param stop integer|nil
---@param node TSNode ---@param node TSNode
---@return integer, integer ---@return integer, integer
local function value_or_node_range(start, stop, node) local function value_or_node_range(start, stop, node)
if start == nil and stop == nil then if start == nil then
local node_start, _, node_stop, _ = node:range() start = node:start()
return node_start, node_stop + 1 -- Make stop inclusive end
if stop == nil then
stop = node:end_() + 1 -- Make stop inclusive
end end
return start, stop return start, stop
@@ -710,8 +712,8 @@ end
--- ---
---@param node TSNode under which the search will occur ---@param node TSNode under which the search will occur
---@param source (integer|string) Source buffer or string to extract text from ---@param source (integer|string) Source buffer or string to extract text from
---@param start integer Starting line for the search ---@param start? integer Starting line for the search. Defaults to `node:start()`.
---@param stop integer Stopping line for the search (end-exclusive) ---@param stop? integer Stopping line for the search (end-exclusive). Defaults to `node:end_()`.
--- ---
---@return (fun(end_line: integer|nil): integer, TSNode, TSMetadata): ---@return (fun(end_line: integer|nil): integer, TSNode, TSMetadata):
--- capture id, capture node, metadata --- capture id, capture node, metadata
@@ -769,12 +771,11 @@ end
--- ---
---@param node TSNode under which the search will occur ---@param node TSNode under which the search will occur
---@param source (integer|string) Source buffer or string to search ---@param source (integer|string) Source buffer or string to search
---@param start integer Starting line for the search ---@param start? integer Starting line for the search. Defaults to `node:start()`.
---@param stop integer Stopping line for the search (end-exclusive) ---@param stop? integer Stopping line for the search (end-exclusive). Defaults to `node:end_()`.
---@param opts table|nil Options: ---@param opts? table Optional keyword arguments:
--- - max_start_depth (integer) if non-zero, sets the maximum start depth --- - max_start_depth (integer) if non-zero, sets the maximum start depth
--- for each match. This is used to prevent traversing too deep into a tree. --- for each match. This is used to prevent traversing too deep into a tree.
--- Requires treesitter >= 0.20.9.
--- ---
---@return (fun(): integer, table<integer,TSNode>, table): pattern id, match, metadata ---@return (fun(): integer, table<integer,TSNode>, table): pattern id, match, metadata
function Query:iter_matches(node, source, start, stop, opts) function Query:iter_matches(node, source, start, stop, opts)