query: Allow configurable match limit

The default is now a whopping 64K matches, which "should be enough for
everyone".  You can use the new `ts_query_cursor_set_match_limit`
function to set this to a lower limit, such as the previous default of
32.
This commit is contained in:
Douglas Creager 2021-06-02 11:24:58 -04:00
parent 78010722a4
commit cd96552448
5 changed files with 106 additions and 23 deletions

View file

@ -798,15 +798,23 @@ void ts_query_cursor_delete(TSQueryCursor *);
void ts_query_cursor_exec(TSQueryCursor *, const TSQuery *, TSNode);
/**
* Check if this cursor has exceeded its maximum number of in-progress
* matches.
* Manage the maximum number of in-progress matches allowed by this query
* cursor.
*
* Currently, query cursors have a fixed capacity for storing lists
* of in-progress captures. If this capacity is exceeded, then the
* earliest-starting match will silently be dropped to make room for
* further matches.
* Query cursors have a maximum capacity for storing lists of in-progress
* captures. If this capacity is exceeded, then the earliest-starting match will
* silently be dropped to make room for further matches.
*
* By default, this limit is 65,536 pending matches, which is effectively
* unlimited for most queries and syntax trees. You can optionally set this to a
* lower number if you want to have (and check) a tighter bound on query
* complexity.
*
* If you update the match limit, it must be > 0 and <= 65536.
*/
bool ts_query_cursor_did_exceed_match_limit(const TSQueryCursor *);
uint32_t ts_query_cursor_match_limit(const TSQueryCursor *);
void ts_query_cursor_set_match_limit(TSQueryCursor *, uint32_t);
/**
* Set the range of bytes or (row, column) positions in which the query