Repository navigation
fix: a resolved code action applies to a file opened while it was resolved, when the file's text is unchanged - #2283
Merged
lagergren merged 1 commit intoNov 26, 2026
Conversation
…olved, when the file's text is unchanged
A resolved code action, a rename reply and a workspace/applyEdit are checked
against a WorkspaceEditSnapshot, captured before the request, or on receipt
for applyEdit. The snapshot records only the documents that the server has
open at capture: the targets of a reply aren't known then. It refused the
whole edit for any target that the server had opened since, as it couldn't
tell an open that left the text as it was from one that changed it. Opening
a file in an editor while the resolve was pending was enough: nothing was
applied, and the editor showed "The document was opened after the edit was
requested".
Since the targets aren't known at capture, their state can't be recorded
then, and modification stamps can't be compared with the capture later: an
undo restores an earlier stamp. WorkspaceEditSnapshot.TextChanges, a
document listener and a VFS listener, marks a file with the next number of a
sequence after each change of its document, and after each VFS event that
changes, creates, copies, moves, renames or deletes it. A snapshot records
the sequence at capture.
A target that the server opened since capture is accepted only if its
document has no unsaved changes, so that its text is the file's, and neither
the file, its document, nor a directory that contains it was marked since
capture. Until the open the server could only read the file, and from the
open on it was sent the document, so both are the text the file had at
capture. A change that is undone still refuses the edit, since the server
may have been sent the changed text. A version in the edit is checked as for
a document open at capture: one above 0 must be current, and a placeholder
below 1 is accepted in a reply and refused in an incoming applyEdit.
Targets open at capture, and targets the server never opened, keep their
existing checks.
Tests:
- ResolvedCodeActionTest: a file opened in an editor, whose didOpen the
server receives, after the action is resolved and before its edit is
applied, gets the edit; typed in, it doesn't.
- RenameVersionTest: a file opened while the rename is pending gets the
reply's unversioned edit.
- WorkspaceEditSnapshotTest: a target opened since capture is accepted while
unchanged, for a reply and an incoming edit, with each kind of version; a
document loaded at capture is accepted when unchanged; refused when changed
and saved before the open, changed and restored after it, unsaved at
capture, changed on disk before its document was loaded, or moved there
with its directory. testTargetOpenedAfterRequestIsRefused, which refused an
unchanged target, is replaced.
Without the fix, the four tests that expect the edit applied fail, among them
ResolvedCodeActionTest's ("world" instead of "hello world"); the tests that
expect a refusal pass. Headless on 2024.2, the code action tests,
WorkspaceEditSnapshotTest, WorkspaceEditVersionTest and RenameVersionTest:
77 tests, 0 failures, 0 skipped.
Fixes redhat-developer#2282
This was referenced Nov 26, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2283 +/- ##
==========================================
+ Coverage 58.40% 58.41% +0.01%
==========================================
Files 846 846
Lines 36429 36455 +26
Branches 7537 7545 +8
==========================================
+ Hits 21275 21295 +20
- Misses 12153 12156 +3
- Partials 3001 3004 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Collaborator
Author
|
@coderabbitai review |
Action performed
|
This was referenced Nov 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A code action that is resolved after it is chosen applied nothing, and showed "The document was opened after the edit was requested", when a file its edit changes was opened while
codeAction/resolvewas pending, though opening it changed none of its text. Rename replies andworkspace/applyEdithad the same check.Cause
WorkspaceEditSnapshotrecords only the documents the server has open at capture, since a reply's targets aren't known then. It refused the whole edit for any target the server had opened since, because it couldn't tell an unchanged open from a changed one.Fix
The targets can't be recorded at capture, and modification stamps can't be compared with it later, since an undo restores an earlier stamp. Instead,
WorkspaceEditSnapshot.TextChangesmarks a file with the next number of a sequence after each change of its document, and after each VFS event that changes, creates, copies, moves, renames or deletes it. It does this as a document listener and as a VFS listener. A snapshot records the sequence at capture.A target the server opened since capture is accepted only if both hold:
Until the open, the server could only read the file, and from the open on it was sent the document, so both are the text the file had at capture. A change that is undone still refuses the edit. Versions are checked as for a document open at capture: one above 0 must be current, and a placeholder below 1 is accepted in a reply and refused in an incoming
applyEdit. Other targets keep their existing checks.The listeners cost one counter increment and one user-data write per document change or VFS batch.
didOpen) while the reply was pending, with its text unchangedTests
ResolvedCodeActionTest: a file opened in an editor after the action is resolved, before its edit is applied, gets the edit. Typed in, it doesn't.RenameVersionTest: a file opened while the rename is pending gets the reply's edit.WorkspaceEditSnapshotTest: acceptance for a reply and for an incoming edit, with each kind of version; a document loaded at the request; a refusal for each kind of change.The four tests that expect the edit to be applied fail without the fix. The refusal tests pass either way. On 2024.2, the code action, rename and workspace edit tests pass (77 tests); CI runs them on all three platforms.
Not covered end to end: an incoming
workspace/applyEdit. Between its receipt and its validation there is a singleinvokeLater, and no deterministic way was found to open a file in between. It sharesvalidatewith rename and code actions.Fixes #2282