diff options
Diffstat (limited to 'runtime/lua/vim/treesitter/query.lua')
-rw-r--r-- | runtime/lua/vim/treesitter/query.lua | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/runtime/lua/vim/treesitter/query.lua b/runtime/lua/vim/treesitter/query.lua index 5830cc12e0..c0106c2da7 100644 --- a/runtime/lua/vim/treesitter/query.lua +++ b/runtime/lua/vim/treesitter/query.lua @@ -960,12 +960,19 @@ end ---@param source (integer|string) Source buffer or string to extract text from ---@param start? integer Starting line for the search. Defaults to `node:start()`. ---@param stop? integer Stopping line for the search (end-exclusive). Defaults to `node:end_()`. +---@param opts? table Optional keyword arguments: +--- - 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. +--- - match_limit (integer) Set the maximum number of in-progress matches (Default: 256). --- ---@return (fun(end_line: integer|nil): integer, TSNode, vim.treesitter.query.TSMetadata, TSQueryMatch, TSTree): --- capture id, capture node, metadata, match, tree --- ---@note Captures are only returned if the query pattern of a specific capture contained predicates. -function Query:iter_captures(node, source, start, stop) +function Query:iter_captures(node, source, start, stop, opts) + opts = opts or {} + opts.match_limit = opts.match_limit or 256 + if type(source) == 'number' and source == 0 then source = api.nvim_get_current_buf() end @@ -974,7 +981,7 @@ function Query:iter_captures(node, source, start, stop) -- Copy the tree to ensure it is valid during the entire lifetime of the iterator local tree = node:tree():copy() - local cursor = vim._create_ts_querycursor(node, self.query, start, stop, { match_limit = 256 }) + local cursor = vim._create_ts_querycursor(node, self.query, start, stop, opts) -- For faster checks that a match is not in the cache. local highest_cached_match_id = -1 |