Skip to content

fix: a file whose editor moves to another window stays open in its language servers, which no longer get didClose while an editor of the file remains - #2212

Merged
lagergren merged 2 commits into
redhat-developer:mainfrom
lagergren:fix/document-sync-detached-editor-window
Nov 24, 2026

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

Fixes #1383

What

Dragging a file's editor tab into another window (detached or not), or using Move to Opposite Group, made LSP4IJ send didClose for the file. It sent didOpen again only when a feature next asked for the file, so in between the language server worked without the document. Closing a tab right after a split also sent didClose while the file stayed open.

Cause

At the end of a tab drag, the platform (EditorTabbedContainerDragOutDelegate.dragOutFinished, the same on 2024.2, 2025.3 and 2026.3):

  1. sets CLOSING_TO_REOPEN on the file;
  2. closes the editor, which fires fileClosed while the file is in no editor;
  3. drops the file into the target. For a detached window, DockableEditorTabbedContainer.add opens it later, in a coroutine, after the marker has been cleared.

So LSPFileListener.fileClosed found no editor and disconnected the file. Move Editor to Opposite Tab Group does the same close-then-reopen, with the same marker.

Right after a split, the new tab group already has the file open (isFileOpen), but it creates its editor asynchronously, so getAllEditors(file) is empty for a moment. Closing the original tab then sent didClose too.

Change

  • ConnectDocumentToLanguageServerSetupParticipant.isClosingToReopen(file) reads the platform's CLOSING_TO_REOPEN marker, as the platform's own fileClosed listeners do, such as ScratchFileServiceImpl and QuickEditHandler. While it's set:
    • LSPFileListener.fileClosed doesn't disconnect the file;
    • the setup participant doesn't count the close as one of the file's last editor, so a connection asked for just before the drag isn't dropped.
  • LSPFileListener.fileClosed also keeps the file connected while source.isFileOpen(file) is true, as the setup participant's close count already does.

API: the marker is read from FileEditorManagerImpl.CLOSING_TO_REOPEN, which is @ApiStatus.Internal and deprecated from 2025.3, where it points to FileEditorManagerKeys.CLOSING_TO_REOPEN. FileEditorManagerKeys doesn't exist in 2024.2, so that's the reference that compiles on all supported versions. The deprecation is suppressed in that one method. The plugin verifier reports it as an internal API usage, which doesn't fail verification (failureLevel is INVALID_PLUGIN and COMPATIBILITY_PROBLEMS). Once the minimum is 2025.3 or later, it can read FileEditorManagerKeys instead (#1971).

Not in this PR:

  • Split and Move Right/Down closes the editor before the split without the platform's marker. It isn't the drag of this issue.
  • Between the close and a detached window's delayed open, the file is in no editor. A temporary connection released in exactly that gap could still disconnect it.

Tests

New EditorWindowConnectionTest (3 tests). It uses the real FileEditorManagerImpl instead of the test editor manager, which has no windows. Each test checks what the mock language server actually read, with a didSave sent after the editors change. It then closes the last editor and expects exactly [didOpen, didClose].

  • Two tab groups: a file open in two tab groups is closed in the first right after the split.
  • Move: the platform's own Move Editor to Opposite Tab Group action.
  • Drag: the end of a tab drag as the platform does it: marker set, close, marker cleared, and a drop that opens the file afterwards, as for a detached window.

A detached window is a frame, which can't be created headless, so a second tab group of the main window stands in for it. The editor manager handles both alike.

Red-green on 2024.2:

Code Result
Without the change 3 of 3 fail: the server read [didOpen, didClose, didOpen]
Marker check only The two-tab-group test fails
With the change 3 of 3 pass
  • The new class passes headless on IC 2024.2, 2025.3 and IU 2026.3.
  • The document and connection tests (*Document*, LanguageServer*, ChangeDuringConnectionTest, ConnectDuringStopTest, WorkspaceDiagnosticsTest, KeepAliveDuringPendingStopTest, ServerStopPendingRequestsTest and more) pass on all three platforms: 350 tests each, with 0 failures or skipped.

Behaviour change

Before After
Dragging a tab to another window or tab group sends didClose, and didOpen comes back only when a feature asks for the file; closing a tab right after a split sends didClose while the file stays open The file stays open in its language servers while any window or tab group has it: one didOpen, and one didClose when its last editor closes

…nguage servers, which no longer get didClose while an editor of the file remains

Dragging an editor tab into another window, a detached one included, or
moving it to the opposite tab group closes the editor before the platform
opens the file again in the other window; a drop into a detached window
opens it only later, in a coroutine. The file was in no editor at the
close, so its language servers got didClose, and didOpen again only once
a feature asked for the file. In between, they worked without the document.

The platform marks such a close with CLOSING_TO_REOPEN. A marked close now
neither disconnects the file nor counts as a close of its last editor.

Closing a file in one tab group also no longer sends didClose while the
file stays open in another one whose editor of it the platform is still
creating, as right after a split. The file listener looked only at the
editors of the file, of which that tab group has none yet, while the setup
participant already checked that the file is open.

Fixes redhat-developer#1383
… or tab group, and gets one didClose when its last editor closes

The real editor manager replaces the test one, which has no windows. A
detached window is a frame, which a headless test can't create, so another
tab group of the main window stands in for it: the editor manager treats
both alike. The tests cover a file open in two tab groups, closed in the
first right after the split; the platform's Move to Opposite Group action;
and the end of a tab drag into another window, whose drop opens the file
after the drag has ended.
@lagergren lagergren added this to the 0.30.2 milestone Nov 24, 2026
@lagergren lagergren added the bug Something isn't working label Nov 24, 2026
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Language server connections now remain active when an open file’s editor is moved between tab groups or windows.
    • Closing one of several editors for the same file no longer disconnects the language server. The connection closes only after the file’s last editor is closed.

Close handling now recognizes files that remain open or are closing to reopen. New tests cover editor transfers between tab groups and windows, and verify didClose occurs after the last editor closes.

Changes: Editor close and reopen handling

Layer / File(s) Summary
Close and reopen checks
src/main/java/com/redhat/devtools/lsp4ij/ConnectDocumentToLanguageServerSetupParticipant.java, src/main/java/com/redhat/devtools/lsp4ij/LSPFileListener.java
The close callbacks check whether other editors remain, whether the file is still reported open, and whether the file is closing to reopen.
Editor transfer scenarios
src/test/java/com/redhat/devtools/lsp4ij/EditorWindowConnectionTest.java
Tests cover files split across tab groups, moved between tab groups, and dragged to another window. They verify that the connection remains open during transfer and that the final editor close produces one didClose notification.

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: angelozerr

Merge Risk: Minimal · up to cc786

The change keeps a file connected to its language servers while an editor moves between tab groups or windows, and sends didClose only when the last editor closes. No concrete defect was found, and the new tests cover the main transfer scenarios. The remaining caveats are the already-documented Split and Move gap and reliance on an internal platform flag.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a file whose editor moves to another window keeps its language server connection, and no longer gets didClose while an editor of the file remains. The changeset adds C…
Description check Passed The description states the problem (dragging an editor to another window or tab group sends didClose), the cause (platform CLOSING_TO_REOPEN marker and async editor creation after a split), the code c…
Linked Issues check Passed Issue #1383 is the only active direct link. Its coding requirements are: (1) for one view of the file, a drag must emit either no events or both didClose and didOpen; (2) with two or more views, a dra…
Out of Scope Changes check Passed The changed production code is limited to ConnectDocumentToLanguageServerSetupParticipant and LSPFileListener, which handle the file-close and connection path that #1383 concerns. The new EditorWindow…
Full details: Title check

Explanation

The title names the main change: a file whose editor moves to another window keeps its language server connection, and no longer gets didClose while an editor of the file remains. The changeset adds CLOSING_TO_REOPEN handling and isFileOpen checks in LSPFileListener and the setup participant, plus tests for the tab-group and window-move cases. The title is long, but it matches the changes.

Full details: Description check

Explanation

The description states the problem (dragging an editor to another window or tab group sends didClose), the cause (platform CLOSING_TO_REOPEN marker and async editor creation after a split), the code changes, the API caveat for the internal FileEditorManagerImpl.CLOSING_TO_REOPEN constant, the new EditorWindowConnectionTest tests, and the behaviour change. It is directly related to the changeset.

Full details: Linked Issues check

Explanation

