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 a potential race between didChange and didOpen #13209

Merged
merged 4 commits into from
Jan 28, 2025

Conversation

Colengms
Copy link
Contributor

@Colengms Colengms commented Jan 28, 2025

Fixes a potential (probably rare?) issue where it's possible that a call to onDidChangeTextDocument might happen before a call to onDidOpenTextDocument, due to didOpen being delayed (processed by the protocol filter, after prior messages in queue). This could result the file's version in openFileVersions becoming incorrect (though would be corrected by subsequent edits).

onDidOpenTextDocument and onDidChangeTextDocument primarily maintain openFileVersions, and update UI state. This change calls onDidOpenTextDocument using a synchronous handler, instead of being processed by the protocol filter, ensuring no awaiting or prior queue work will delay it, similar to what we were already doing with onDidChangeTextDocument.

Having openFileVersions kept as closely in sync as possible with the editor ensures we properly discard results for operations that shouldn't be applied if the document has since changed.

@Colengms Colengms requested a review from a team as a code owner January 28, 2025 04:26
@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented Jan 28, 2025

This is for 1.24.0 or 1.23.5? i.e. should I cherry-pick it to the release branch?

@Colengms Colengms merged commit e3bb8a7 into main Jan 28, 2025
6 checks passed
@Colengms Colengms deleted the coleng/fix_didOpen_didChange_race branch January 28, 2025 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants