Skip to content

fix: the document of a deleted file is closed, also when no editor has the file open - #2340

Merged
lagergren merged 2 commits into
redhat-developer:mainfrom
lagergren:fix/deleted-file-document
Nov 30, 2026
Merged

lagergren merged 2 commits into
redhat-developer:mainfrom
lagergren:fix/deleted-file-document

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

Fixes #2335, for 0.30.3.

Behaviour changes

One commit each, to be rebase-merged.

Commit Change
fix: the document of a deleted file is closed, also when no editor has the file open A delete sends textDocument/didClose for each document whose file it removed, the files of a deleted directory included, and drops the document, before workspace/didDeleteFiles and workspace/didChangeWatchedFiles. Before, only the close of an editor disconnected a document. So a document connected without an editor, as for the inline values of a stopped debug session, stayed connected with an invalid file, its diagnostics kept being pulled, and a new file at the same URL got the deleted file's text. A language server left without a document then follows its idle-stop policy, as after the close of its last editor.
fix: a connection asked for before its file is deleted no longer connects the deleted file A connection that waits, as for its language server to start, while its file is deleted, now connects nothing. Before, it registered the document after the delete had disconnected the deleted files, so the document stayed connected.

Tests

DeletedFileDocumentTest, 6 tests. Each fails against its commit's parent src/main:

Commit Tests Failing against the parent
the document of a deleted file is closed 5 5
a connection asked for before its file is deleted 1 1

testTheDocumentOfADeletedFileWithAnEditorIsClosed fails against main only because of the light test fixture: its editor manager still reports the editor when the close event comes, so LSPFileListener.fileClosed ignored the close. In the IDE, the close of the editor of a deleted file should already disconnect its document. That isn't checked.

The full suite passes locally on macOS, on IC 2024.2: 2,658 tests, 0 failures, 0 errors, 7 skipped.

Not in this PR

A document connected without an editor still stays connected while its file exists, until a delete, a move or the language server's stop. Closing it once its request has the answer, the "ideally" of #2335, isn't done:

  • for the inline values, it would send didOpen and didClose around each stop and each workspace/inlineValue/refresh in a file that no editor shows;
  • other requests for a file that no editor shows connect it in the same way, so that would cover only the debugger's part.

…s the file open

A file connected for a request without an editor, as for the inline values
of a stopped debug session, stayed connected after its delete: no didClose,
an opened document with an invalid file, and a new file at the same URL
served the deleted text. The delete now disconnects every document whose
file it removed, the files of a deleted directory included, before the
file operations are sent. A language server left without a document then
follows its idle-stop policy, as after the close of its last editor.
…ects the deleted file

A connection that waited, as for the language server to start, while its
file was deleted registered the document after the delete had
disconnected the deleted files, so it stayed connected. A connection now
checks that its file is valid, under the lock that the delete takes, before
it registers the document.
@lagergren lagergren added this to the 0.30.3 milestone Nov 28, 2026
@lagergren lagergren added the bug Something isn't working label Nov 28, 2026
@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Deleted files and directories are now properly disconnected from language servers, including files without an open editor.
    • Recreated files at the same location are handled as new documents, and servers can stop when their last document is deleted.

The change disconnects language-server documents when their files are deleted. It also prevents connection setup from registering a file that became invalid while waiting for the language server.

Changes: Deleted Document Cleanup

Layer / File(s) Summary
Clean up invalid documents
src/main/java/com/redhat/devtools/lsp4ij/LanguageServerWrapper.java, src/test/java/com/redhat/devtools/lsp4ij/DeletedFileDocumentTest.java
The wrapper skips document registration when a file is invalid and disconnects opened documents whose files are invalid. Tests cover deletion during server initialization.
Handle VFS deletion events
src/main/java/com/redhat/devtools/lsp4ij/LSPFileListener.java, src/test/java/com/redhat/devtools/lsp4ij/DeletedFileDocumentTest.java
The listener disconnects deleted documents after the VFS operation and schedules an idle-stop check when documents were removed. Tests cover file and directory deletion, file recreation at the same URI, server shutdown, and document closure.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant VFS
  participant LSPFileListener
  participant LanguageServerWrapper
  VFS->>LSPFileListener: Complete deletion event
  LSPFileListener->>LanguageServerWrapper: Disconnect documents with invalid files
  LanguageServerWrapper-->>LSPFileListener: Return whether documents were removed
  LSPFileListener->>LSPFileListener: Schedule stopIfIdle when documents were removed
Loading

Suggested reviewers: angelozerr

Merge Risk: Minimal · up to ffd5b