Issue #1383 is the only active direct link. Its coding requirements are: (1) for one view of the file, a drag must emit either no events or both didClose and didOpen; (2) with two or more views, a drag must emit neither event. The PR addresses (1) by making LSPFileListener.fileClosed keep the file connected while the platform's CLOSING_TO_REOPEN marker is set, and while source.isFileOpen(file) is true. The setup participant also does not count such a close as a last-editor close. This removes the lone didClose on drag. Requirement (2) is covered by the two-tab-group test, which checks that the server reads one didOpen and no didClose until the last editor closes. The Move Editor to Opposite Tab Group and drag-simulation tests cover the single-view path. Evidence is the PR description and AI-generated summary. The diff could not be read from the checkout, so the test results are author-reported and were not re-run. Split and Move Right/Down is explicitly excluded by the PR and is not an objective of #1383.

Full details: Out of Scope Changes check

Explanation

The changed production code is limited to ConnectDocumentToLanguageServerSetupParticipant and LSPFileListener, which handle the file-close and connection path that #1383 concerns. The new EditorWindowConnectionTest supports the objective. The FileEditorManagerImpl.CLOSING_TO_REOPEN read is a required mechanism for the marker check, and its deprecation handling is documented as a consequence of that read. No unrelated change is identified in the PR summary or description. The actual diff could not be read from the checkout, so this conclusion relies on the summary and description.

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: 5fa193dc-706d-4a26-84d3-d77204223d2b
Commits

Reviewing files that changed from the base of the PR and between d592c89 and cc7865e.

Files selected for processing: 3

  • src/main/java/com/redhat/devtools/lsp4ij/ConnectDocumentToLanguageServerSetupParticipant.java
  • src/main/java/com/redhat/devtools/lsp4ij/LSPFileListener.java
  • src/test/java/com/redhat/devtools/lsp4ij/EditorWindowConnectionTest.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.

@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 54.66%. Comparing base (1b0b053) to head (cc7865e).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...va/com/redhat/devtools/lsp4ij/LSPFileListener.java 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2212      +/-   ##
==========================================
+ Coverage   54.59%   54.66%   +0.06%     
==========================================
  Files         834      834              
  Lines       35385    35388       +3     
  Branches     7300     5547    -1753     
==========================================
+ Hits        19320    19344      +24     
+ Misses      13223    13204      -19     
+ Partials     2842     2840       -2     

☔ 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

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 24, 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 24, 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 1a0dca5 into redhat-developer:main Nov 24, 2026
9 checks passed
lagergren added a commit that referenced this pull request Nov 26, 2026
The plugin verifier reported `FileEditorManagerImpl` and its field `CLOSING_TO_REOPEN` as internal API usages on all
eight verified IDEs, 2024.2 to 2026.3, from `ConnectDocumentToLanguageServerSetupParticipant.isClosingToReopen`
(1a0dca5, #2212).

No public field has the key on every supported version:
- `FileEditorManagerImpl` is `@ApiStatus.Internal` on all of them.
- `FileEditorManagerKeys.CLOSING_TO_REOPEN` is public from 2024.3 on, but `FileEditorManagerKeys` is missing in
  2024.2, the minimum.
- No public editor event tells a close to reopen apart: at the end of a tab drag, the platform sets the marker, closes
  the editor and only then drops it into the target, which for a detached window opens the file later, in a coroutine.

So `isClosingToReopen` finds the platform's key by its name, with `Key.findKeyByName("CLOSING_TO_REOPEN")`, and keeps
it once found. It's the same key on every supported version: from 2024.3, `FileEditorManagerImpl.CLOSING_TO_REOPEN` is
`FileEditorManagerKeys.CLOSING_TO_REOPEN`, and no other platform key has the name. It's a workaround, and
`findKeyByName` is deprecated, not internal, so the verifier reports one deprecated usage instead of two internal ones.
Once the minimum version has `FileEditorManagerKeys`, `isClosingToReopen` can read it instead (#1971).

The key exists once the platform's editor manager is loaded, before any editor closes. Until it's found, as with the
editor manager of a test, no file has the marker, and the lookup is tried again at the next close.

`EditorWindowConnectionTest` gets a test that the marker which the platform's editor manager sets is the one that LSP4IJ
reads. With a wrong key name, it fails, and so do the tests of the move to the opposite tab group and of the drag into
another window.

Part of #2274
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.

didClose and didOpen events go out of balance when dragging an editor window from the main IDE view to another view

1 participant