fix(language-server): correctly calculate coalesced document change #240
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.
fixes vuejs/language-tools#4909
calculateChangeRange
was incorrectly calculating combined change if the document update contained multiple changes. It calculated offset for each change using the original state of the document as a base while the offsets for the next change need to be calculated based on a document state with previous change applied.I'm guessing that vscode coalesced changes so generally there was just a single one and the issue was never apparent there but with other editors there is no such guarantee.
To fix I've dropped the incorrect code and instead switched to converting changes to
ts.TextChangeRange
s and using existingcombineChangeRanges
utility function that seems to be doing the right thing.Calculating incorrect range for the snapshot resulted in incorrectly applying changes to the SFC, causing the generated document to end up with pretty much random content and causing random issues with different features.