diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/repl/replUtil.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/repl/replUtil.kt index 20a9c47eedc..4212a153bea 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/repl/replUtil.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/repl/replUtil.kt @@ -24,8 +24,8 @@ import java.io.File import java.net.URLClassLoader // using '#' to avoid collisions with xml escaping -private val SOURCE_CHARS: List = listOf("\n", "#") -private val XML_REPLACEMENTS: List = listOf("#n", "#diez") +private val SOURCE_CHARS: List = listOf("\r", "\n", "#") +private val XML_REPLACEMENTS: List = listOf("#r", "#n", "#diez") private val END_LINE: String = LineSeparator.getSystemLineSeparator().separatorString private const val XML_PREAMBLE = "" @@ -45,6 +45,7 @@ fun String.replInputAsXml(): String { fun String.replAddLineBreak() = this + END_LINE fun String.replRemoveLineBreaksInTheEnd() = trimEnd(*END_LINE.toCharArray()) +fun String.replNormalizeLineBreaks() = replace(END_LINE, "\n") fun makeScriptBaseName(codeLine: ReplCodeLine) = "Line_${codeLine.no}${if (codeLine.generation > REPL_CODE_LINE_FIRST_GEN) "_gen_${codeLine.generation}" else ""}" diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/repl/KtScratchReplExecutor.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/repl/KtScratchReplExecutor.kt index c31ad906c06..e0d903e1507 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/repl/KtScratchReplExecutor.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/repl/KtScratchReplExecutor.kt @@ -21,6 +21,7 @@ import com.intellij.execution.process.OSProcessHandler import com.intellij.execution.process.ProcessOutputTypes import com.intellij.openapi.util.Key import org.jetbrains.kotlin.cli.common.repl.replInputAsXml +import org.jetbrains.kotlin.cli.common.repl.replNormalizeLineBreaks import org.jetbrains.kotlin.cli.common.repl.replRemoveLineBreaksInTheEnd import org.jetbrains.kotlin.cli.common.repl.replUnescapeLineBreaks import org.jetbrains.kotlin.console.KotlinConsoleKeeper @@ -123,7 +124,7 @@ class KtScratchReplExecutor(file: ScratchFile) : ScratchExecutor(file) { val root = output.firstChild as Element val outputType = root.getAttribute("type") - val content = root.textContent.replUnescapeLineBreaks().replRemoveLineBreaksInTheEnd() + val content = root.textContent.replUnescapeLineBreaks().replNormalizeLineBreaks().replRemoveLineBreaksInTheEnd() LOG.printDebugMessage("REPL output: $outputType $content") diff --git a/idea/idea-repl/src/org/jetbrains/kotlin/console/ReplOutputHandler.kt b/idea/idea-repl/src/org/jetbrains/kotlin/console/ReplOutputHandler.kt index 57bf22bd59e..f637db8762c 100644 --- a/idea/idea-repl/src/org/jetbrains/kotlin/console/ReplOutputHandler.kt +++ b/idea/idea-repl/src/org/jetbrains/kotlin/console/ReplOutputHandler.kt @@ -20,6 +20,7 @@ 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 org.jetbrains.kotlin.cli.common.repl.replNormalizeLineBreaks import org.jetbrains.kotlin.cli.common.repl.replUnescapeLineBreaks import org.jetbrains.kotlin.console.actions.logError import org.jetbrains.kotlin.diagnostics.Severity @@ -75,7 +76,7 @@ class ReplOutputHandler( val root = output.firstChild as Element val outputType = ReplEscapeType.valueOfOrNull(root.getAttribute("type")) - val content = root.textContent.replUnescapeLineBreaks() + val content = root.textContent.replUnescapeLineBreaks().replNormalizeLineBreaks() when (outputType) { INITIAL_PROMPT -> buildWarningIfNeededBeforeInit(content) diff --git a/idea/testData/scratch/unresolved.repl.after b/idea/testData/scratch/unresolved.repl.after index ad634ea7927..cc0156fa90f 100644 --- a/idea/testData/scratch/unresolved.repl.after +++ b/idea/testData/scratch/unresolved.repl.after @@ -1,6 +1,4 @@ foo() // ERROR: error: unresolved reference: foo... /** unresolved.kts:1 error: unresolved reference: foo - foo() - ^ */ \ No newline at end of file diff --git a/idea/testData/scratch/unresolvedMultiline.repl.after b/idea/testData/scratch/unresolvedMultiline.repl.after index b6c15da7f85..9697f4b6107 100644 --- a/idea/testData/scratch/unresolvedMultiline.repl.after +++ b/idea/testData/scratch/unresolvedMultiline.repl.after @@ -6,20 +6,13 @@ fun goo(a: String) { // ERROR: error: unresolved reference: goo... super.goo(a) } /** unresolvedMultiline.kts:1 error: unresolved reference: foo - foo.forEach { - ^ - error: cannot choose among the following candidates without completing type inference: @HidesMembers public inline fun Iterable.forEach(action: (???) -> Unit): Unit defined in kotlin.collections @HidesMembers public inline fun Map.forEach(action: (Map.Entry) -> Unit): Unit defined in kotlin.collections - foo.forEach { - ^ */ /** unresolvedMultiline.kts:5 error: unresolved reference: goo - super.goo(a) - ^ */ \ No newline at end of file