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