waitForAllEditorsFinallyLoaded: don't dispatch events unless there are non-loaded editors

because `UIUtil.dispatchAllInvocationEvents` isn't totally free
This commit is contained in:
peter
2019-01-21 12:30:02 +01:00
parent dc36bbcaed
commit e3b63f297c
@@ -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