Summary
When a language server sends a workspace/applyEdit containing a versioned TextDocumentEdit, the client sometimes applies the edit even though the local document version has already advanced past the version specified in the edit.
Steps to Reproduce
A minimal reproduction is available at:
LCamel/vscode-extension-samples @ repro/versioned-edit-bug
- Open a plaintext file containing
apple\nbanana
- Press F11 — triggers a server-side
workspace/applyEdit with a versioned TextDocumentEdit (replace chars 0–5 with XXXXX, using the document version captured at request time)
- Immediately press Enter, advancing the document version before the edit arrives
- Repeat a few times
Expected Behavior
Either of these two outcomes is correct depending on timing:
The edit arrives before the Enter (edit applied correctly):
The Enter arrives before the edit (edit rejected correctly due to version mismatch):
Actual Behavior
The edit is intermittently applied in a way that produces an impossible document state — apple survives even though the edit was supposed to replace it:
Demonstration
https://www.youtube.com/watch?v=_zyFEwdu6OE
Summary
When a language server sends a
workspace/applyEditcontaining a versionedTextDocumentEdit, the client sometimes applies the edit even though the local document version has already advanced past the version specified in the edit.Steps to Reproduce
A minimal reproduction is available at:
LCamel/vscode-extension-samples @ repro/versioned-edit-bug
apple\nbananaworkspace/applyEditwith a versionedTextDocumentEdit(replace chars 0–5 withXXXXX, using the document version captured at request time)Expected Behavior
Either of these two outcomes is correct depending on timing:
The edit arrives before the Enter (edit applied correctly):
The Enter arrives before the edit (edit rejected correctly due to version mismatch):
Actual Behavior
The edit is intermittently applied in a way that produces an impossible document state —
applesurvives even though the edit was supposed to replace it:Demonstration
https://www.youtube.com/watch?v=_zyFEwdu6OE