[ide-console] Remove INCOMPLETE support from ide console

This commit is contained in:
Dmitry Kovanikov
2015-08-28 17:16:40 +03:00
committed by Pavel V. Talanov
parent fcc5fa13f3
commit 48866fbeeb
7 changed files with 15 additions and 62 deletions
@@ -271,8 +271,13 @@ public class ReplInterpreter {
AnalyzerWithCompilerReport.SyntaxErrorReport syntaxErrorReport = AnalyzerWithCompilerReport.reportSyntaxErrors(psiFile, errorHolder); AnalyzerWithCompilerReport.SyntaxErrorReport syntaxErrorReport = AnalyzerWithCompilerReport.reportSyntaxErrors(psiFile, errorHolder);
if (syntaxErrorReport.isHasErrors() && syntaxErrorReport.isAllErrorsAtEof()) { if (syntaxErrorReport.isHasErrors() && syntaxErrorReport.isAllErrorsAtEof()) {
previousIncompleteLines.add(line); if (ideMode) {
return LineResult.incomplete(); return LineResult.compileError(errorHolder.getRenderedDiagnostics());
}
else {
previousIncompleteLines.add(line);
return LineResult.incomplete();
}
} }
previousIncompleteLines.clear(); previousIncompleteLines.clear();
@@ -36,7 +36,7 @@ public class KotlinConsoleExecutor(
val inputText = document.text.trim() val inputText = document.text.trim()
if (inputText.isNotEmpty()) { if (inputText.isNotEmpty()) {
historyHighlighter.printNewCommandInHistory(inputText, historyManager.lastCommandType) historyHighlighter.printNewCommandInHistory(inputText)
submitCommand("$inputText\n") submitCommand("$inputText\n")
} }
} }
@@ -20,7 +20,6 @@ import com.intellij.codeInsight.lookup.LookupManager
import com.intellij.openapi.command.WriteCommandAction import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.editor.ex.EditorEx import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.editor.ex.util.EditorUtil import com.intellij.openapi.editor.ex.util.EditorUtil
import org.jetbrains.kotlin.console.highlight.ReplOutputType
import java.awt.event.KeyAdapter import java.awt.event.KeyAdapter
import java.awt.event.KeyEvent import java.awt.event.KeyEvent
@@ -34,16 +33,11 @@ public class KotlinConsoleHistoryManager(private val runner: KotlinConsoleRunner
private var prevCaretOffset = -1 private var prevCaretOffset = -1
private var unfinishedCommand = "" private var unfinishedCommand = ""
var lastCommandType = ReplOutputType.USER_OUTPUT
val lastCommandLength: Int val lastCommandLength: Int
get() = history.last().length() get() = history.last().length()
public fun updateHistory(command: String) { public fun updateHistory(command: String) {
if (lastCommandType == ReplOutputType.INCOMPLETE) history.add(command)
history[history.lastIndex] = "${history.last()}$command"
else
history.add(command)
// reset history positions // reset history positions
historyPos = history.size() historyPos = history.size()
@@ -23,7 +23,6 @@ import com.intellij.execution.process.*
import com.intellij.execution.runners.AbstractConsoleRunnerWithHistory import com.intellij.execution.runners.AbstractConsoleRunnerWithHistory
import com.intellij.execution.ui.RunContentDescriptor import com.intellij.execution.ui.RunContentDescriptor
import com.intellij.openapi.actionSystem.* import com.intellij.openapi.actionSystem.*
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.editor.colors.EditorColors import com.intellij.openapi.editor.colors.EditorColors
import com.intellij.openapi.editor.ex.EditorEx import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.editor.markup.* import com.intellij.openapi.editor.markup.*
@@ -40,7 +39,6 @@ import org.jetbrains.kotlin.console.highlight.ReplColors
import org.jetbrains.kotlin.idea.JetLanguage import org.jetbrains.kotlin.idea.JetLanguage
import java.awt.Color import java.awt.Color
import java.awt.Font import java.awt.Font
import java.util.concurrent.ConcurrentHashMap
import javax.swing.Icon import javax.swing.Icon
import kotlin.properties.Delegates import kotlin.properties.Delegates
@@ -53,7 +51,6 @@ public class KotlinConsoleRunner(
title: String, title: String,
path: String? path: String?
) : AbstractConsoleRunnerWithHistory<LanguageConsoleView>(myProject, title, path) { ) : AbstractConsoleRunnerWithHistory<LanguageConsoleView>(myProject, title, path) {
private val editorToIndicator = ConcurrentHashMap<EditorEx, RangeHighlighter>()
private val historyManager = KotlinConsoleHistoryManager(this) private val historyManager = KotlinConsoleHistoryManager(this)
private var disposableDescriptor: RunContentDescriptor by Delegates.notNull() private var disposableDescriptor: RunContentDescriptor by Delegates.notNull()
@@ -152,6 +149,7 @@ public class KotlinConsoleRunner(
historyEditor.settings.isUseSoftWraps = true historyEditor.settings.isUseSoftWraps = true
historyEditor.settings.additionalLinesCount = 0 historyEditor.settings.additionalLinesCount = 0
historyEditor.scrollPane.horizontalScrollBar.isEnabled = true
consoleEditor.settings.isCaretRowShown = true consoleEditor.settings.isCaretRowShown = true
consoleEditor.settings.additionalLinesCount = 2 consoleEditor.settings.additionalLinesCount = 2
@@ -165,12 +163,6 @@ public class KotlinConsoleRunner(
) )
indicatorHighlighter.gutterIconRenderer = indicator 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 // this method shouldn't be called in normal usage; it is for test purpose only
@@ -61,7 +61,7 @@ public class KotlinReplOutputHandler(
"HELP_PROMPT" -> outputHighlighter.printHelp(content) "HELP_PROMPT" -> outputHighlighter.printHelp(content)
"USER_OUTPUT" -> outputHighlighter.printUserOutput(content) "USER_OUTPUT" -> outputHighlighter.printUserOutput(content)
"REPL_RESULT" -> outputHighlighter.printResultWithGutterIcon(content) "REPL_RESULT" -> outputHighlighter.printResultWithGutterIcon(content)
"REPL_INCOMPLETE" -> outputHighlighter.changeIndicatorOnIncomplete() "REPL_INCOMPLETE",
"COMPILE_ERROR" -> outputHighlighter.highlightCompilerErrors(createCompilerMessages(content)) "COMPILE_ERROR" -> outputHighlighter.highlightCompilerErrors(createCompilerMessages(content))
"RUNTIME_ERROR" -> outputHighlighter.printRuntimeError(content) "RUNTIME_ERROR" -> outputHighlighter.printRuntimeError(content)
"INNER_ERROR" -> logError(javaClass, content) "INNER_ERROR" -> logError(javaClass, content)
@@ -29,10 +29,10 @@ import org.jetbrains.kotlin.console.gutter.ReplIcons
public class KotlinHistoryHighlighter(private val runner: KotlinConsoleRunner ) { public class KotlinHistoryHighlighter(private val runner: KotlinConsoleRunner ) {
private val consoleView: LanguageConsoleImpl by lazy { runner.consoleView as LanguageConsoleImpl } private val consoleView: LanguageConsoleImpl by lazy { runner.consoleView as LanguageConsoleImpl }
fun printNewCommandInHistory(trimmedCommandText: String, lastCommandType: ReplOutputType) { fun printNewCommandInHistory(trimmedCommandText: String) {
val historyEditor = consoleView.historyViewer val historyEditor = consoleView.historyViewer
addLineBreakIfNeeded(historyEditor, lastCommandType) addLineBreakIfNeeded(historyEditor)
val consoleEditor = consoleView.consoleEditor val consoleEditor = consoleView.consoleEditor
val consoleDocument = consoleEditor.document 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 historyDocument = historyEditor.document
val historyText = historyDocument.text val historyText = historyDocument.text
val textLength = historyText.length() 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 if (textLength == 0) // this will work first time after 'Clear all' action
runner.addGutterIndicator(historyEditor, ReplIcons.HISTORY_INDICATOR) runner.addGutterIndicator(historyEditor, ReplIcons.HISTORY_INDICATOR)
else if (lastCommandType != ReplOutputType.INCOMPLETE) else
historyDocument.insertString(textLength + 1, "\n") historyDocument.insertString(textLength + 1, "\n")
} else if (!historyText.endsWith("\n\n")) { } else if (!historyText.endsWith("\n\n")) {
@@ -24,7 +24,6 @@ import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.openapi.command.WriteCommandAction import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.editor.colors.CodeInsightColors import com.intellij.openapi.editor.colors.CodeInsightColors
import com.intellij.openapi.editor.colors.TextAttributesKey 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.HighlighterLayer
import com.intellij.openapi.editor.markup.HighlighterTargetArea import com.intellij.openapi.editor.markup.HighlighterTargetArea
import com.intellij.openapi.editor.markup.TextAttributes 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 org.jetbrains.kotlin.diagnostics.Severity
import javax.swing.Icon import javax.swing.Icon
enum class ReplOutputType {
USER_OUTPUT,
RESULT,
INCOMPLETE,
ERROR
}
public class KotlinReplOutputHighlighter( public class KotlinReplOutputHighlighter(
private val runner: KotlinConsoleRunner, private val runner: KotlinConsoleRunner,
private val historyManager: KotlinConsoleHistoryManager, private val historyManager: KotlinConsoleHistoryManager,
@@ -57,8 +49,6 @@ public class KotlinReplOutputHighlighter(
private val historyDocument = historyEditor.document private val historyDocument = historyEditor.document
private val historyMarkup = historyEditor.markupModel private val historyMarkup = historyEditor.markupModel
private fun resetConsoleEditorIndicator() = runner.changeEditorIndicatorIcon(consoleView.consoleEditor, ReplIcons.EDITOR_INDICATOR)
private fun textOffsets(text: String): Pair<Int, Int> { private fun textOffsets(text: String): Pair<Int, Int> {
consoleView.flushDeferredText() // flush before getting offsets to calculate them properly consoleView.flushDeferredText() // flush before getting offsets to calculate them properly
val oldLen = historyDocument.textLength val oldLen = historyDocument.textLength
@@ -106,43 +96,18 @@ public class KotlinReplOutputHighlighter(
fun printInitialPrompt(command: String) = consoleView.print(command, ReplColors.INITIAL_PROMPT_CONTENT_TYPE) fun printInitialPrompt(command: String) = consoleView.print(command, ReplColors.INITIAL_PROMPT_CONTENT_TYPE)
fun printHelp(help: String) = WriteCommandAction.runWriteCommandAction(project) { fun printHelp(help: String) = WriteCommandAction.runWriteCommandAction(project) {
resetConsoleEditorIndicator()
historyManager.lastCommandType = ReplOutputType.USER_OUTPUT
printOutput(help, ConsoleViewContentType.SYSTEM_OUTPUT, ReplIcons.SYSTEM_HELP) printOutput(help, ConsoleViewContentType.SYSTEM_OUTPUT, ReplIcons.SYSTEM_HELP)
} }
fun printUserOutput(command: String) = WriteCommandAction.runWriteCommandAction(project) { fun printUserOutput(command: String) = WriteCommandAction.runWriteCommandAction(project) {
resetConsoleEditorIndicator()
historyManager.lastCommandType = ReplOutputType.USER_OUTPUT
consoleView.print(command, ReplColors.USER_OUTPUT_CONTENT_TYPE) consoleView.print(command, ReplColors.USER_OUTPUT_CONTENT_TYPE)
} }
fun printResultWithGutterIcon(result: String) = WriteCommandAction.runWriteCommandAction(project) { fun printResultWithGutterIcon(result: String) = WriteCommandAction.runWriteCommandAction(project) {
resetConsoleEditorIndicator()
historyManager.lastCommandType = ReplOutputType.RESULT
printOutput(result, ConsoleViewContentType.NORMAL_OUTPUT, ReplIcons.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<SeverityDetails>) = WriteCommandAction.runWriteCommandAction(project) { fun highlightCompilerErrors(compilerMessages: List<SeverityDetails>) = WriteCommandAction.runWriteCommandAction(project) {
resetConsoleEditorIndicator()
historyManager.lastCommandType = ReplOutputType.ERROR
val lastCommandStartOffset = historyDocument.textLength - historyManager.lastCommandLength val lastCommandStartOffset = historyDocument.textLength - historyManager.lastCommandLength
val lastCommandStartLine = historyDocument.getLineNumber(lastCommandStartOffset) val lastCommandStartLine = historyDocument.getLineNumber(lastCommandStartOffset)
val historyCommandRunIndicator = historyMarkup.allHighlighters filter { val historyCommandRunIndicator = historyMarkup.allHighlighters filter {
@@ -176,9 +141,6 @@ public class KotlinReplOutputHighlighter(
} }
fun printRuntimeError(errorText: String) = WriteCommandAction.runWriteCommandAction(project) { fun printRuntimeError(errorText: String) = WriteCommandAction.runWriteCommandAction(project) {
resetConsoleEditorIndicator()
historyManager.lastCommandType = ReplOutputType.ERROR
printOutput(errorText, ConsoleViewContentType.ERROR_OUTPUT, ReplIcons.RUNTIME_EXCEPTION) printOutput(errorText, ConsoleViewContentType.ERROR_OUTPUT, ReplIcons.RUNTIME_EXCEPTION)
} }