wasm: Add matchLimit option to query methods
This exposes the new configurable match limits for query cursors.
This commit is contained in:
parent
1f6eac555c
commit
ad3907c2a6
3 changed files with 37 additions and 7 deletions
|
|
@ -594,9 +594,15 @@ void ts_query_matches_wasm(
|
|||
uint32_t start_row,
|
||||
uint32_t start_column,
|
||||
uint32_t end_row,
|
||||
uint32_t end_column
|
||||
uint32_t end_column,
|
||||
uint32_t match_limit
|
||||
) {
|
||||
if (!scratch_query_cursor) scratch_query_cursor = ts_query_cursor_new();
|
||||
if (match_limit == 0) {
|
||||
ts_query_cursor_set_match_limit(scratch_query_cursor, UINT32_MAX);
|
||||
} else {
|
||||
ts_query_cursor_set_match_limit(scratch_query_cursor, match_limit);
|
||||
}
|
||||
|
||||
TSNode node = unmarshal_node(tree);
|
||||
TSPoint start_point = {start_row, code_unit_to_byte(start_column)};
|
||||
|
|
@ -635,9 +641,15 @@ void ts_query_captures_wasm(
|
|||
uint32_t start_row,
|
||||
uint32_t start_column,
|
||||
uint32_t end_row,
|
||||
uint32_t end_column
|
||||
uint32_t end_column,
|
||||
uint32_t match_limit
|
||||
) {
|
||||
if (!scratch_query_cursor) scratch_query_cursor = ts_query_cursor_new();
|
||||
if (match_limit == 0) {
|
||||
ts_query_cursor_set_match_limit(scratch_query_cursor, UINT32_MAX);
|
||||
} else {
|
||||
ts_query_cursor_set_match_limit(scratch_query_cursor, match_limit);
|
||||
}
|
||||
|
||||
TSNode node = unmarshal_node(tree);
|
||||
TSPoint start_point = {start_row, code_unit_to_byte(start_column)};
|
||||
|
|
|
|||
|
|
@ -953,9 +953,17 @@ class Query {
|
|||
this[0] = 0;
|
||||
}
|
||||
|
||||
matches(node, startPosition, endPosition) {
|
||||
matches(node, startPosition, endPosition, options) {
|
||||
if (!startPosition) startPosition = ZERO_POINT;
|
||||
if (!endPosition) endPosition = ZERO_POINT;
|
||||
if (!options) options = {};
|
||||
|
||||
let matchLimit = options.matchLimit;
|
||||
if (typeof matchLimit === 'undefined') {
|
||||
matchLimit = 0;
|
||||
} else if (typeof matchLimit !== 'number') {
|
||||
throw new Error('Arguments must be numbers');
|
||||
}
|
||||
|
||||
marshalNode(node);
|
||||
|
||||
|
|
@ -965,7 +973,8 @@ class Query {
|
|||
startPosition.row,
|
||||
startPosition.column,
|
||||
endPosition.row,
|
||||
endPosition.column
|
||||
endPosition.column,
|
||||
matchLimit
|
||||
);
|
||||
|
||||
const rawCount = getValue(TRANSFER_BUFFER, 'i32');
|
||||
|
|
@ -1000,9 +1009,17 @@ class Query {
|
|||
return result;
|
||||
}
|
||||
|
||||
captures(node, startPosition, endPosition) {
|
||||
captures(node, startPosition, endPosition, options) {
|
||||
if (!startPosition) startPosition = ZERO_POINT;
|
||||
if (!endPosition) endPosition = ZERO_POINT;
|
||||
if (!options) options = {};
|
||||
|
||||
let matchLimit = options.matchLimit;
|
||||
if (typeof matchLimit === 'undefined') {
|
||||
matchLimit = 0;
|
||||
} else if (typeof matchLimit !== 'number') {
|
||||
throw new Error('Arguments must be numbers');
|
||||
}
|
||||
|
||||
marshalNode(node);
|
||||
|
||||
|
|
@ -1012,7 +1029,8 @@ class Query {
|
|||
startPosition.row,
|
||||
startPosition.column,
|
||||
endPosition.row,
|
||||
endPosition.column
|
||||
endPosition.column,
|
||||
matchLimit
|
||||
);
|
||||
|
||||
const count = getValue(TRANSFER_BUFFER, 'i32');
|
||||
|
|
|
|||
|
|
@ -256,7 +256,7 @@ describe("Query", () => {
|
|||
(array (identifier) @pre (identifier) @post)
|
||||
`);
|
||||
|
||||
const captures = query.captures(tree.rootNode);
|
||||
const captures = query.captures(tree.rootNode, null, null, {matchLimit: 32});
|
||||
assert.ok(query.didExceedMatchLimit());
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue