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 file connected by an editor feature as its last editor closes stays connected without an editor #1880
A feature that asks for a file's language servers just as the file's last editor closes connects the file again, after the close has disconnected it. The file then stays connected with no editor showing it: the server keeps it open, and LSP4IJ treats it as an open document from then on, for instance applying a workspace diagnostic report to it as an opened document instead of keeping it in the closed-file cache.
How it happens
Opening an editor starts IntelliJ's first code vision pass on a pooled thread:
getLanguageServers(psiFile) connects the file without a scope, and the wrapper's connect() runs later in the common pool. When the editor closes before that connection runs, LSPFileListener.fileClosed() disconnects the file first, and the late connect() then connects it again for good, since nothing is left to close it.
Code vision is the case that was traced; any feature that connects through getLanguageServers(psiFile) on its own schedule can do the same when it runs after the file's last editor closed.
How it was found
It made WorkspaceDiagnosticsTest.testCloseFiltersWorkspacePullWithoutPreviousResultId flaky on main (4c93203 on Windows, 31c951c on macOS) and on #1875: the test opened and closed an editor within milliseconds, and when the code vision connection ran after the close, the "fresh" report found an opened document, so getClosedDocument(uri, false) returned null. With a hold that let the code vision connection run only after the close's disconnect, the failure reproduced in 19 of 20 runs. #1879 makes the test deterministic by not opening an editor, and leaves this race as it is.
It has the same symptom as #1842, which #1843 fixed for the connection of a selected tab, but it's a different connection.
Possible direction
Tie the connections that editor features make to the editor's lifetime, so that a connection asked for while an editor was open doesn't outlive it: for instance, have such a connection check, when it runs, that the file still has an editor (or another reason to stay connected), or make it a scoped connection, as temporary requests already use, that an editor's close can end.
Activity
fix: don't connect a file again for a feature that asked before its l…