Repl: refactoring, move common parts to utils
This commit is contained in:
@@ -18,11 +18,9 @@ package org.jetbrains.kotlin.console
|
||||
|
||||
import com.intellij.execution.process.BaseOSProcessHandler
|
||||
import com.intellij.openapi.command.WriteCommandAction
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import org.jetbrains.kotlin.cli.common.repl.replInputAsXml
|
||||
import org.jetbrains.kotlin.console.actions.logError
|
||||
|
||||
private val XML_PREAMBLE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||
|
||||
class CommandExecutor(private val runner: KotlinConsoleRunner) {
|
||||
private val commandHistory = runner.commandHistory
|
||||
private val historyUpdater = HistoryUpdater(runner)
|
||||
@@ -50,12 +48,7 @@ class CommandExecutor(private val runner: KotlinConsoleRunner) {
|
||||
val processInputOS = processHandler.processInput ?: return logError(this::class.java, "<p>Broken process stream</p>")
|
||||
val charset = (processHandler as? BaseOSProcessHandler)?.charset ?: Charsets.UTF_8
|
||||
|
||||
val xmlRes = XML_PREAMBLE +
|
||||
"<input>" +
|
||||
StringUtil.escapeXml(
|
||||
StringUtil.replace(command, SOURCE_CHARS, XML_REPLACEMENTS)
|
||||
) +
|
||||
"</input>"
|
||||
val xmlRes = command.replInputAsXml()
|
||||
|
||||
val bytes = ("$xmlRes\n").toByteArray(charset)
|
||||
processInputOS.write(bytes)
|
||||
|
||||
@@ -20,20 +20,16 @@ import com.intellij.execution.process.OSProcessHandler
|
||||
import com.intellij.execution.process.ProcessOutputTypes
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import org.jetbrains.annotations.NotNull
|
||||
import org.jetbrains.kotlin.cli.common.repl.replUnescapeLineBreaks
|
||||
import org.jetbrains.kotlin.console.actions.logError
|
||||
import org.jetbrains.kotlin.diagnostics.Severity
|
||||
import org.jetbrains.kotlin.utils.repl.ReplEscapeType
|
||||
import org.jetbrains.kotlin.utils.repl.ReplEscapeType.*
|
||||
import org.w3c.dom.Element
|
||||
import org.xml.sax.InputSource
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.nio.charset.Charset
|
||||
import javax.xml.parsers.DocumentBuilderFactory
|
||||
import org.jetbrains.kotlin.utils.repl.ReplEscapeType.*
|
||||
|
||||
val XML_REPLACEMENTS: Array<String> = arrayOf("#n", "#diez")
|
||||
val SOURCE_CHARS: Array<String> = arrayOf("\n", "#")
|
||||
|
||||
data class SeverityDetails(val severity: Severity, val description: String, val range: TextRange)
|
||||
|
||||
@@ -79,7 +75,7 @@ class ReplOutputHandler(
|
||||
|
||||
val root = output.firstChild as Element
|
||||
val outputType = ReplEscapeType.valueOfOrNull(root.getAttribute("type"))
|
||||
val content = StringUtil.replace(root.textContent, XML_REPLACEMENTS, SOURCE_CHARS)
|
||||
val content = root.textContent.replUnescapeLineBreaks()
|
||||
|
||||
when (outputType) {
|
||||
INITIAL_PROMPT -> buildWarningIfNeededBeforeInit(content)
|
||||
|
||||
Reference in New Issue
Block a user