[ide-console] Remove INCOMPLETE support from ide console
This commit is contained in:
committed by
Pavel V. Talanov
parent
fcc5fa13f3
commit
48866fbeeb
@@ -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();
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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<LanguageConsoleView>(myProject, title, path) {
|
||||
private val editorToIndicator = ConcurrentHashMap<EditorEx, RangeHighlighter>()
|
||||
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
|
||||
|
||||
@@ -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)
|
||||
|
||||
+4
-4
@@ -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")) {
|
||||
|
||||
-38
@@ -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<Int, Int> {
|
||||
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<SeverityDetails>) = 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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user