I think this is the last of the issues when getting the concurrent canFormats to run while we are in this hybrid state of v4 or v5. It doesn't fix the underlying timeout issue but it will ensure the UI doesn't lock up.
For reference, I just got this stacktrace.
2022-05-30 13:38:52,630 [10645915] SEVERE - #c.i.p.i.s.PostprocessReformattingAspect - java.util.concurrent.TimeoutException
java.util.concurrent.ExecutionException: java.util.concurrent.TimeoutException
at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:395)
at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1999)
at com.dprint.formatter.DprintExternalFormatter.canFormat(DprintExternalFormatter.kt:38)
at com.intellij.formatting.service.FormattingServiceUtil.lambda$findService$0(FormattingServiceUtil.java:28)
at com.intellij.util.containers.ContainerUtil.find(ContainerUtil.java:758)
at com.intellij.util.containers.ContainerUtil.find(ContainerUtil.java:742)
at com.intellij.formatting.service.FormattingServiceUtil.findService(FormattingServiceUtil.java:26)
at com.intellij.psi.impl.source.PostprocessReformattingAspect$ReformatRangesAction.execute(PostprocessReformattingAspect.java:774)
at com.intellij.psi.impl.source.PostprocessReformattingAspect.lambda$doPostponedFormattingInner$8(PostprocessReformattingAspect.java:386)
at com.intellij.psi.impl.source.codeStyle.CodeStyleManagerImpl.runWithDocCommentFormattingDisabled(CodeStyleManagerImpl.java:655)
at com.intellij.psi.impl.source.PostprocessReformattingAspect.doPostponedFormattingInner(PostprocessReformattingAspect.java:385)
at com.intellij.psi.impl.source.PostprocessReformattingAspect.lambda$doPostponedFormatting$6(PostprocessReformattingAspect.java:263)
at com.intellij.psi.impl.source.PostprocessReformattingAspect.lambda$disablePostprocessFormattingInside$2(PostprocessReformattingAspect.java:120)
at com.intellij.psi.impl.source.PostprocessReformattingAspect.disablePostprocessFormattingInside(PostprocessReformattingAspect.java:128)
at com.intellij.psi.impl.source.PostprocessReformattingAspect.disablePostprocessFormattingInside(PostprocessReformattingAspect.java:119)
at com.intellij.psi.impl.source.PostprocessReformattingAspect.lambda$doPostponedFormatting$7(PostprocessReformattingAspect.java:263)
at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeNonCancelableSection$3(CoreProgressManager.java:223)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:683)
at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:639)
at com.intellij.openapi.progress.impl.CoreProgressManager.computeInNonCancelableSection(CoreProgressManager.java:238)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeNonCancelableSection(CoreProgressManager.java:222)
at com.intellij.psi.impl.source.PostprocessReformattingAspect.doPostponedFormatting(PostprocessReformattingAspect.java:261)
at com.intellij.psi.impl.source.PostprocessReformattingAspect.doPostponedFormatting(PostprocessReformattingAspect.java:248)
at com.intellij.psi.impl.source.PostprocessReformattingAspect.decrementPostponedCounter(PostprocessReformattingAspect.java:161)
at com.intellij.psi.impl.source.PostprocessReformattingAspect$1.writeActionFinished(PostprocessReformattingAspect.java:112)
at jdk.internal.reflect.GeneratedMethodAccessor77.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.intellij.util.EventDispatcher.dispatchVoidMethod(EventDispatcher.java:120)
at com.intellij.util.EventDispatcher.lambda$createMulticaster$1(EventDispatcher.java:85)
at com.sun.proxy.$Proxy70.writeActionFinished(Unknown Source)
at com.intellij.openapi.application.impl.ApplicationImpl.fireWriteActionFinished(ApplicationImpl.java:1394)
at com.intellij.openapi.application.impl.ApplicationImpl.endWrite(ApplicationImpl.java:1232)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteActionWithClass(ApplicationImpl.java:1006)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1029)
at com.intellij.openapi.application.WriteAction.run(WriteAction.java:85)
at com.intellij.lang.ecmascript6.editor.ES6CopyPasteProcessor.processTransferableData(ES6CopyPasteProcessor.java:315)
at com.intellij.codeInsight.editorActions.PasteHandler$ProcessorAndData.process(PasteHandler.java:141)
at com.intellij.codeInsight.editorActions.PasteHandler.lambda$doPasteAction$4(PasteHandler.java:249)
at com.intellij.util.SlowOperations.allowSlowOperations(SlowOperations.java:147)
at com.intellij.codeInsight.editorActions.PasteHandler.doPasteAction(PasteHandler.java:248)
at com.intellij.codeInsight.editorActions.PasteHandler.doPaste(PasteHandler.java:124)
at com.intellij.codeInsight.editorActions.PasteHandler.lambda$execute$2(PasteHandler.java:105)
at com.intellij.openapi.project.DumbService.runWithAlternativeResolveEnabled(DumbService.java:417)
at com.intellij.codeInsight.editorActions.PasteHandler.execute(PasteHandler.java:96)
at com.intellij.codeInsight.editorActions.PasteHandler.doExecute(PasteHandler.java:52)
at com.intellij.openapi.editor.actionSystem.EditorActionHandler.lambda$execute$4(EditorActionHandler.java:199)
at com.intellij.openapi.editor.actionSystem.EditorActionHandler.doIfEnabled(EditorActionHandler.java:89)
at com.intellij.openapi.editor.actionSystem.EditorActionHandler.execute(EditorActionHandler.java:198)
at com.intellij.codeInsight.editorActions.LanguageConsolePasteHandler.doExecute(LanguageConsolePasteHandler.kt:24)
at com.intellij.openapi.editor.actionSystem.DynamicEditorActionHandler.doExecute(DynamicEditorActionHandler.java:63)
at com.intellij.openapi.editor.actionSystem.EditorActionHandler.lambda$execute$4(EditorActionHandler.java:199)
at com.intellij.openapi.editor.actionSystem.EditorActionHandler.doIfEnabled(EditorActionHandler.java:89)
at com.intellij.openapi.editor.actionSystem.EditorActionHandler.execute(EditorActionHandler.java:198)
at com.intellij.openapi.editor.actionSystem.EditorAction.lambda$actionPerformed$0(EditorAction.java:89)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:219)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:174)
at com.intellij.openapi.editor.actionSystem.EditorAction.actionPerformed(EditorAction.java:98)
at com.intellij.openapi.editor.actionSystem.EditorAction.actionPerformed(EditorAction.java:73)
at com.intellij.openapi.keymap.impl.ActionProcessor.performAction(ActionProcessor.java:65)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$1.performAction(IdeKeyEventDispatcher.java:579)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.lambda$doPerformActionInner$10(IdeKeyEventDispatcher.java:704)
at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:106)
at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:95)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.lambda$doPerformActionInner$11(IdeKeyEventDispatcher.java:704)
at com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareWithCallbacks(ActionUtil.java:256)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.doPerformActionInner(IdeKeyEventDispatcher.java:701)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:645)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:590)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processActionOrWaitSecondStroke(IdeKeyEventDispatcher.java:473)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.inInitState(IdeKeyEventDispatcher.java:462)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:227)
at com.intellij.ide.IdeEventQueue.dispatchKeyEvent(IdeEventQueue.java:804)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:740)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$6(IdeEventQueue.java:439)
at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:803)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:438)
at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:119)
at com.intellij.ide.IdeEventQueue.performActivity(IdeEventQueue.java:604)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:436)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:873)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:484)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)
Caused by: java.util.concurrent.TimeoutException
at java.base/java.util.concurrent.CompletableFuture$Timeout.run(CompletableFuture.java:2792)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
I actually found a way to fix this by using an action that is not so low level. I am going to trigger a merge and release but have a read over the PR anyways.
I think this is the last of the issues when getting the concurrent canFormats to run while we are in this hybrid state of v4 or v5. It doesn't fix the underlying timeout issue but it will ensure the UI doesn't lock up.
For reference, I just got this stacktrace.