diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java index 54cdffbcd73a..4c3181f92741 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java @@ -375,7 +375,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo } if (myFlushAlarm.isDisposed()) return; cancelAllFlushRequests(); - UIUtil.invokeLaterIfNeeded(new MyClearRunnable()); + addFlushRequest(new MyClearRunnable()); cancelHeavyAlarm(); } diff --git a/platform/lang-impl/src/com/intellij/unscramble/AnalyzeStacktraceUtil.java b/platform/lang-impl/src/com/intellij/unscramble/AnalyzeStacktraceUtil.java index e13325db04e1..820c9a75a6d3 100644 --- a/platform/lang-impl/src/com/intellij/unscramble/AnalyzeStacktraceUtil.java +++ b/platform/lang-impl/src/com/intellij/unscramble/AnalyzeStacktraceUtil.java @@ -40,6 +40,7 @@ import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ui.JBUI; @@ -59,15 +60,30 @@ public class AnalyzeStacktraceUtil { private AnalyzeStacktraceUtil() { } - public static void printStacktrace(@NotNull ConsoleView consoleView, @NotNull String unscrambledTrace) { + public static void printStacktrace(@NotNull final ConsoleView consoleView, @NotNull String unscrambledTrace) { ApplicationManager.getApplication().assertIsDispatchThread(); - String text = unscrambledTrace + "\n"; - String consoleText = ((ConsoleViewImpl)consoleView).getText(); + final String text = unscrambledTrace + "\n"; + final String consoleText = ((ConsoleViewImpl)consoleView).getText(); if (!text.equals(consoleText)) { consoleView.clear(); - consoleView.print(text, ConsoleViewContentType.ERROR_OUTPUT); - - consoleView.scrollTo(0); + // make sure other "clear" requests stuck in EDT are performed before our print next stacktrace + ApplicationManager.getApplication().invokeLater(new Runnable() { + @Override + public void run() { + try { + consoleView.print(text, ConsoleViewContentType.ERROR_OUTPUT); + consoleView.scrollTo(0); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + }, new Condition() { + @Override + public boolean value(Object o) { + return !((ConsoleViewImpl)consoleView).isVisible(); + } + }); } } diff --git a/platform/platform-tests/testSrc/com/intellij/execution/impl/ConsoleViewImplTest.java b/platform/platform-tests/testSrc/com/intellij/execution/impl/ConsoleViewImplTest.java index b7037137548b..bfbce06ed7b8 100644 --- a/platform/platform-tests/testSrc/com/intellij/execution/impl/ConsoleViewImplTest.java +++ b/platform/platform-tests/testSrc/com/intellij/execution/impl/ConsoleViewImplTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -66,7 +66,7 @@ public class ConsoleViewImplTest extends LightPlatformTestCase { assertEquals(2, console.getContentSize()); } - public void testDoubleClear() throws Exception { + public void testConsolePrintsSomethingAfterDoubleClear() throws Exception { ConsoleViewImpl console = myConsole; Alarm alarm = new Alarm(Alarm.ThreadToUse.SHARED_THREAD); CountDownLatch latch = new CountDownLatch(1); @@ -81,7 +81,7 @@ public class ConsoleViewImplTest extends LightPlatformTestCase { TimeoutUtil.sleep(SystemProperties.getIntProperty("console.flush.delay.ms", 200)); UIUtil.dispatchAllInvocationEvents(); assertFalse(console.hasDeferredOutput()); - //assertEquals("Test", console.getText()); + assertEquals("Test", console.getText()); } public void testTypeInEmptyConsole() throws Exception {