Scripting: refactor history handling in legacy REPL using new infra
#KT-47187 fixed
This commit is contained in:
+12
@@ -441,6 +441,18 @@ obj
|
||||
tempDir.toFile().deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEvalWithCompilationError() {
|
||||
val engine = ScriptEngineManager().getEngineByExtension("kts")
|
||||
val compilable: Compilable = engine as Compilable
|
||||
assertThrows(ScriptException::class.java) {
|
||||
compilable.compile("foo")
|
||||
}
|
||||
compilable.compile("true")
|
||||
engine.eval("val x = 3")
|
||||
compilable.compile("x")
|
||||
}
|
||||
}
|
||||
|
||||
fun assertThrows(exceptionClass: Class<*>, body: () -> Unit) {
|
||||
|
||||
+13
@@ -369,6 +369,19 @@ class ReplTest : TestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCompileWithoutEval() {
|
||||
val replCompiler = KJvmReplCompilerBase<ReplCodeAnalyzerBase>()
|
||||
val replEvaluator = BasicJvmReplEvaluator()
|
||||
val compCfg = simpleScriptCompilationConfiguration
|
||||
runBlocking {
|
||||
replCompiler.compile("false".toScriptSource(), compCfg)
|
||||
replCompiler.compile("true".toScriptSource(), compCfg).onSuccess {
|
||||
replEvaluator.eval(it, simpleScriptEvaluationConfiguration)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private fun positionsEqual(a: SourceCode.Position?, b: SourceCode.Position?): Boolean {
|
||||
if (a == null || b == null) {
|
||||
|
||||
+14
-2
@@ -7,6 +7,7 @@ package kotlin.script.experimental.jvmhost.repl
|
||||
|
||||
import org.jetbrains.kotlin.cli.common.repl.*
|
||||
import org.jetbrains.kotlin.scripting.compiler.plugin.impl.KJvmReplCompilerBase
|
||||
import org.jetbrains.kotlin.scripting.compiler.plugin.impl.currentLineId
|
||||
import org.jetbrains.kotlin.scripting.compiler.plugin.repl.JvmReplCompilerState
|
||||
import org.jetbrains.kotlin.scripting.compiler.plugin.repl.ReplCodeAnalyzerBase
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock
|
||||
@@ -38,10 +39,21 @@ class JvmReplCompiler(
|
||||
replCompilerState
|
||||
)
|
||||
|
||||
val lineId = LineId(codeLine.no, codeLine.generation, snippet.hashCode())
|
||||
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
when (val res = internalScriptingRunSuspend { replCompiler.compile(listOf(snippet), scriptCompilationConfiguration) }) {
|
||||
val res = internalScriptingRunSuspend {
|
||||
replCompiler.compile(
|
||||
listOf(snippet),
|
||||
scriptCompilationConfiguration.with {
|
||||
repl {
|
||||
currentLineId(lineId)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
when (res) {
|
||||
is ResultWithDiagnostics.Success -> {
|
||||
val lineId = LineId(codeLine.no, 0, snippet.hashCode())
|
||||
ReplCompileResult.CompiledClasses(
|
||||
lineId,
|
||||
replCompiler.state.history.map { it.id },
|
||||
|
||||
Reference in New Issue
Block a user