Deleting a file now closes its language-server document and cleans up state, so deleted or recreated files no longer leave stale documents behind. No merge-blocking risk was found, and the change is covered by new tests.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title describes the main change: a deleted file's document is now closed even when no editor has the file open. The raw summary confirms that deletion now sends didClose and disconnects documents,…
Description check Passed The description explains the behaviour changes, the two commits, the reasoning and the test results. It relates directly to the changeset, which adds deletion-driven document disconnection and a test …
Linked Issues check Passed Issue #2335 requires four coding behaviors: (1) on deletion of a file connected without an editor, send textDocument/didClose; (2) remove the stale document from getOpenedDocuments(), so its diagnosti…
Out of Scope Changes check Passed The changed files are LSPFileListener.java (delete handling in prepareChange, prepareMoves delegate parameter, VFileDeleteEvent import), LanguageServerWrapper.java (invalid-file check in connectDocume…
Full details: Title check

Explanation

The title describes the main change: a deleted file's document is now closed even when no editor has the file open. The raw summary confirms that deletion now sends didClose and disconnects documents, including those in deleted directories. The title is specific and concise.

Full details: Description check

Explanation

The description explains the behaviour changes, the two commits, the reasoning and the test results. It relates directly to the changeset, which adds deletion-driven document disconnection and a test class.

Full details: Linked Issues check

Explanation

Issue #2335 requires four coding behaviors: (1) on deletion of a file connected without an editor, send textDocument/didClose; (2) remove the stale document from getOpenedDocuments(), so its diagnostics stop being pulled; (3) prevent a recreated file at the same URL from reusing the deleted text; (4) stop a connection requested before deletion from reconnecting the deleted file. The whole-PR summary shows: LSPFileListener.prepareChange disconnects documents whose files a VFS delete removed, after the VFS operation and before the delegate's afterVfsChange. This covers (1)-(3). LanguageServerWrapper.connectDocument abandons registration when the file is invalid at the registration lock, and disconnectDeletedDocuments removes invalid opened documents. This covers (4). DeletedFileDocumentTest (6 tests) covers the no-editor delete, directory delete, recreated file with its own text, server stop after last document, and deletion during pending initialization. The issue's 'ideally' item (closing a document once no request needs it) is optional wording and the PR explicitly defers it. Per the PR description, this is not a required objective. The rename-tolerance workaround in the issue is a consumer-side note and is not a requirement here. Evidence is from the summary and the PR description; I did not run the tests. The test testTheDocumentOfADeletedFileWithAnEditorIsClosed is a fixture-specific case and does not change the coding verdict.

Full details: Out of Scope Changes check

Explanation

The changed files are LSPFileListener.java (delete handling in prepareChange, prepareMoves delegate parameter, VFileDeleteEvent import), LanguageServerWrapper.java (invalid-file check in connectDocument, disconnectDeletedDocuments), and the new DeletedFileDocumentTest.java. Each change maps to an objective of #2335 or to its tests. The prepareMoves signature change is a supporting refactor needed to keep move handling working with the new delete wrapper. No unrelated feature or unrelated refactor appears in the summary. The PR does not add the deferred 'ideally' close-when-unneeded behavior, so it introduces no out-of-scope behavior of that kind.

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: 0c6ea425-92aa-4ca4-b44a-9414af558f72
Commits

Reviewing files that changed from the base of the PR and between 7c6d061 and ffd5b2b.

Files selected for processing: 3

  • src/main/java/com/redhat/devtools/lsp4ij/LSPFileListener.java
  • src/main/java/com/redhat/devtools/lsp4ij/LanguageServerWrapper.java
  • src/test/java/com/redhat/devtools/lsp4ij/DeletedFileDocumentTest.java

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

@codecov

codecov Bot commented Nov 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.76923% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.67%. Comparing base (7c6d061) to head (ffd5b2b).

Files with missing lines Patch % Lines
...va/com/redhat/devtools/lsp4ij/LSPFileListener.java 75.00% 4 Missing ⚠️
.../redhat/devtools/lsp4ij/LanguageServerWrapper.java 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2340      +/-   ##
==========================================
+ Coverage   58.64%   58.67%   +0.02%     
==========================================
  Files         849      849              
  Lines       36719    36744      +25     
  Branches     7609     7616       +7     
==========================================
+ Hits        21535    21559      +24     
  Misses      12186    12186              
- Partials     2998     2999       +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 merged commit 444037a into redhat-developer:main Nov 30, 2026
11 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A file connected for a request without an editor stays connected after the file is deleted

1 participant