Skip to content

workspace/will* requests for a rename or move made in the IDE still block the UI thread, up to the file operations timeout #1740

Closed

Description

@lagergren

a0730c2 moved the workspace/will* requests from beforeVfsChange() into prepareChange(), and bounded their wait with the new file operations timeout (5 s by default). Its Javadoc says that IntelliJ calls prepareChange on a background thread. That holds for events from a VFS refresh. But the will* requests are only sent for the other events (isFromRefresh() is false), and IntelliJ calls prepareChange for those synchronously, in the write action that changes the file. So a rename or move made in the IDE still waits for the server's reply on the UI thread, for up to the timeout.

Where IntelliJ calls prepareChange

AsyncEventSupport registers a BulkFileListener, whose before(events) runs in the write action that makes the change. Unless the events were already processed asynchronously, which only a refresh does (markAsynchronouslyProcessedEvents), before calls runAsyncListeners(events). That calls each AsyncFileListener.prepareChange(events) on the same thread. I read this in AsyncEventSupport$1.before in app-client.jar of IntelliJ 2024.2, the platform LSP4IJ builds against.

Measurement

On main (9d1e5cd), with a server that answers workspace/willRenameFiles after 2 seconds, the write action of a rename on the UI thread takes 2,129 ms, and that of a move takes 2,048 ms. The test, in an LSPCodeInsightFixtureTestCase("*.foo") whose server registers willRename and didRename for **/*.foo, as FileOperationEditSaveTest does:

MockLanguageServer.INSTANCE.getWorkspaceService().setWillRenameDelayMs(2000);
long start = System.nanoTime();
WriteCommandAction.runWriteCommandAction(myFixture.getProject(), () -> {
    try {
        file.rename(this, "moved.foo");    // or file.move(this, target)
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
});
// on the UI thread (isDispatchThread() is true), the write action took 2129 ms, and willRenameFiles was sent

Since a0730c2, the wait is bounded, so the UI no longer freezes for as long as the server takes. It still freezes, though, for up to the timeout.

Possible direction

To keep the request off the UI thread, it has to be sent before the write action that changes the file starts. For example, rename and move refactorings could send it when they start, as VS Code runs its onWillRenameFiles participants before its file service applies the operation. prepareChange would then only apply the edits it already has, and other operations would keep today's bounded wait. I haven't tried this in LSP4IJ, and I don't know which entry points would cover all of the IDE's operations. Our own IntelliJ client avoids the freeze by getting the server's edits from its rename and move entry points before the write action.

I can help with a pull request if you think this is the right direction.

Activity

  1. added
    bug
    on Oct 26, 2026
  2. added this to the 0.21.1 milestone on Oct 26, 2026
  3. moved this to In Progress in Java Toolingon Oct 26, 2026
  4. moved this from In Progress to Done in Java Toolingon Oct 26, 2026
  5. added a commit that references this issue on Oct 26, 2026
    ffd02c2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions