docs(treesitter): annotate some tables as TSMetadata

This commit is contained in:
Yi Ming 2024-09-01 12:07:07 +08:00 committed by Lewis Russell
parent 195eca94d4
commit 9b983e5f6c
2 changed files with 9 additions and 9 deletions

View File

@ -1023,7 +1023,7 @@ add_directive({name}, {handler}, {opts})
Parameters: ~
• {name} (`string`) Name of the directive, without leading #
• {handler} (`fun(match: table<integer,TSNode[]>, pattern: integer, source: integer|string, predicate: any[], metadata: table)`)
• {handler} (`fun(match: table<integer,TSNode[]>, pattern: integer, source: integer|string, predicate: any[], metadata: vim.treesitter.query.TSMetadata)`)
• match: A table mapping capture IDs to a list of captured
nodes
• pattern: the index of the matching pattern in the query
@ -1046,7 +1046,7 @@ add_predicate({name}, {handler}, {opts})
Parameters: ~
• {name} (`string`) Name of the predicate, without leading #
• {handler} (`fun(match: table<integer,TSNode[]>, pattern: integer, source: integer|string, predicate: any[], metadata: table)`)
• {handler} (`fun(match: table<integer,TSNode[]>, pattern: integer, source: integer|string, predicate: any[], metadata: vim.treesitter.query.TSMetadata)`)
• see |vim.treesitter.query.add_directive()| for argument
meanings
• {opts} (`table`) A table with the following fields:
@ -1256,8 +1256,8 @@ Query:iter_matches({node}, {source}, {start}, {stop}, {opts})
eventually become the default and removed.
Return: ~
(`fun(): integer, table<integer, TSNode[]>, table`) pattern id, match,
metadata
(`fun(): integer, table<integer, TSNode[]>, vim.treesitter.query.TSMetadata`)
pattern id, match, metadata
set({lang}, {query_name}, {text}) *vim.treesitter.query.set()*
Sets the runtime query named {query_name} for {lang}

View File

@ -487,8 +487,8 @@ predicate_handlers['any-vim-match?'] = predicate_handlers['any-match?']
---@class vim.treesitter.query.TSMetadata
---@field range? Range
---@field conceal? string
---@field [integer] vim.treesitter.query.TSMetadata
---@field [string] integer|string
---@field [integer]? vim.treesitter.query.TSMetadata
---@field [string]? integer|string
---@alias TSDirective fun(match: table<integer,TSNode[]>, _, _, predicate: (string|integer)[], metadata: vim.treesitter.query.TSMetadata)
@ -627,7 +627,7 @@ local directive_handlers = {
--- Adds a new predicate to be used in queries
---
---@param name string Name of the predicate, without leading #
---@param handler fun(match: table<integer,TSNode[]>, pattern: integer, source: integer|string, predicate: any[], metadata: table)
---@param handler fun(match: table<integer,TSNode[]>, pattern: integer, source: integer|string, predicate: any[], metadata: vim.treesitter.query.TSMetadata)
--- - see |vim.treesitter.query.add_directive()| for argument meanings
---@param opts vim.treesitter.query.add_predicate.Opts
function M.add_predicate(name, handler, opts)
@ -667,7 +667,7 @@ end
--- metadata table `metadata[capture_id].key = value`
---
---@param name string Name of the directive, without leading #
---@param handler fun(match: table<integer,TSNode[]>, pattern: integer, source: integer|string, predicate: any[], metadata: table)
---@param handler fun(match: table<integer,TSNode[]>, pattern: integer, source: integer|string, predicate: any[], metadata: vim.treesitter.query.TSMetadata)
--- - match: A table mapping capture IDs to a list of captured nodes
--- - pattern: the index of the matching pattern in the query file
--- - predicate: list of strings containing the full directive being called, e.g.
@ -929,7 +929,7 @@ end
--- Older versions of iter_matches incorrectly mapped capture IDs to a single node, which is
--- incorrect behavior. This option will eventually become the default and removed.
---
---@return (fun(): integer, table<integer, TSNode[]>, table): pattern id, match, metadata
---@return (fun(): integer, table<integer, TSNode[]>, vim.treesitter.query.TSMetadata): pattern id, match, metadata
function Query:iter_matches(node, source, start, stop, opts)
opts = opts or {}
opts.match_limit = opts.match_limit or 256