@@ -3,6 +3,7 @@ package org.jetbrains.kotlin.jupyter
3
3
import jupyter.kotlin.*
4
4
import jupyter.kotlin.KotlinContext
5
5
import jupyter.kotlin.KotlinReceiver
6
+ import kotlinx.coroutines.runBlocking
6
7
import org.jetbrains.kotlin.config.KotlinCompilerVersion
7
8
import org.jetbrains.kotlin.jupyter.repl.completion.CompletionResult
8
9
import org.jetbrains.kotlin.jupyter.repl.completion.KotlinCompleter
@@ -11,17 +12,14 @@ import org.jetbrains.kotlin.jupyter.repl.completion.SourceCodeImpl
11
12
import org.jetbrains.kotlin.jupyter.repl.reflect.ContextUpdater
12
13
import org.jetbrains.kotlin.jupyter.repl.spark.ClassWriter
13
14
import org.jetbrains.kotlin.scripting.ide_services.compiler.KJvmReplCompilerImpl
14
- import org.jetbrains.kotlin.scripting.ide_services.evaluator.KJvmReplEvaluatorImpl
15
15
import java.io.File
16
16
import java.net.URLClassLoader
17
17
import java.util.*
18
18
import kotlin.script.dependencies.ScriptContents
19
19
import kotlin.script.experimental.api.*
20
20
import kotlin.script.experimental.host.withDefaultsFrom
21
21
import kotlin.script.experimental.jvm.*
22
- import kotlin.script.experimental.util.hasErrors
23
- import kotlin.script.experimental.util.isIncomplete
24
- import kotlin.script.experimental.util.renderError
22
+ import kotlin.script.experimental.util.*
25
23
26
24
data class EvalResult (val resultValue : Any? )
27
25
@@ -264,7 +262,7 @@ class ReplForJupyterImpl(val scriptClasspath: List<File> = emptyList(),
264
262
265
263
override fun checkComplete (executionNumber : Long , code : String ): CheckResult {
266
264
val codeLine = SourceCodeImpl (executionNumber.toInt(), code)
267
- val result = compiler.analyze(codeLine, 0 , compilerConfiguration)
265
+ val result = runBlocking { compiler.analyze(codeLine, 0 .toSourceCodePosition(codeLine) , compilerConfiguration) }
268
266
return when {
269
267
result.isIncomplete() -> CheckResult (false )
270
268
result.hasErrors() -> throw ReplException (result.renderError())
@@ -322,7 +320,7 @@ class ReplForJupyterImpl(val scriptClasspath: List<File> = emptyList(),
322
320
typeRenderers.putAll(p.typeRenderers.map { it.className to it.code })
323
321
}
324
322
325
- private fun lastReplLine () = evaluator.lastEvaluatedSnippet()?.snippetObject
323
+ private fun lastReplLine () = evaluator.lastEvaluatedSnippet?.get ()?.snippetClass
326
324
327
325
override fun eval (code : String , displayHandler : ((Any ) -> Unit )? , jupyterId : Int ): EvalResult {
328
326
synchronized(this ) {
@@ -413,7 +411,7 @@ class ReplForJupyterImpl(val scriptClasspath: List<File> = emptyList(),
413
411
override suspend fun listErrors (code : String , callback : (ListErrorsResult ) -> Unit ) = doWithLock(ListErrorsArgs (code, callback), listErrorsQueue, ListErrorsResult (code)) {
414
412
// val preprocessed = preprocessCode(code)
415
413
val codeLine = SourceCodeImpl (executionCounter++ , code)
416
- val errorsList = compiler.analyze(codeLine, 0 , compilerConfiguration)
414
+ val errorsList = runBlocking { compiler.analyze(codeLine, 0 .toSourceCodePosition(codeLine) , compilerConfiguration) }
417
415
ListErrorsResult (code, errorsList.valueOrThrow())
418
416
}
419
417
@@ -463,25 +461,25 @@ class ReplForJupyterImpl(val scriptClasspath: List<File> = emptyList(),
463
461
println (code)
464
462
val id = executionCounter++
465
463
val codeLine = SourceCodeImpl (id, code)
466
- when (val compileResultWithDiagnostics = compiler.compile(codeLine, compilerConfiguration)) {
464
+ when (val compileResultWithDiagnostics = runBlocking { compiler.compile(codeLine, compilerConfiguration) } ) {
467
465
is ResultWithDiagnostics .Success -> {
468
466
val compileResult = compileResultWithDiagnostics.value
469
- classWriter?.writeClasses(compileResult())
467
+ classWriter?.writeClasses(codeLine, compileResult.get ())
470
468
val repl = this
471
469
val currentEvalConfig = ScriptEvaluationConfiguration (evaluatorConfiguration) {
472
470
constructorArgs.invoke(repl as KotlinKernelHost )
473
471
}
474
- val result = evaluator.eval(compileResult, currentEvalConfig).valueOrThrow()
472
+ val result = runBlocking { evaluator.eval(compileResult, currentEvalConfig).valueOrThrow() }
475
473
contextUpdater.update()
476
474
477
- val pureResult = result()
475
+ val pureResult = result.get ()
478
476
return when {
479
477
pureResult.isErrorResult -> throw ReplEvalRuntimeException (pureResult.error?.message.orEmpty(), pureResult.error)
480
478
pureResult.isUnitResult -> {
481
479
InternalEvalResult (Unit , null )
482
480
}
483
481
pureResult.isValueResult -> {
484
- InternalEvalResult (pureResult.result, pureResult.compiledSnippet() .resultField)
482
+ InternalEvalResult (pureResult.result, pureResult.compiledSnippet.resultField)
485
483
}
486
484
else -> throw IllegalStateException (" Unknown eval result type ${this } " )
487
485
}
0 commit comments