diff options
| author | Yuan Fu | 2023-02-18 02:20:12 -0800 |
|---|---|---|
| committer | Yuan Fu | 2023-02-18 02:32:25 -0800 |
| commit | e985466556c71743ec9f47ee969bb4f45da141aa (patch) | |
| tree | 68a05c4c4126103bf91f6fee8a8dc9828db5f591 /src | |
| parent | 1e5cebc88bb5f028058e072071fee03529d0b204 (diff) | |
| download | emacs-e985466556c71743ec9f47ee969bb4f45da141aa.tar.gz emacs-e985466556c71743ec9f47ee969bb4f45da141aa.zip | |
Fix comment in treesit_record_change (bug#61369)
Turns out the previous commit message and comment is not entirely
correct: the old behavior is in fact wrong, not just "correct but has
problems".
Here is why the old code is wrong:
|visible range| -> markup for visible range
updated range -> markup for updated range
-------------
First we have some text
|aaaaaa|
Now we insert something at the beginning, because we clip
new_end_offset to visible_end, out of eight b's inserted, only the
first six are known to tree-sitter.
|bbbbbbbbaaaa|aa start: 0, old_end: 0, new_end: 6
------
In treesit_sync_visible_region, we sync up visible region, but the two
missing b's are not in the updated range.
|bbbbbbbbaaaaaa| start: 12, old_end: 12, new_end: 14
--
The old behavior not only is wrong, but also doesn't make much sense.
* src/treesit.c (treesit_record_change): Update comment.
Diffstat (limited to 'src')
| -rw-r--r-- | src/treesit.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/treesit.c b/src/treesit.c index e1d6f1ef79f..ef0f2407840 100644 --- a/src/treesit.c +++ b/src/treesit.c | |||
| @@ -797,12 +797,10 @@ treesit_record_change (ptrdiff_t start_byte, ptrdiff_t old_end_byte, | |||
| 797 | max (visible_beg, old_end_byte)) | 797 | max (visible_beg, old_end_byte)) |
| 798 | - visible_beg); | 798 | - visible_beg); |
| 799 | /* We don't clip new_end_offset under visible_end, because | 799 | /* We don't clip new_end_offset under visible_end, because |
| 800 | inserting in narrowed region always extends the visible | 800 | otherwise we would miss updating the clipped part. Plus, |
| 801 | region. If we clip new_end_offset here, and re-add the | 801 | when inserting in narrowed region, the narrowed region |
| 802 | clipped "tail" in treesit_sync_visible_region later, | 802 | will grow to accommodate the new text, so this is the |
| 803 | while it is technically equivalent, tree-sitter's | 803 | correct behavior. (Bug#61369). */ |
| 804 | incremental parsing algorithm doesn't seem to like it | ||
| 805 | (bug#61369). */ | ||
| 806 | ptrdiff_t new_end_offset = (max (visible_beg, new_end_byte) | 804 | ptrdiff_t new_end_offset = (max (visible_beg, new_end_byte) |
| 807 | - visible_beg); | 805 | - visible_beg); |
| 808 | eassert (start_offset <= old_end_offset); | 806 | eassert (start_offset <= old_end_offset); |