You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A resolved code action applies nothing when a file it edits is opened while the resolve is pending, though its text is unchanged #2282
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) {
returnLanguageServerBundle.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
Register UP89: LSP4IJ applies nothing of a resolved quick fix whose t…
Register UP89: LSP4IJ applies nothing of a resolved quick fix whose t…
fix: a resolved code action applies to a file opened while it was res…
Open a companion destination in IntelliJ's playbook after the quick f…
Open a companion destination in IntelliJ's playbook after the quick f…
Open a companion destination in IntelliJ's playbook after the quick f…
Register UP89: LSP4IJ applies nothing of a resolved quick fix whose t…
Open a companion destination in IntelliJ's playbook after the quick f…
Open a companion destination in IntelliJ's playbook after the quick f…
Register UP89: LSP4IJ applies nothing of a resolved quick fix whose t…
Open a companion destination in IntelliJ's playbook after the quick f…
Open a companion destination in IntelliJ's playbook after the quick f…
Open a companion destination in IntelliJ's playbook after the quick f…
Open a companion destination in IntelliJ's playbook after the quick f…
Open a companion destination in IntelliJ's playbook after the quick f…
Open a companion destination in IntelliJ's playbook after the quick f…