Skip to content
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(language-server): correctly calculate coalesced document change #240

Merged
merged 1 commit into from
Oct 7, 2024

Conversation

rchl
Copy link
Contributor

@rchl rchl commented Oct 6, 2024

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.TextChangeRanges and using existing combineChangeRanges 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.

@johnsoncodehk
Copy link
Member

Your method is simpler, thank you!

@johnsoncodehk johnsoncodehk merged commit 4733999 into volarjs:master Oct 7, 2024
0 of 4 checks passed
@rchl rchl deleted the fix/document-sync branch October 7, 2024 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Changing vue files causes internal state to desync in Sublime Text
2 participants