Add ts_query_cursor_did_exceed_match_limit API
This commit is contained in:
parent
047d33eecf
commit
db6e1d9bdc
5 changed files with 38 additions and 0 deletions
|
|
@ -1425,6 +1425,7 @@ fn test_query_matches_with_too_many_permutations_to_track() {
|
|||
collect_matches(matches, &query, source.as_str())[0],
|
||||
(0, vec![("pre", "hello"), ("post", "hello")]),
|
||||
);
|
||||
assert_eq!(cursor.did_exceed_match_limit(), true);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -1462,6 +1463,7 @@ fn test_query_matches_with_alternatives_and_too_many_permutations_to_track() {
|
|||
collect_matches(matches, &query, source.as_str()),
|
||||
vec![(1, vec![("method", "b")]); 50],
|
||||
);
|
||||
assert_eq!(cursor.did_exceed_match_limit(), true);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -3119,6 +3121,7 @@ fn assert_query_matches(
|
|||
let mut cursor = QueryCursor::new();
|
||||
let matches = cursor.matches(&query, tree.root_node(), to_callback(source));
|
||||
assert_eq!(collect_matches(matches, &query, source), expected);
|
||||
assert_eq!(cursor.did_exceed_match_limit(), false);
|
||||
}
|
||||
|
||||
fn collect_matches<'a>(
|
||||
|
|
|
|||
|
|
@ -720,6 +720,16 @@ extern "C" {
|
|||
#[doc = " Start running a given query on a given node."]
|
||||
pub fn ts_query_cursor_exec(arg1: *mut TSQueryCursor, arg2: *const TSQuery, arg3: TSNode);
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Check if this cursor has exceeded its maximum number of in-progress"]
|
||||
#[doc = " matches."]
|
||||
#[doc = ""]
|
||||
#[doc = " Currently, query cursors have a fixed capacity for storing lists"]
|
||||
#[doc = " of in-progress captures. If this capacity is exceeded, then the"]
|
||||
#[doc = " earliest-starting match will silently be dropped to make room for"]
|
||||
#[doc = " further matches."]
|
||||
pub fn ts_query_cursor_did_exceed_match_limit(arg1: *const TSQueryCursor) -> bool;
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Set the range of bytes or (row, column) positions in which the query"]
|
||||
#[doc = " will be executed."]
|
||||
|
|
|
|||
|
|
@ -1595,6 +1595,12 @@ impl QueryCursor {
|
|||
QueryCursor(unsafe { NonNull::new_unchecked(ffi::ts_query_cursor_new()) })
|
||||
}
|
||||
|
||||
/// Check if, on its last execution, this cursor exceeded its maximum number of
|
||||
/// in-progress matches.
|
||||
pub fn did_exceed_match_limit(&self) -> bool {
|
||||
unsafe { ffi::ts_query_cursor_did_exceed_match_limit(self.0.as_ptr()) }
|
||||
}
|
||||
|
||||
/// Iterate over all of the matches in the order that they were found.
|
||||
///
|
||||
/// Each match contains the index of the pattern that matched, and a list of captures.
|
||||
|
|
|
|||
|
|
@ -791,6 +791,17 @@ 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
bool ts_query_cursor_did_exceed_match_limit(const TSQueryCursor *);
|
||||
|
||||
/**
|
||||
* Set the range of bytes or (row, column) positions in which the query
|
||||
* will be executed.
|
||||
|
|
|
|||
|
|
@ -236,6 +236,7 @@ struct TSQueryCursor {
|
|||
TSPoint end_point;
|
||||
bool ascending;
|
||||
bool halted;
|
||||
bool did_exceed_match_limit;
|
||||
};
|
||||
|
||||
static const TSQueryError PARENT_DONE = -1;
|
||||
|
|
@ -2103,6 +2104,7 @@ void ts_query_disable_pattern(
|
|||
TSQueryCursor *ts_query_cursor_new(void) {
|
||||
TSQueryCursor *self = ts_malloc(sizeof(TSQueryCursor));
|
||||
*self = (TSQueryCursor) {
|
||||
.did_exceed_match_limit = false,
|
||||
.ascending = false,
|
||||
.halted = false,
|
||||
.states = array_new(),
|
||||
|
|
@ -2126,6 +2128,10 @@ void ts_query_cursor_delete(TSQueryCursor *self) {
|
|||
ts_free(self);
|
||||
}
|
||||
|
||||
bool ts_query_cursor_did_exceed_match_limit(const TSQueryCursor *self) {
|
||||
return self->did_exceed_match_limit;
|
||||
}
|
||||
|
||||
void ts_query_cursor_exec(
|
||||
TSQueryCursor *self,
|
||||
const TSQuery *query,
|
||||
|
|
@ -2140,6 +2146,7 @@ void ts_query_cursor_exec(
|
|||
self->ascending = false;
|
||||
self->halted = false;
|
||||
self->query = query;
|
||||
self->did_exceed_match_limit = false;
|
||||
}
|
||||
|
||||
void ts_query_cursor_set_byte_range(
|
||||
|
|
@ -2359,6 +2366,7 @@ static CaptureList *ts_query_cursor__prepare_to_capture(
|
|||
// state has captured the earliest node in the document, and steal its
|
||||
// capture list.
|
||||
if (state->capture_list_id == NONE) {
|
||||
self->did_exceed_match_limit = true;
|
||||
uint32_t state_index, byte_offset, pattern_index;
|
||||
if (
|
||||
ts_query_cursor__first_in_progress_capture(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue