Skip to content

fix(language-server): correctly calculate coalesced document change#240

Merged
johnsoncodehk merged 1 commit intovolarjs:masterfrom
rchl:fix/document-sync
Oct 7, 2024
Merged

fix(language-server): correctly calculate coalesced document change#240
johnsoncodehk merged 1 commit intovolarjs:masterfrom
rchl:fix/document-sync

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
@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