fix document state getting out of sync in rare cases #2375
Merged
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.
I've reproduced a case where document state gets desynchronized on the LSP side. The issue seems to be only reproducible when there are at least two servers starting on a file (or maybe it just makes it more likely to happen). The easiest way to reproduce is to start ST, (re)open a file on which at least two servers will get started and start typing immediately. After undoing the changes LSP will show some stale errors.
Screen.Recording.2023-12-13.at.01.15.10.mov
This happened on opening the file. We have applied all latest changes through
didOpen
when the change count was, let's say, 1, but there was also already pending text change notification with a change count of 1 which we have applied again a little later.To fix, ignore text change notification that refer to current or old versions of the view since those are already applied/synced.
I was trying to think whether there is some deeper issue in the code that should be fixed instead but given how async tasks are scheduled, I don't think there is and it's just an expected case that we need to handle.