This repository was archived by the owner on Mar 3, 2023. It is now read-only.
Fix error causing tree-sitter highlighting to get out-of-sync when editing rapidly #18375
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Identify the Bug
When using Tree-sitter, it was previously possible to get the buffer and the syntax tree into an inconsistent state by making many rapid changes to the buffer.
See also:
Description of the Change
Whenever you make a change to a buffer that's using Tree-sitter, we start incrementally re-parsing the buffer. If that parse does not complete quickly, we allow it to finish parsing in the background. Then, if you make additional edits while that parse is still going, we need to store those edits so that we can apply them after-the-fact to the new syntax tree.
We store the edits in a
Patch
in order to group the changes efficiently. Unfortunately, the code that was mutating that patch was passing the wrong values toPatch.splice
. I'm not sure how this huge logic error didn't cause more problems than it did!Verification Process
The easiest way I found to reproduce the original bug was to open a large JavaScript file, place the cursor somewhere near the top of the file, and hold down
command-x
(Editor: Delete Line
). Previously, you would periodically get broken syntax highlighting.Now, with this change, I'm not seeing this problem.
Release Notes