Skip to content

A resolved code action applies nothing when a file it edits is opened while the resolve is pending, though its text is unchanged #2282

Done

Description

@lagergren

Summary

A code action that is resolved after it is chosen applies nothing, and shows "The document was opened after the edit was requested", when one of the files its edit changes is opened while the codeAction/resolve request is pending. This happens even though opening the file changed none of its text, and the server computed the edit from that text.

Seen with 0.30.1, and the code is unchanged on main (5e4c130d).

Cause

LSPLazyCodeActionIntentionAction captures a WorkspaceEditSnapshot before it sends the resolve, and applyResolved validates the resolved edit against it. The snapshot records only the documents that the language server has open at capture. For any other target, validate refuses the whole edit as soon as the server has opened that document since:

// Without a captured state, a document this server opened since has no request-time stamp.
if (state == null && synchronizer != null) {
    return LanguageServerBundle.message("lsp.workspace.edit.document.opened", uriString);
}

Opening a file in an editor is enough to make the server open its document. Without a captured stamp, the check can't tell an open that left the text as it was from one that changed it, so it refuses both. The same check applies to rename replies and workspace/applyEdit.

How it shows

A quick fix that creates a method in another class, Other.x, with an import in a third file. Neither target is open when the fix is chosen. The user, or here an automated UI test, opens Other.x right after choosing the fix. The language server's trace has codeAction/resolve received at .449, textDocument/didOpen of Other.x at .490, and the resolve's reply, with the correct edit, at .489. Nothing is applied to either file, and the editor shows the error hint.

The window is the resolve's round trip, so a user rarely hits it. A test that opens the destination file to check the result hits it whenever the reply is slower than the open.

Fix

For a target that the server doesn't have open at capture, also record IntelliJ's state of its document: whether a document is loaded (FileDocumentManager.getCachedDocument) and its modification stamp. In validate, accept a document that the server opened since when its stamp is unchanged, or, when it wasn't loaded at capture, when it has not been modified since it was loaded. Refuse it only when its text may have changed.

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
    0bd5652
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