Skip to content

fix: apply the will* edit to a loaded document that the server hasn't opened - #2137

Merged
lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/apply-will-file-edits-to-unopened-documents
Nov 23, 2026
Merged

lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/apply-will-file-edits-to-unopened-documents

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

Fixes #2135

What

A rename or move made in the IDE dropped the server's workspace/willRenameFiles edit whenever the edit changed a file that IntelliJ had loaded but the server hadn't opened. It logged Discarding stale workspace/will* edit: target document(s) modified during request, though no document had changed. The file was renamed, and its references in the other files kept the old name.

Cause

  • AbstractLSPFileListener.captureDocumentStamps() records a stamp only for the documents that the server has open.
  • isDocumentStale treated a target document without a recorded stamp, but with a cached document, as stale.

A file that isn't open in an editor still has a cached document once anything has loaded it, such as an editor opened and closed before, or Find Usages. So the edit was dropped for exactly the files that a rename's edit is usually for.

Change

isDocumentStale treats a document without a recorded stamp as stale only if it has unsaved changes (FileDocumentManager.isDocumentUnsaved):

  • The server didn't have that document open, so its edit is based on the file on disk.
  • The document matches the file on disk unless it has unsaved changes.

The recorded stamps still decide for the documents that the server has open. Both paths use the check: the requests sent before a refactoring's write action (#1755), and those sent from the VFS listener.

Behavior changes

Not changed

A document that the server hadn't opened, and that changes and is saved again while the request is out, still gets the edit: its document again matches the file on disk. Closing that gap would mean recording the documents that the server hasn't opened as well.

Test

New tests:

  • FileOperationRefactoringTest.testRenameRefactoringAppliesTheEditToALoadedDocumentThatTheServerHasNotOpened loads the other file's document, then renames a file with RenameProcessor.
  • FileOperationEditSaveTest.testWillRenameEditToALoadedDocumentThatTheServerHasNotOpenedIsApplied does the same with a VFS rename, and checks that the edit is saved.

On main both fail: the edit is dropped, and the other file keeps its text.

2024.2 2025.3 IU 2026.3
The two new tests and testUntrackedDocumentWithoutUnsavedChangesIsNotStale on main fail fail fail
FileOperation*, FileRenameUriTest, FileDocumentMoveTest and features.files.* with the change 114 pass 114 pass 114 pass
Full suite with the change 1997 tests, 0 failures, 7 skipped

@lagergren lagergren added bug Something isn't working rename refactoring labels Nov 23, 2026
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • File rename and refactoring edits now apply correctly to documents loaded in the editor even if they have not been opened by the language server.
    • Edits to documents without a captured change record are no longer incorrectly treated as stale when there are no unsaved changes. Documents with unsaved changes continue to be protected from stale edits.

The stale-edit check now marks a document without a captured modification stamp as stale only when it has unsaved changes. Tests cover this condition and willRenameFiles edits to documents loaded by IntelliJ but not opened by the language server.

Changes: Rename edit staleness

Layer / File(s) Summary
Stale check and file-operation validation
src/main/java/com/redhat/devtools/lsp4ij/features/files/AbstractLSPFileListener.java, src/test/java/com/redhat/devtools/lsp4ij/features/files/DocumentStampValidationTest.java, src/test/java/com/redhat/devtools/lsp4ij/FileOperationRefactoringTest.java, src/test/java/com/redhat/devtools/lsp4ij/FileOperationEditSaveTest.java
For documents without a captured stamp, the stale check now depends on whether the document has unsaved changes. Tests cover both stale-check outcomes and rename edits to loaded documents that the server has not opened.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: angelozerr

Merge Risk: Low · up to fb5ec

Renames and moves now apply a language server's edit to files that IntelliJ has loaded but the server has not opened. The only remaining exposure is a narrow, documented race: if such a file is changed and saved while the request is still pending, the edit can be applied to the changed text. This is acceptable for merge with owner awareness.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: a will* edit is now applied to a loaded document that the language server has not opened. The objectives and raw summary confirm that the stale-document check for unt…
Description check Passed The description explains what is broken (willRenameFiles edits dropped for loaded but unopened files), the cause (stamps recorded only for open documents, untracked cached documents treated as stale),…
Linked Issues check Passed Issue #2135 requires that an edit to a document IntelliJ has loaded, but the server has not opened, is applied when the document matches the file on disk. The suggested fix is to treat an untracked do…
Out of Scope Changes check Passed All changes support the issue objective. The isDocumentStale rule change is the requested fix. The new FileOperationRefactoringTest and FileOperationEditSaveTest tests exercise the RenameProcessor and…
Full details: Title check

