From 354078660d2bb6f49e0c04be0f1137e5ee8888f6 Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Thu, 28 Sep 2017 23:29:33 +0300 Subject: [PATCH] PY-24875: Filter messages in console, do not use InputFilter EP With InputFilter API we can't check if are in test console and even if it is Python console or not. Affecting any console in Intellij-based product is not good idea and may lead to performance problems. See https://buildserver.labs.intellij.net/viewLog.html?buildId=22270794&tab=buildResultsDiv&buildTypeId=ijplatform_master_Idea_PerformanceTests --- python/src/META-INF/python-core-common.xml | 1 - .../console/PydevConsoleRunnerImpl.java | 2 +- .../python/console/PythonConsoleView.java | 11 +++++++- .../PythonDebugLanguageConsoleView.java | 9 ++++-- .../jetbrains/python/testing/PyTestsShared.kt | 28 +++++++++---------- .../PythonTestCommandLineStateBase.java | 2 +- .../python/PyConsoleEnterHandlerTest.kt | 2 +- 7 files changed, 32 insertions(+), 23 deletions(-) diff --git a/python/src/META-INF/python-core-common.xml b/python/src/META-INF/python-core-common.xml index 294eeb900d22..357a50c76c34 100644 --- a/python/src/META-INF/python-core-common.xml +++ b/python/src/META-INF/python-core-common.xml @@ -169,7 +169,6 @@ - diff --git a/python/src/com/jetbrains/python/console/PydevConsoleRunnerImpl.java b/python/src/com/jetbrains/python/console/PydevConsoleRunnerImpl.java index 011898cbea67..053a755ae90c 100644 --- a/python/src/com/jetbrains/python/console/PydevConsoleRunnerImpl.java +++ b/python/src/com/jetbrains/python/console/PydevConsoleRunnerImpl.java @@ -387,7 +387,7 @@ public class PydevConsoleRunnerImpl implements PydevConsoleRunner { } private PythonConsoleView createConsoleView() { - PythonConsoleView consoleView = new PythonConsoleView(myProject, myTitle, mySdk); + PythonConsoleView consoleView = new PythonConsoleView(myProject, myTitle, mySdk, false); myPydevConsoleCommunication.setConsoleFile(consoleView.getVirtualFile()); consoleView.addMessageFilter(new PythonTracebackFilter(myProject)); return consoleView; diff --git a/python/src/com/jetbrains/python/console/PythonConsoleView.java b/python/src/com/jetbrains/python/console/PythonConsoleView.java index 10c6fe539502..c2790598e495 100644 --- a/python/src/com/jetbrains/python/console/PythonConsoleView.java +++ b/python/src/com/jetbrains/python/console/PythonConsoleView.java @@ -72,6 +72,7 @@ import com.jetbrains.python.debugger.PyStackFrameInfo; import com.jetbrains.python.highlighting.PyHighlighter; import com.jetbrains.python.psi.LanguageLevel; import com.jetbrains.python.sdk.PythonSdkType; +import com.jetbrains.python.testing.PyTestsSharedKt; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -85,6 +86,7 @@ public class PythonConsoleView extends LanguageConsoleImpl implements Observable private static final Logger LOG = Logger.getInstance(PythonConsoleView.class); private final ConsolePromptDecorator myPromptView; + private final boolean myTestMode; private PythonConsoleExecuteActionHandler myExecuteActionHandler; private PyConsoleSourceHighlighter mySourceHighlighter; @@ -97,8 +99,12 @@ public class PythonConsoleView extends LanguageConsoleImpl implements Observable private ActionCallback myInitialized = new ActionCallback(); private boolean isShowVars = true; - public PythonConsoleView(final Project project, final String title, final Sdk sdk) { + /** + * @param testMode this console will be used to display test output and should support TC messages + */ + public PythonConsoleView(final Project project, final String title, final Sdk sdk, final boolean testMode) { super(project, title, PythonLanguage.getInstance()); + myTestMode = testMode; getVirtualFile().putUserData(LanguageLevel.KEY, PythonSdkType.getLanguageLevelForSdk(sdk)); // Mark editor as console one, to prevent autopopup completion @@ -263,6 +269,9 @@ public class PythonConsoleView extends LanguageConsoleImpl implements Observable @Override public void print(@NotNull String text, @NotNull final ConsoleViewContentType outputType) { + if (myTestMode) { + text = PyTestsSharedKt.processTCMessage(text); + } detectIPython(text, outputType); if (PyConsoleUtil.detectIPythonEnd(text)) { myIsIPythonOutput = false; diff --git a/python/src/com/jetbrains/python/console/PythonDebugLanguageConsoleView.java b/python/src/com/jetbrains/python/console/PythonDebugLanguageConsoleView.java index 35f5f7b0678d..8eff46188572 100644 --- a/python/src/com/jetbrains/python/console/PythonDebugLanguageConsoleView.java +++ b/python/src/com/jetbrains/python/console/PythonDebugLanguageConsoleView.java @@ -42,8 +42,11 @@ public class PythonDebugLanguageConsoleView extends DuplexConsoleView = arrayOf( PyNoseTestFactory, PyTrialTestFactory) +/** + * Accepts text that may be wrapped in TC message. Unwarps it and removes TC escape code. + * Regular text is unchanged + */ +fun processTCMessage(text: String): String { + val parsedMessage = ServiceMessage.parse(text.trim()) ?: return text // Not a TC message + return when (parsedMessage) { + is TestStdOut -> parsedMessage.stdOut // TC with stdout + is TestStdErr -> parsedMessage.stdErr // TC with stderr + else -> "" // TC with out of any output + } +} + internal fun getAdditionalArgumentsPropertyName() = com.jetbrains.python.testing.PyAbstractTestConfiguration::additionalArguments.name /** @@ -789,21 +802,6 @@ object PyTestsConfigurationProducer : AbstractPythonTestConfigurationProducer>? { - val parsedMessage = ServiceMessage.parse(text.trim()) ?: return null // Not a TC message - return when (parsedMessage) { - is TestStdOut -> listOf(Pair(parsedMessage.stdOut, contentType!!)) // TC with stdout - is TestStdErr -> listOf(Pair(parsedMessage.stdErr, contentType!!)) // TC with stderr - else -> emptyList() // TC with out of any output - } - } -} - -object PyTestConsoleInputFilterProvider : ConsoleInputFilterProvider { - override fun getDefaultFilters(project: Project): Array = arrayOf(PyTestInputFilter) -} - @Retention(AnnotationRetention.RUNTIME) @Target(AnnotationTarget.PROPERTY) /** diff --git a/python/src/com/jetbrains/python/testing/PythonTestCommandLineStateBase.java b/python/src/com/jetbrains/python/testing/PythonTestCommandLineStateBase.java index c1dbffcb8b51..fcea305d3e30 100644 --- a/python/src/com/jetbrains/python/testing/PythonTestCommandLineStateBase.java +++ b/python/src/com/jetbrains/python/testing/PythonTestCommandLineStateBase.java @@ -72,7 +72,7 @@ public abstract class PythonTestCommandLineStateBase