Skip to content

A workspace edit applies to a target that was typed into and undone while its request was pending #2284

Done

Description

@lagergren

Found while fixing #2282.

What

WorkspaceEditSnapshot checks a target that the language server had open at capture by its document's modification stamp (WorkspaceEditSnapshot.java:229-231):

private record DocumentState(DocumentContentSynchronizer synchronizer, long modificationStamp, boolean textSent) {
    boolean matches(@Nullable DocumentContentSynchronizer current) {
        return current == synchronizer && synchronizer.getDocument().getModificationStamp() == modificationStamp;
    }
}

An undo puts back the document's earlier modification stamp (EditorChangeAction.undo, seen in the 2024.2 bytecode). So if the user types into a target while a rename, a codeAction/resolve or an incoming workspace/applyEdit is pending, and then undoes it, the stamp matches again and the edit is applied. Meanwhile the server was sent the typed text (didChange) and then the original text, and it may have computed its edit against the typed text.

When it can matter

All of these must hold, so it is rare:

  • the edit carries no version (a TextDocumentEdit with a version above 0 is still checked against the current version, which the two didChange have moved on);
  • the user types into the target, then undoes it, while the reply is pending;
  • the server computes its reply against the intermediate text.

The edit would then apply offsets of the typed text to the original text.

Suggested fix

Also record the synchronizer's version at capture, and require it to be unchanged. Every didChange raises it, an undo included. Alternatively, use the change sequence that #2283 adds (WorkspaceEditSnapshot.TextChanges), which already counts an undone change as a change.

Activity

  1. added
    bug
    on Nov 26, 2026
  2. added this to the 0.30.2 milestone on Nov 26, 2026
  3. added a commit that references this issue on Nov 26, 2026
    76a1a61
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions