From 48866fbeeb7ea6d969dfa6958263c2f3a9b1aad1 Mon Sep 17 00:00:00 2001 From: Dmitry Kovanikov Date: Fri, 28 Aug 2015 17:16:40 +0300 Subject: [PATCH] [ide-console] Remove INCOMPLETE support from ide console --- .../kotlin/cli/jvm/repl/ReplInterpreter.java | 9 ++++- .../kotlin/console/KotlinConsoleExecutor.kt | 2 +- .../console/KotlinConsoleHistoryManager.kt | 8 +--- .../kotlin/console/KotlinConsoleRunner.kt | 10 +---- .../kotlin/console/KotlinReplOutputHandler.kt | 2 +- .../highlight/KotlinHistoryHighlighter.kt | 8 ++-- .../highlight/KotlinReplOutputHighlighter.kt | 38 ------------------- 7 files changed, 15 insertions(+), 62 deletions(-) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/ReplInterpreter.java b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/ReplInterpreter.java index b8df8742cb6..c977bdf3cfc 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/ReplInterpreter.java +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/ReplInterpreter.java @@ -271,8 +271,13 @@ public class ReplInterpreter { AnalyzerWithCompilerReport.SyntaxErrorReport syntaxErrorReport = AnalyzerWithCompilerReport.reportSyntaxErrors(psiFile, errorHolder); if (syntaxErrorReport.isHasErrors() && syntaxErrorReport.isAllErrorsAtEof()) { - previousIncompleteLines.add(line); - return LineResult.incomplete(); + if (ideMode) { + return LineResult.compileError(errorHolder.getRenderedDiagnostics()); + } + else { + previousIncompleteLines.add(line); + return LineResult.incomplete(); + } } previousIncompleteLines.clear(); diff --git a/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinConsoleExecutor.kt b/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinConsoleExecutor.kt index d8d136d0936..c7d1e6cccbe 100644 --- a/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinConsoleExecutor.kt +++ b/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinConsoleExecutor.kt @@ -36,7 +36,7 @@ public class KotlinConsoleExecutor( val inputText = document.text.trim() if (inputText.isNotEmpty()) { - historyHighlighter.printNewCommandInHistory(inputText, historyManager.lastCommandType) + historyHighlighter.printNewCommandInHistory(inputText) submitCommand("$inputText\n") } } diff --git a/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinConsoleHistoryManager.kt b/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinConsoleHistoryManager.kt index 79173aea850..01ae100f2f7 100644 --- a/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinConsoleHistoryManager.kt +++ b/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinConsoleHistoryManager.kt @@ -20,7 +20,6 @@ import com.intellij.codeInsight.lookup.LookupManager import com.intellij.openapi.command.WriteCommandAction import com.intellij.openapi.editor.ex.EditorEx import com.intellij.openapi.editor.ex.util.EditorUtil -import org.jetbrains.kotlin.console.highlight.ReplOutputType import java.awt.event.KeyAdapter import java.awt.event.KeyEvent @@ -34,16 +33,11 @@ public class KotlinConsoleHistoryManager(private val runner: KotlinConsoleRunner private var prevCaretOffset = -1 private var unfinishedCommand = "" - var lastCommandType = ReplOutputType.USER_OUTPUT - val lastCommandLength: Int get() = history.last().length() public fun updateHistory(command: String) { - if (lastCommandType == ReplOutputType.INCOMPLETE) - history[history.lastIndex] = "${history.last()}$command" - else - history.add(command) + history.add(command) // reset history positions historyPos = history.size() diff --git a/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinConsoleRunner.kt b/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinConsoleRunner.kt index bda603a3526..24602f3ed70 100644 --- a/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinConsoleRunner.kt +++ b/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinConsoleRunner.kt @@ -23,7 +23,6 @@ import com.intellij.execution.process.* import com.intellij.execution.runners.AbstractConsoleRunnerWithHistory import com.intellij.execution.ui.RunContentDescriptor import com.intellij.openapi.actionSystem.* -import com.intellij.openapi.command.WriteCommandAction import com.intellij.openapi.editor.colors.EditorColors import com.intellij.openapi.editor.ex.EditorEx import com.intellij.openapi.editor.markup.* @@ -40,7 +39,6 @@ import org.jetbrains.kotlin.console.highlight.ReplColors import org.jetbrains.kotlin.idea.JetLanguage import java.awt.Color import java.awt.Font -import java.util.concurrent.ConcurrentHashMap import javax.swing.Icon import kotlin.properties.Delegates @@ -53,7 +51,6 @@ public class KotlinConsoleRunner( title: String, path: String? ) : AbstractConsoleRunnerWithHistory(myProject, title, path) { - private val editorToIndicator = ConcurrentHashMap() private val historyManager = KotlinConsoleHistoryManager(this) private var disposableDescriptor: RunContentDescriptor by Delegates.notNull() @@ -152,6 +149,7 @@ public class KotlinConsoleRunner( historyEditor.settings.isUseSoftWraps = true historyEditor.settings.additionalLinesCount = 0 + historyEditor.scrollPane.horizontalScrollBar.isEnabled = true consoleEditor.settings.isCaretRowShown = true consoleEditor.settings.additionalLinesCount = 2 @@ -165,12 +163,6 @@ public class KotlinConsoleRunner( ) indicatorHighlighter.gutterIconRenderer = indicator - editorToIndicator[editor] = indicatorHighlighter - } - - fun changeEditorIndicatorIcon(editor: EditorEx, newIcon: Icon) { - val oldHighlighter = editorToIndicator[editor] ?: return - WriteCommandAction.runWriteCommandAction(project) { oldHighlighter.gutterIconRenderer = KotlinConsoleIndicatorRenderer(newIcon) } } // this method shouldn't be called in normal usage; it is for test purpose only diff --git a/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinReplOutputHandler.kt b/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinReplOutputHandler.kt index dc44d0db6df..cf6410707fd 100644 --- a/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinReplOutputHandler.kt +++ b/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinReplOutputHandler.kt @@ -61,7 +61,7 @@ public class KotlinReplOutputHandler( "HELP_PROMPT" -> outputHighlighter.printHelp(content) "USER_OUTPUT" -> outputHighlighter.printUserOutput(content) "REPL_RESULT" -> outputHighlighter.printResultWithGutterIcon(content) - "REPL_INCOMPLETE" -> outputHighlighter.changeIndicatorOnIncomplete() + "REPL_INCOMPLETE", "COMPILE_ERROR" -> outputHighlighter.highlightCompilerErrors(createCompilerMessages(content)) "RUNTIME_ERROR" -> outputHighlighter.printRuntimeError(content) "INNER_ERROR" -> logError(javaClass, content) diff --git a/idea/idea-repl/src/org/jetbrains/kotlin/console/highlight/KotlinHistoryHighlighter.kt b/idea/idea-repl/src/org/jetbrains/kotlin/console/highlight/KotlinHistoryHighlighter.kt index a059cd37fba..afb1c9074a2 100644 --- a/idea/idea-repl/src/org/jetbrains/kotlin/console/highlight/KotlinHistoryHighlighter.kt +++ b/idea/idea-repl/src/org/jetbrains/kotlin/console/highlight/KotlinHistoryHighlighter.kt @@ -29,10 +29,10 @@ import org.jetbrains.kotlin.console.gutter.ReplIcons public class KotlinHistoryHighlighter(private val runner: KotlinConsoleRunner ) { private val consoleView: LanguageConsoleImpl by lazy { runner.consoleView as LanguageConsoleImpl } - fun printNewCommandInHistory(trimmedCommandText: String, lastCommandType: ReplOutputType) { + fun printNewCommandInHistory(trimmedCommandText: String) { val historyEditor = consoleView.historyViewer - addLineBreakIfNeeded(historyEditor, lastCommandType) + addLineBreakIfNeeded(historyEditor) val consoleEditor = consoleView.consoleEditor val consoleDocument = consoleEditor.document @@ -53,7 +53,7 @@ public class KotlinHistoryHighlighter(private val runner: KotlinConsoleRunner ) } } - private fun addLineBreakIfNeeded(historyEditor: EditorEx, lastCommandType: ReplOutputType) { + private fun addLineBreakIfNeeded(historyEditor: EditorEx) { val historyDocument = historyEditor.document val historyText = historyDocument.text val textLength = historyText.length() @@ -63,7 +63,7 @@ public class KotlinHistoryHighlighter(private val runner: KotlinConsoleRunner ) if (textLength == 0) // this will work first time after 'Clear all' action runner.addGutterIndicator(historyEditor, ReplIcons.HISTORY_INDICATOR) - else if (lastCommandType != ReplOutputType.INCOMPLETE) + else historyDocument.insertString(textLength + 1, "\n") } else if (!historyText.endsWith("\n\n")) { diff --git a/idea/idea-repl/src/org/jetbrains/kotlin/console/highlight/KotlinReplOutputHighlighter.kt b/idea/idea-repl/src/org/jetbrains/kotlin/console/highlight/KotlinReplOutputHighlighter.kt index 881d51cdfd9..ae13747ad17 100644 --- a/idea/idea-repl/src/org/jetbrains/kotlin/console/highlight/KotlinReplOutputHighlighter.kt +++ b/idea/idea-repl/src/org/jetbrains/kotlin/console/highlight/KotlinReplOutputHighlighter.kt @@ -24,7 +24,6 @@ import com.intellij.lang.annotation.HighlightSeverity import com.intellij.openapi.command.WriteCommandAction import com.intellij.openapi.editor.colors.CodeInsightColors import com.intellij.openapi.editor.colors.TextAttributesKey -import com.intellij.openapi.editor.ex.util.EditorUtil import com.intellij.openapi.editor.markup.HighlighterLayer import com.intellij.openapi.editor.markup.HighlighterTargetArea import com.intellij.openapi.editor.markup.TextAttributes @@ -38,13 +37,6 @@ import org.jetbrains.kotlin.console.gutter.ReplIcons import org.jetbrains.kotlin.diagnostics.Severity import javax.swing.Icon -enum class ReplOutputType { - USER_OUTPUT, - RESULT, - INCOMPLETE, - ERROR -} - public class KotlinReplOutputHighlighter( private val runner: KotlinConsoleRunner, private val historyManager: KotlinConsoleHistoryManager, @@ -57,8 +49,6 @@ public class KotlinReplOutputHighlighter( private val historyDocument = historyEditor.document private val historyMarkup = historyEditor.markupModel - private fun resetConsoleEditorIndicator() = runner.changeEditorIndicatorIcon(consoleView.consoleEditor, ReplIcons.EDITOR_INDICATOR) - private fun textOffsets(text: String): Pair { consoleView.flushDeferredText() // flush before getting offsets to calculate them properly val oldLen = historyDocument.textLength @@ -106,43 +96,18 @@ public class KotlinReplOutputHighlighter( fun printInitialPrompt(command: String) = consoleView.print(command, ReplColors.INITIAL_PROMPT_CONTENT_TYPE) fun printHelp(help: String) = WriteCommandAction.runWriteCommandAction(project) { - resetConsoleEditorIndicator() - historyManager.lastCommandType = ReplOutputType.USER_OUTPUT - printOutput(help, ConsoleViewContentType.SYSTEM_OUTPUT, ReplIcons.SYSTEM_HELP) } fun printUserOutput(command: String) = WriteCommandAction.runWriteCommandAction(project) { - resetConsoleEditorIndicator() - historyManager.lastCommandType = ReplOutputType.USER_OUTPUT consoleView.print(command, ReplColors.USER_OUTPUT_CONTENT_TYPE) } fun printResultWithGutterIcon(result: String) = WriteCommandAction.runWriteCommandAction(project) { - resetConsoleEditorIndicator() - historyManager.lastCommandType = ReplOutputType.RESULT - printOutput(result, ConsoleViewContentType.NORMAL_OUTPUT, ReplIcons.RESULT) } - fun changeIndicatorOnIncomplete() = WriteCommandAction.runWriteCommandAction(project) { - historyManager.lastCommandType = ReplOutputType.INCOMPLETE - runner.changeEditorIndicatorIcon(consoleView.consoleEditor, ReplIcons.INCOMPLETE_INDICATOR) - - // remove line breaks after incomplete part - val historyText = historyDocument.text - val historyLength = historyText.length() - val trimmedHistoryText = historyText.trimEnd() - val whitespaceCharsToDelete = historyLength - trimmedHistoryText.length() - - historyDocument.deleteString(historyLength - whitespaceCharsToDelete, historyLength) - EditorUtil.scrollToTheEnd(historyEditor) - } - fun highlightCompilerErrors(compilerMessages: List) = WriteCommandAction.runWriteCommandAction(project) { - resetConsoleEditorIndicator() - historyManager.lastCommandType = ReplOutputType.ERROR - val lastCommandStartOffset = historyDocument.textLength - historyManager.lastCommandLength val lastCommandStartLine = historyDocument.getLineNumber(lastCommandStartOffset) val historyCommandRunIndicator = historyMarkup.allHighlighters filter { @@ -176,9 +141,6 @@ public class KotlinReplOutputHighlighter( } fun printRuntimeError(errorText: String) = WriteCommandAction.runWriteCommandAction(project) { - resetConsoleEditorIndicator() - historyManager.lastCommandType = ReplOutputType.ERROR - printOutput(errorText, ConsoleViewContentType.ERROR_OUTPUT, ReplIcons.RUNTIME_EXCEPTION) }