Skip to content

Commit

Permalink
docs(treesitter): annotate some tables as TSMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ofseed authored and lewis6991 committed Sep 1, 2024
1 parent 195eca9 commit 9b983e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions runtime/doc/treesitter.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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}
Expand Down
10 changes: 5 additions & 5 deletions runtime/lua/vim/treesitter/query.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9b983e5

Please sign in to comment.