2017-08-04 11:03:14 -07:00
|
|
|
#include "runtime/get_changed_ranges.h"
|
2018-05-10 15:11:14 -07:00
|
|
|
#include "runtime/subtree.h"
|
2017-07-17 17:07:56 -07:00
|
|
|
#include "runtime/language.h"
|
2016-10-16 21:10:25 -07:00
|
|
|
#include "runtime/error_costs.h"
|
2018-05-09 16:38:56 -07:00
|
|
|
#include "runtime/tree_cursor.h"
|
2017-08-07 10:35:06 -07:00
|
|
|
#include <assert.h>
|
2016-10-16 20:42:55 -07:00
|
|
|
|
2017-12-29 18:01:42 -08:00
|
|
|
// #define DEBUG_GET_CHANGED_RANGES
|
|
|
|
|
|
2016-10-16 20:42:55 -07:00
|
|
|
typedef Array(TSRange) RangeArray;
|
|
|
|
|
|
2018-06-20 11:46:44 -07:00
|
|
|
static void range_array_add(RangeArray *results, Length start, Length end) {
|
2016-10-16 20:42:55 -07:00
|
|
|
if (results->size > 0) {
|
|
|
|
|
TSRange *last_range = array_back(results);
|
2018-06-20 11:46:44 -07:00
|
|
|
if (start.bytes <= last_range->end_byte) {
|
|
|
|
|
last_range->end_byte = end.bytes;
|
|
|
|
|
last_range->end_point = end.extent;
|
2016-11-04 09:18:38 -07:00
|
|
|
return;
|
2016-10-16 20:42:55 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-20 11:46:44 -07:00
|
|
|
if (start.bytes < end.bytes) {
|
|
|
|
|
TSRange range = { start.extent, end.extent, start.bytes, end.bytes };
|
2016-11-04 09:18:38 -07:00
|
|
|
array_push(results, range);
|
2016-10-16 20:42:55 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-04 14:50:50 -07:00
|
|
|
typedef struct {
|
2018-05-16 16:05:08 -07:00
|
|
|
TreeCursor cursor;
|
2017-08-04 14:50:50 -07:00
|
|
|
const TSLanguage *language;
|
|
|
|
|
unsigned visible_depth;
|
2017-08-06 17:16:29 -07:00
|
|
|
bool in_padding;
|
2017-08-04 14:50:50 -07:00
|
|
|
} Iterator;
|
|
|
|
|
|
2018-05-16 16:05:08 -07:00
|
|
|
static Iterator iterator_new(TreeCursor *cursor, const Subtree *tree, const TSLanguage *language) {
|
2018-05-09 16:38:56 -07:00
|
|
|
array_clear(&cursor->stack);
|
|
|
|
|
array_push(&cursor->stack, ((TreeCursorEntry){
|
2018-05-10 22:22:37 -07:00
|
|
|
.subtree = tree,
|
2017-08-06 17:16:29 -07:00
|
|
|
.position = length_zero(),
|
2017-08-05 20:33:38 -07:00
|
|
|
.child_index = 0,
|
|
|
|
|
.structural_child_index = 0,
|
|
|
|
|
}));
|
|
|
|
|
return (Iterator) {
|
2018-05-09 16:38:56 -07:00
|
|
|
.cursor = *cursor,
|
2017-08-05 20:33:38 -07:00
|
|
|
.language = language,
|
|
|
|
|
.visible_depth = 1,
|
2017-08-06 17:16:29 -07:00
|
|
|
.in_padding = false,
|
2017-08-05 20:33:38 -07:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-06 17:16:29 -07:00
|
|
|
static bool iterator_done(Iterator *self) {
|
2018-05-09 16:38:56 -07:00
|
|
|
return self->cursor.stack.size == 0;
|
2017-08-06 17:16:29 -07:00
|
|
|
}
|
|
|
|
|
|
2017-08-05 20:33:38 -07:00
|
|
|
Length iterator_start_position(Iterator *self) {
|
2018-05-09 16:38:56 -07:00
|
|
|
TreeCursorEntry entry = *array_back(&self->cursor.stack);
|
2017-08-06 17:16:29 -07:00
|
|
|
if (self->in_padding) {
|
|
|
|
|
return entry.position;
|
|
|
|
|
} else {
|
2018-09-17 13:12:13 -07:00
|
|
|
return length_add(entry.position, ts_subtree_padding(*entry.subtree));
|
2017-08-06 17:16:29 -07:00
|
|
|
}
|
2017-08-05 20:33:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Length iterator_end_position(Iterator *self) {
|
2018-05-09 16:38:56 -07:00
|
|
|
TreeCursorEntry entry = *array_back(&self->cursor.stack);
|
2018-09-17 13:12:13 -07:00
|
|
|
Length result = length_add(entry.position, ts_subtree_padding(*entry.subtree));
|
2017-08-06 17:16:29 -07:00
|
|
|
if (self->in_padding) {
|
|
|
|
|
return result;
|
|
|
|
|
} else {
|
2018-09-17 13:12:13 -07:00
|
|
|
return length_add(result, ts_subtree_size(*entry.subtree));
|
2017-08-06 17:16:29 -07:00
|
|
|
}
|
2017-08-05 20:33:38 -07:00
|
|
|
}
|
|
|
|
|
|
2017-08-04 14:03:41 -07:00
|
|
|
static bool iterator_tree_is_visible(const Iterator *self) {
|
2018-05-09 16:38:56 -07:00
|
|
|
TreeCursorEntry entry = *array_back(&self->cursor.stack);
|
2018-09-17 13:12:13 -07:00
|
|
|
if (ts_subtree_visible(*entry.subtree)) return true;
|
2018-05-09 16:38:56 -07:00
|
|
|
if (self->cursor.stack.size > 1) {
|
2018-09-17 13:12:13 -07:00
|
|
|
Subtree parent = *self->cursor.stack.contents[self->cursor.stack.size - 2].subtree;
|
|
|
|
|
const TSSymbol *alias_sequence = ts_language_alias_sequence(
|
|
|
|
|
self->language,
|
|
|
|
|
parent.ptr->alias_sequence_id
|
|
|
|
|
);
|
2017-08-04 14:03:41 -07:00
|
|
|
return alias_sequence && alias_sequence[entry.structural_child_index] != 0;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-08-04 11:03:14 -07:00
|
|
|
|
2018-09-17 13:12:13 -07:00
|
|
|
static void iterator_get_visible_state(const Iterator *self, Subtree *tree,
|
2017-08-06 17:16:29 -07:00
|
|
|
TSSymbol *alias_symbol, uint32_t *start_byte) {
|
2018-05-09 16:38:56 -07:00
|
|
|
uint32_t i = self->cursor.stack.size - 1;
|
2017-08-04 11:03:14 -07:00
|
|
|
|
2017-08-06 17:16:29 -07:00
|
|
|
if (self->in_padding) {
|
2017-12-29 18:02:06 -08:00
|
|
|
if (i == 0) return;
|
|
|
|
|
i--;
|
2017-08-06 17:16:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (; i + 1 > 0; i--) {
|
2018-05-09 16:38:56 -07:00
|
|
|
TreeCursorEntry entry = self->cursor.stack.contents[i];
|
2017-08-06 17:16:29 -07:00
|
|
|
|
|
|
|
|
if (i > 0) {
|
2018-05-11 15:06:13 -07:00
|
|
|
const Subtree *parent = self->cursor.stack.contents[i - 1].subtree;
|
2017-08-06 17:16:29 -07:00
|
|
|
const TSSymbol *alias_sequence = ts_language_alias_sequence(
|
|
|
|
|
self->language,
|
2018-09-17 13:12:13 -07:00
|
|
|
parent->ptr->alias_sequence_id
|
2017-08-06 17:16:29 -07:00
|
|
|
);
|
|
|
|
|
if (alias_sequence) {
|
|
|
|
|
*alias_symbol = alias_sequence[entry.structural_child_index];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-17 13:12:13 -07:00
|
|
|
if (ts_subtree_visible(*entry.subtree) || *alias_symbol) {
|
|
|
|
|
*tree = *entry.subtree;
|
2017-08-06 17:16:29 -07:00
|
|
|
*start_byte = entry.position.bytes;
|
|
|
|
|
break;
|
2017-08-04 11:03:14 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-06 17:16:29 -07:00
|
|
|
static void iterator_ascend(Iterator *self) {
|
|
|
|
|
if (iterator_done(self)) return;
|
|
|
|
|
if (iterator_tree_is_visible(self) && !self->in_padding) self->visible_depth--;
|
2018-05-09 16:38:56 -07:00
|
|
|
if (array_back(&self->cursor.stack)->child_index > 0) self->in_padding = false;
|
|
|
|
|
self->cursor.stack.size--;
|
2017-08-06 17:16:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool iterator_descend(Iterator *self, uint32_t goal_position) {
|
|
|
|
|
if (self->in_padding) return false;
|
2017-01-24 12:48:47 -08:00
|
|
|
|
2016-10-16 20:42:55 -07:00
|
|
|
bool did_descend;
|
|
|
|
|
do {
|
|
|
|
|
did_descend = false;
|
2018-05-09 16:38:56 -07:00
|
|
|
TreeCursorEntry entry = *array_back(&self->cursor.stack);
|
2017-08-06 17:16:29 -07:00
|
|
|
Length position = entry.position;
|
2017-08-04 11:03:14 -07:00
|
|
|
uint32_t structural_child_index = 0;
|
2018-09-17 13:12:13 -07:00
|
|
|
for (uint32_t i = 0, n = ts_subtree_child_count(*entry.subtree); i < n; i++) {
|
|
|
|
|
const Subtree *child = &entry.subtree->ptr->children[i];
|
|
|
|
|
Length child_left = length_add(position, ts_subtree_padding(*child));
|
|
|
|
|
Length child_right = length_add(child_left, ts_subtree_size(*child));
|
2017-08-04 14:03:41 -07:00
|
|
|
|
2017-08-06 17:16:29 -07:00
|
|
|
if (child_right.bytes > goal_position) {
|
2018-05-09 16:38:56 -07:00
|
|
|
array_push(&self->cursor.stack, ((TreeCursorEntry){
|
2018-05-10 22:22:37 -07:00
|
|
|
.subtree = child,
|
2017-08-06 17:16:29 -07:00
|
|
|
.position = position,
|
2017-08-04 11:03:14 -07:00
|
|
|
.child_index = i,
|
|
|
|
|
.structural_child_index = structural_child_index,
|
2017-08-04 14:03:41 -07:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
if (iterator_tree_is_visible(self)) {
|
2017-08-06 17:16:29 -07:00
|
|
|
if (child_left.bytes > goal_position) {
|
|
|
|
|
self->in_padding = true;
|
|
|
|
|
} else {
|
|
|
|
|
self->visible_depth++;
|
|
|
|
|
}
|
2016-10-16 20:42:55 -07:00
|
|
|
return true;
|
2017-08-04 11:03:14 -07:00
|
|
|
}
|
2017-08-04 14:03:41 -07:00
|
|
|
|
2017-08-06 17:16:29 -07:00
|
|
|
did_descend = true;
|
|
|
|
|
break;
|
2016-10-16 20:42:55 -07:00
|
|
|
}
|
2017-08-04 14:03:41 -07:00
|
|
|
|
2017-08-06 17:16:29 -07:00
|
|
|
position = child_right;
|
2018-09-17 13:12:13 -07:00
|
|
|
if (!ts_subtree_extra(*child)) structural_child_index++;
|
2016-10-16 20:42:55 -07:00
|
|
|
}
|
|
|
|
|
} while (did_descend);
|
2017-01-24 12:48:47 -08:00
|
|
|
|
2016-10-16 20:42:55 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-06 17:16:29 -07:00
|
|
|
static void iterator_advance(Iterator *self) {
|
|
|
|
|
if (self->in_padding) {
|
|
|
|
|
self->in_padding = false;
|
|
|
|
|
if (iterator_tree_is_visible(self)) {
|
|
|
|
|
self->visible_depth++;
|
|
|
|
|
} else {
|
|
|
|
|
iterator_descend(self, 0);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-01-24 12:48:47 -08:00
|
|
|
|
2017-08-04 14:03:41 -07:00
|
|
|
for (;;) {
|
|
|
|
|
if (iterator_tree_is_visible(self)) self->visible_depth--;
|
2018-05-09 16:38:56 -07:00
|
|
|
TreeCursorEntry entry = array_pop(&self->cursor.stack);
|
2017-08-06 17:16:29 -07:00
|
|
|
if (iterator_done(self)) return;
|
2017-01-24 12:48:47 -08:00
|
|
|
|
2018-05-11 15:06:13 -07:00
|
|
|
const Subtree *parent = array_back(&self->cursor.stack)->subtree;
|
2017-08-06 17:16:29 -07:00
|
|
|
uint32_t child_index = entry.child_index + 1;
|
2018-09-17 13:12:13 -07:00
|
|
|
if (ts_subtree_child_count(*parent) > child_index) {
|
|
|
|
|
Length position = length_add(entry.position, ts_subtree_total_size(*entry.subtree));
|
2017-08-06 17:16:29 -07:00
|
|
|
uint32_t structural_child_index = entry.structural_child_index;
|
2018-09-17 13:12:13 -07:00
|
|
|
if (!ts_subtree_extra(*entry.subtree)) structural_child_index++;
|
|
|
|
|
const Subtree *next_child = &parent->ptr->children[child_index];
|
2017-08-04 11:03:14 -07:00
|
|
|
|
2018-05-09 16:38:56 -07:00
|
|
|
array_push(&self->cursor.stack, ((TreeCursorEntry){
|
2018-05-10 22:22:37 -07:00
|
|
|
.subtree = next_child,
|
2017-08-04 14:03:41 -07:00
|
|
|
.position = position,
|
2017-08-06 17:16:29 -07:00
|
|
|
.child_index = child_index,
|
2017-08-04 14:03:41 -07:00
|
|
|
.structural_child_index = structural_child_index,
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
if (iterator_tree_is_visible(self)) {
|
2018-09-17 13:12:13 -07:00
|
|
|
if (ts_subtree_padding(*next_child).bytes > 0) {
|
2017-08-06 17:16:29 -07:00
|
|
|
self->in_padding = true;
|
|
|
|
|
} else {
|
|
|
|
|
self->visible_depth++;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
iterator_descend(self, 0);
|
2017-08-04 14:03:41 -07:00
|
|
|
}
|
2017-08-06 17:16:29 -07:00
|
|
|
break;
|
2016-10-16 20:42:55 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-17 17:07:56 -07:00
|
|
|
typedef enum {
|
2017-08-04 14:03:41 -07:00
|
|
|
IteratorDiffers,
|
|
|
|
|
IteratorMayDiffer,
|
|
|
|
|
IteratorMatches,
|
|
|
|
|
} IteratorComparison;
|
|
|
|
|
|
2017-08-06 17:16:29 -07:00
|
|
|
IteratorComparison iterator_compare(const Iterator *old_iter, const Iterator *new_iter) {
|
2018-09-17 22:24:37 -07:00
|
|
|
Subtree old_tree = NULL_SUBTREE, new_tree = NULL_SUBTREE;
|
2017-08-07 10:35:06 -07:00
|
|
|
uint32_t old_start = 0, new_start = 0;
|
|
|
|
|
TSSymbol old_alias_symbol = 0, new_alias_symbol = 0;
|
2017-08-06 17:16:29 -07:00
|
|
|
iterator_get_visible_state(old_iter, &old_tree, &old_alias_symbol, &old_start);
|
|
|
|
|
iterator_get_visible_state(new_iter, &new_tree, &new_alias_symbol, &new_start);
|
2017-07-17 17:07:56 -07:00
|
|
|
|
2018-09-17 13:12:13 -07:00
|
|
|
if (!old_tree.ptr && !new_tree.ptr) return IteratorMatches;
|
|
|
|
|
if (!old_tree.ptr || !new_tree.ptr) return IteratorDiffers;
|
2017-08-07 10:35:06 -07:00
|
|
|
|
2017-07-31 11:45:24 -07:00
|
|
|
if (old_alias_symbol == new_alias_symbol) {
|
2017-08-06 17:16:29 -07:00
|
|
|
if (old_start == new_start) {
|
2018-09-17 13:12:13 -07:00
|
|
|
if (!ts_subtree_has_changes(old_tree) &&
|
|
|
|
|
ts_subtree_symbol(old_tree) == ts_subtree_symbol(new_tree) &&
|
|
|
|
|
ts_subtree_symbol(old_tree) != ts_builtin_sym_error &&
|
|
|
|
|
ts_subtree_size(old_tree).bytes == ts_subtree_size(new_tree).bytes &&
|
|
|
|
|
ts_subtree_parse_state(old_tree) != TS_TREE_STATE_NONE &&
|
|
|
|
|
ts_subtree_parse_state(new_tree) != TS_TREE_STATE_NONE &&
|
|
|
|
|
(ts_subtree_parse_state(old_tree) == ERROR_STATE) ==
|
|
|
|
|
(ts_subtree_parse_state(new_tree) == ERROR_STATE)) {
|
2017-08-04 14:03:41 -07:00
|
|
|
return IteratorMatches;
|
2017-07-17 17:07:56 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-17 13:12:13 -07:00
|
|
|
if (ts_subtree_symbol(old_tree) == ts_subtree_symbol(new_tree)) {
|
2017-08-04 14:03:41 -07:00
|
|
|
return IteratorMayDiffer;
|
2017-07-17 17:07:56 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-04 14:03:41 -07:00
|
|
|
return IteratorDiffers;
|
2016-10-16 20:42:55 -07:00
|
|
|
}
|
|
|
|
|
|
2017-12-29 18:01:42 -08:00
|
|
|
#ifdef DEBUG_GET_CHANGED_RANGES
|
|
|
|
|
static inline void iterator_print_state(Iterator *self) {
|
2018-05-09 16:38:56 -07:00
|
|
|
TreeCursorEntry entry = *array_back(&self->cursor.stack);
|
2017-12-29 18:01:42 -08:00
|
|
|
TSPoint start = iterator_start_position(self).extent;
|
|
|
|
|
TSPoint end = iterator_end_position(self).extent;
|
2018-05-10 22:22:37 -07:00
|
|
|
const char *name = ts_language_symbol_name(self->language, entry.subtree->symbol);
|
2017-12-29 18:01:42 -08:00
|
|
|
printf(
|
|
|
|
|
"(%-25s %s\t depth:%u [%u, %u] - [%u, %u])",
|
|
|
|
|
name, self->in_padding ? "(p)" : " ",
|
|
|
|
|
self->visible_depth,
|
|
|
|
|
start.row, start.column,
|
|
|
|
|
end.row, end.column
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2017-08-06 17:16:29 -07:00
|
|
|
|
2018-05-11 15:06:13 -07:00
|
|
|
unsigned ts_subtree_get_changed_ranges(const Subtree *old_tree, const Subtree *new_tree,
|
2018-05-16 16:05:08 -07:00
|
|
|
TreeCursor *cursor1, TreeCursor *cursor2,
|
2018-05-11 15:06:13 -07:00
|
|
|
const TSLanguage *language, TSRange **ranges) {
|
2017-08-06 17:16:29 -07:00
|
|
|
RangeArray results = array_new();
|
|
|
|
|
|
2018-05-09 16:38:56 -07:00
|
|
|
Iterator old_iter = iterator_new(cursor1, old_tree, language);
|
|
|
|
|
Iterator new_iter = iterator_new(cursor2, new_tree, language);
|
2016-10-16 20:42:55 -07:00
|
|
|
|
2017-08-06 17:16:29 -07:00
|
|
|
Length position = iterator_start_position(&old_iter);
|
|
|
|
|
Length next_position = iterator_start_position(&new_iter);
|
|
|
|
|
if (position.bytes < next_position.bytes) {
|
2018-06-20 11:46:44 -07:00
|
|
|
range_array_add(&results, position, next_position);
|
2017-08-06 17:16:29 -07:00
|
|
|
position = next_position;
|
|
|
|
|
} else if (position.bytes > next_position.bytes) {
|
2018-06-20 11:46:44 -07:00
|
|
|
range_array_add(&results, next_position, position);
|
2017-08-06 17:16:29 -07:00
|
|
|
next_position = position;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do {
|
2017-12-29 18:01:42 -08:00
|
|
|
#ifdef DEBUG_GET_CHANGED_RANGES
|
|
|
|
|
printf("At [%-2u, %-2u] Compare ", position.extent.row, position.extent.column);
|
|
|
|
|
iterator_print_state(&old_iter);
|
|
|
|
|
printf("\tvs\t");
|
|
|
|
|
iterator_print_state(&new_iter);
|
|
|
|
|
puts("");
|
|
|
|
|
#endif
|
2017-08-06 17:16:29 -07:00
|
|
|
|
2016-10-16 20:42:55 -07:00
|
|
|
bool is_changed = false;
|
2017-08-06 17:16:29 -07:00
|
|
|
switch (iterator_compare(&old_iter, &new_iter)) {
|
|
|
|
|
case IteratorMatches:
|
|
|
|
|
next_position = iterator_end_position(&old_iter);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case IteratorMayDiffer:
|
|
|
|
|
if (iterator_descend(&old_iter, position.bytes)) {
|
|
|
|
|
if (!iterator_descend(&new_iter, position.bytes)) {
|
2017-07-17 17:07:56 -07:00
|
|
|
is_changed = true;
|
2017-08-06 17:16:29 -07:00
|
|
|
next_position = iterator_end_position(&old_iter);
|
2017-07-17 17:07:56 -07:00
|
|
|
}
|
2017-08-06 17:16:29 -07:00
|
|
|
} else if (iterator_descend(&new_iter, position.bytes)) {
|
2017-08-04 14:50:50 -07:00
|
|
|
is_changed = true;
|
2017-08-06 17:16:29 -07:00
|
|
|
next_position = iterator_end_position(&new_iter);
|
|
|
|
|
} else {
|
|
|
|
|
next_position = length_min(
|
|
|
|
|
iterator_end_position(&old_iter),
|
|
|
|
|
iterator_end_position(&new_iter)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2016-10-16 20:42:55 -07:00
|
|
|
|
2017-08-06 17:16:29 -07:00
|
|
|
case IteratorDiffers:
|
|
|
|
|
is_changed = true;
|
|
|
|
|
next_position = length_min(
|
|
|
|
|
iterator_end_position(&old_iter),
|
|
|
|
|
iterator_end_position(&new_iter)
|
|
|
|
|
);
|
|
|
|
|
break;
|
2017-08-04 14:50:50 -07:00
|
|
|
}
|
|
|
|
|
|
2017-08-06 17:16:29 -07:00
|
|
|
while (
|
|
|
|
|
!iterator_done(&old_iter) &&
|
|
|
|
|
iterator_end_position(&old_iter).bytes <= next_position.bytes
|
|
|
|
|
) iterator_advance(&old_iter);
|
2017-08-04 14:50:50 -07:00
|
|
|
|
2017-08-06 17:16:29 -07:00
|
|
|
while (
|
|
|
|
|
!iterator_done(&new_iter) &&
|
|
|
|
|
iterator_end_position(&new_iter).bytes <= next_position.bytes
|
|
|
|
|
) iterator_advance(&new_iter);
|
2017-08-04 14:50:50 -07:00
|
|
|
|
2017-08-06 17:16:29 -07:00
|
|
|
while (old_iter.visible_depth > new_iter.visible_depth) iterator_ascend(&old_iter);
|
|
|
|
|
|
|
|
|
|
while (new_iter.visible_depth > old_iter.visible_depth) iterator_ascend(&new_iter);
|
2016-10-16 20:42:55 -07:00
|
|
|
|
2017-08-04 11:03:14 -07:00
|
|
|
if (is_changed) {
|
2017-12-29 18:01:42 -08:00
|
|
|
#ifdef DEBUG_GET_CHANGED_RANGES
|
|
|
|
|
printf(
|
|
|
|
|
" change: [[%u, %u] - [%u, %u]]\n",
|
|
|
|
|
position.extent.row, position.extent.column,
|
|
|
|
|
next_position.extent.row, next_position.extent.column
|
|
|
|
|
);
|
|
|
|
|
#endif
|
2017-08-04 14:50:50 -07:00
|
|
|
|
2018-06-20 11:46:44 -07:00
|
|
|
range_array_add(&results, position, next_position);
|
2017-08-04 11:03:14 -07:00
|
|
|
}
|
2017-08-04 14:03:41 -07:00
|
|
|
|
2016-10-16 20:42:55 -07:00
|
|
|
position = next_position;
|
2017-08-06 17:16:29 -07:00
|
|
|
} while (!iterator_done(&old_iter) && !iterator_done(&new_iter));
|
2016-10-16 20:42:55 -07:00
|
|
|
|
2018-05-09 16:38:56 -07:00
|
|
|
*cursor1 = old_iter.cursor;
|
|
|
|
|
*cursor2 = new_iter.cursor;
|
2016-10-16 20:42:55 -07:00
|
|
|
*ranges = results.contents;
|
2017-08-04 11:03:14 -07:00
|
|
|
return results.size;
|
2016-10-16 20:42:55 -07:00
|
|
|
}
|