Explanation

The title states the main change: a will* edit is now applied to a loaded document that the language server has not opened. The objectives and raw summary confirm that the stale-document check for untracked documents was changed to use unsaved-changes status. The title is accurate and specific.

Full details: Description check

Explanation

The description explains what is broken (willRenameFiles edits dropped for loaded but unopened files), the cause (stamps recorded only for open documents, untracked cached documents treated as stale), the change (stale only if isDocumentUnsaved), behavior changes, a stated limitation, and the new tests. It is related to the changeset.

Full details: Linked Issues check

Explanation

Issue #2135 requires that an edit to a document IntelliJ has loaded, but the server has not opened, is applied when the document matches the file on disk. The suggested fix is to treat an untracked document as stale only when it has unsaved changes, while recorded stamps still govern open documents. The PR description and the change summary report this exact rule in isDocumentStale (AbstractLSPFileListener.java, +3/-3). It applies to both the pre-write-action path (#1755) and the VFS listener path. Tests cover the behavior: FileOperationRefactoringTest.testRenameRefactoringAppliesTheEditToALoadedDocumentThatTheServerHasNotOpened, FileOperationEditSaveTest.testWillRenameEditToALoadedDocumentThatTheServerHasNotOpenedIsApplied, and DocumentStampValidationTest.testUntrackedDocumentWithoutUnsavedChangesIsNotStale. The old testNewlyOpenedDocumentIsStale is replaced by the two DocumentStampValidationTest tests, which match the new rule. The PR reports the new tests fail on main. The raw code read of isDocumentStale was truncated, so the body of the method was not directly confirmed.

Full details: Out of Scope Changes check

Explanation

All changes support the issue objective. The isDocumentStale rule change is the requested fix. The new FileOperationRefactoringTest and FileOperationEditSaveTest tests exercise the RenameProcessor and VFS rename paths. The DocumentStampValidationTest update replaces the old test that encoded the previous rule. The documentsToSave save-without-editor behavior is described as existing (#1731) and is not part of the reported +3/-3 change, so it is not new scope. The PR description states the remaining limitation (an untracked document changed and saved during the request) explicitly; it does not expand scope.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b148e8df-02f5-40e0-ae45-0ace142af629
Commits

Reviewing files that changed from the base of the PR and between 2abaa4a and fb5ecd8.

Files selected for processing: 4

  • src/main/java/com/redhat/devtools/lsp4ij/features/files/AbstractLSPFileListener.java
  • src/test/java/com/redhat/devtools/lsp4ij/FileOperationEditSaveTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/FileOperationRefactoringTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/features/files/DocumentStampValidationTest.java

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

… opened

Fixes redhat-developer#2135

A rename or move made in the IDE dropped the server's workspace/willRenameFiles edit if it changed a file that
IntelliJ had loaded but the server hadn't opened, logging "Discarding stale workspace/will* edit: target
document(s) modified during request" though no document had changed. captureDocumentStamps() records only
the documents that the server has open, and isDocumentStale took any other target document that has a cached
document for stale. A file that isn't open in an editor has one once anything has loaded it, so the edit was
dropped for the files that a rename's edit is usually for.

Such a document is now stale only if it has unsaved changes: the server, which didn't have it open, bases its
edit on the file on disk, which the document matches unless it has unsaved changes. The recorded stamps still
decide for the documents that the server has open. DocumentStampValidationTest's test of the old rule is now
two tests, one for each case.

Not changed: a document that the server hadn't opened, and that changes and is saved again during the
request, still gets the edit.

FileOperationRefactoringTest and FileOperationEditSaveTest get a test each that loads the other file's
document before a rename: through RenameProcessor, and through a VFS rename. On main both fail: the edit
is dropped.
@lagergren
lagergren force-pushed the fix/apply-will-file-edits-to-unopened-documents branch from a370775 to fb5ecd8 Compare November 23, 2026 13:04
@codecov

codecov Bot commented Nov 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 53.15%. Comparing base (2abaa4a) to head (fb5ecd8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2137      +/-   ##
==========================================
- Coverage   53.16%   53.15%   -0.02%     
==========================================
  Files         826      826              
  Lines       34679    34679              
  Branches     5414     5414              
==========================================
- Hits        18438    18434       -4     
- Misses      13471    13476       +5     
+ Partials     2770     2769       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lagergren lagergren added this to the 0.30.2 milestone Nov 23, 2026
@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren
lagergren merged commit 0a4dda1 into redhat-developer:main Nov 23, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working refactoring rename

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A rename or move made in the IDE drops the server's willRenameFiles edit to a file that IntelliJ has loaded but the server hasn't opened

1 participant