New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error causing tree-sitter highlighting to get out-of-sync when editing rapidly #18375

Merged
merged 2 commits into from Nov 3, 2018

Conversation

Projects
None yet
3 participants
@maxbrunsfeld
Contributor

maxbrunsfeld commented Oct 31, 2018

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 to Patch.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

  • Fixed an issue where making many rapid edits could cause incorrect syntax highlighting to be rendered.
@maxbrunsfeld

This comment has been minimized.

Contributor

maxbrunsfeld commented Oct 31, 2018

/cc @Ben3eeE - I think this may be contributing to #18342, though there might be other problems causing that.

@maxbrunsfeld

This comment has been minimized.

Contributor

maxbrunsfeld commented Nov 1, 2018

/cc @as-cii - I think this is the bug that you mentioned to me the other day. Gonna take your suggestion of using a randomized test to cover this.

@Ben3eeE

This comment has been minimized.

Member

Ben3eeE commented Nov 1, 2018

I was still able to reproduce the issue with syntax highlighting breaking and Atom freezing that I saw after building Atom on this commit.

I saw syntax highlighting break when pasting a 42 lines long erb file holding ctrl-v until it pasted to a couple of thousand lines.
I got atom to freeze by pasting a 7000 line erb file and undoing rapidly.

I send the files I used on Slack.

@maxbrunsfeld

This comment has been minimized.

Contributor

maxbrunsfeld commented Nov 1, 2018

I was still able to reproduce the issue with syntax highlighting breaking and Atom freezing that I saw after building Atom on this commit.

Ok, thanks for testing that. I think that there's a separate issue relating to ERB specifically. I'll do a little more testing to make sure that it is actually ERB-specific.

@as-cii

This comment has been minimized.

Member

as-cii commented Nov 2, 2018

I think this is the bug that you mentioned to me the other day.

Yes, it seems quite possible.

Gonna take your suggestion of using a randomized test to cover this.

Nice!

@Ben3eeE

This comment has been minimized.

Member

Ben3eeE commented Nov 2, 2018

@maxbrunsfeld Just wanna say I was able to reproduce the issue that this PR fixes to confirm the fix.

I could reproduce it by just typing fast at the top of text-editor-component. On this branch it did not reproduce again.

ERB files seem like a different issue 👍

@maxbrunsfeld maxbrunsfeld force-pushed the mb-highlighting-on-fast-edits branch from 8014e81 to 815cd2b Nov 3, 2018

@maxbrunsfeld maxbrunsfeld merged commit e0ace16 into master Nov 3, 2018

3 checks passed

Atom Pull Requests #20181103.2 succeeded
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@maxbrunsfeld maxbrunsfeld deleted the mb-highlighting-on-fast-edits branch Nov 3, 2018

maxbrunsfeld added a commit that referenced this pull request Nov 6, 2018

Merge pull request #18375 from atom/mb-highlighting-on-fast-edits
Fix error causing tree-sitter highlighting to get out-of-sync when editing rapidly

maxbrunsfeld added a commit that referenced this pull request Nov 6, 2018

Merge pull request #18375 from atom/mb-highlighting-on-fast-edits
Fix error causing tree-sitter highlighting to get out-of-sync when editing rapidly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment