Implement remote part of the new repl state handling

This commit is contained in:
Ilya Chernikov
2017-02-06 14:09:31 +01:00
parent f9dedab8c8
commit c5bc58ad32
9 changed files with 369 additions and 186 deletions
@@ -16,11 +16,14 @@
package org.jetbrains.kotlin.jsr223
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.common.repl.*
import org.jetbrains.kotlin.daemon.client.DaemonReportMessage
import org.jetbrains.kotlin.daemon.client.DaemonReportingTargets
import org.jetbrains.kotlin.daemon.client.KotlinCompilerClient
import org.jetbrains.kotlin.daemon.client.KotlinRemoteReplCompiler
import org.jetbrains.kotlin.daemon.client.KotlinRemoteReplClient
import org.jetbrains.kotlin.daemon.common.*
import org.jetbrains.kotlin.utils.PathUtil
import java.io.File
@@ -52,14 +55,18 @@ class KotlinJsr223JvmScriptEngine4Idea(
?: throw ScriptException("Unable to connect to repl server:" + daemonReportMessages.joinToString("\n ", prefix = "\n ") { "${it.category.name} ${it.message}" })
}
private val messageCollector = MyMessageCollector()
override val replCompiler: ReplCompiler by lazy {
daemon.let {
KotlinRemoteReplCompiler(it,
makeAutodeletingFlagFile("idea-jsr223-repl-session"),
CompileService.TargetPlatform.JVM,
templateClasspath,
templateClassName,
System.out)
KotlinRemoteReplClient(it,
makeAutodeletingFlagFile("idea-jsr223-repl-session"),
CompileService.TargetPlatform.JVM,
emptyArray(),
messageCollector,
templateClasspath,
templateClassName,
ScriptArgsWithTypes(emptyArray(), emptyArray()))
}
}
@@ -69,4 +76,20 @@ class KotlinJsr223JvmScriptEngine4Idea(
val localEvaluator: ReplFullEvaluator by lazy { GenericReplCompilingEvaluator(replCompiler, templateClasspath, Thread.currentThread().contextClassLoader) }
override val replEvaluator: ReplFullEvaluator get() = localEvaluator
private class MyMessageCollector : MessageCollector {
var _hasErrors: Boolean = false
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) {
System.err.println(message) // TODO: proper location printing
if (!_hasErrors) {
_hasErrors = severity == CompilerMessageSeverity.EXCEPTION || severity == CompilerMessageSeverity.ERROR
}
}
override fun clear() {}
override fun hasErrors(): Boolean = _hasErrors
}
}