From e3b63f297cf882868b1c1ff0b34df7ad9db0fac2 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 21 Jan 2019 12:28:12 +0100 Subject: [PATCH] waitForAllEditorsFinallyLoaded: don't dispatch events unless there are non-loaded editors because `UIUtil.dispatchAllInvocationEvents` isn't totally free --- .../daemon/impl/DaemonCodeAnalyzerImpl.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java index 49b326b1b12c..c2a5d06abb8c 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java @@ -393,22 +393,26 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzerEx implements Pers public static void waitForAllEditorsFinallyLoaded(@NotNull Project project, long timeout, @NotNull TimeUnit unit) throws TimeoutException { ApplicationManager.getApplication().assertIsDispatchThread(); long deadline = unit.toMillis(timeout) + System.currentTimeMillis(); - W: while (true) { - UIUtil.dispatchAllInvocationEvents(); if (System.currentTimeMillis() > deadline) throw new TimeoutException(); - for (FileEditor editor : FileEditorManager.getInstance(project).getAllEditors()) { - if (editor instanceof TextEditorImpl) { - try { - ((TextEditorImpl)editor).waitForLoaded(1, TimeUnit.MILLISECONDS); - } - catch (TimeoutException ignored) { - continue W; - } + if (waitABitForEditorLoading(project)) break; + UIUtil.dispatchAllInvocationEvents(); + } + } + + @TestOnly + private static boolean waitABitForEditorLoading(@NotNull Project project) { + for (FileEditor editor : FileEditorManager.getInstance(project).getAllEditors()) { + if (editor instanceof TextEditorImpl) { + try { + ((TextEditorImpl)editor).waitForLoaded(1, TimeUnit.MILLISECONDS); + } + catch (TimeoutException ignored) { + return false; } } - break; } + return true; } @TestOnly