Skip to content

workspace/applyEdit with versioned TextDocumentEdit is not always rejected when document version has advanced #1756

@LCamel

Description

@LCamel

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

  1. Open a plaintext file containing apple\nbanana
  2. 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)
  3. Immediately press Enter, advancing the document version before the edit arrives
  4. 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):

XXXXX

banana

The Enter arrives before the edit (edit rejected correctly due to version mismatch):


apple
banana

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:

XXXXX
apple
banana

Demonstration

https://www.youtube.com/watch?v=_zyFEwdu6OE

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions