Assign ids to query matches only when the matches are returned

Refs #1372
This commit is contained in:
Max Brunsfeld 2021-09-13 12:39:48 -07:00
parent 6c66b5ee29
commit 22a5cfbe10

View file

@ -2561,6 +2561,7 @@ static void ts_query_cursor__add_state(
pattern->step_index
);
array_insert(&self->states, index, ((QueryState) {
.id = UINT32_MAX,
.capture_list_id = NONE,
.step_index = pattern->step_index,
.pattern_index = pattern->pattern_index,
@ -2725,7 +2726,6 @@ static inline bool ts_query_cursor__advance(
if (step->depth == PATTERN_DONE_MARKER) {
if (state->start_depth > self->depth || self->halted) {
LOG(" finish pattern %u\n", state->pattern_index);
state->id = self->next_state_id++;
array_push(&self->finished_states, *state);
did_match = true;
deleted_count++;
@ -3114,7 +3114,6 @@ static inline bool ts_query_cursor__advance(
LOG(" defer finishing pattern %u\n", state->pattern_index);
} else {
LOG(" finish pattern %u\n", state->pattern_index);
state->id = self->next_state_id++;
array_push(&self->finished_states, *state);
array_erase(&self->states, state - self->states.contents);
did_match = true;
@ -3169,6 +3168,7 @@ bool ts_query_cursor_next_match(
}
QueryState *state = &self->finished_states.contents[0];
if (state->id == UINT32_MAX) state->id = self->next_state_id++;
match->id = state->id;
match->pattern_index = state->pattern_index;
const CaptureList *captures = capture_list_pool_get(
@ -3278,6 +3278,7 @@ bool ts_query_cursor_next_capture(
}
if (state) {
if (state->id == UINT32_MAX) state->id = self->next_state_id++;
match->id = state->id;
match->pattern_index = state->pattern_index;
const CaptureList *captures = capture_list_pool_get(