@@ -5,6 +5,9 @@ import jupyter.kotlin.DependsOn
55import jupyter.kotlin.KotlinContext
66import jupyter.kotlin.KotlinKernelHostProvider
77import jupyter.kotlin.Repository
8+ import kotlinx.coroutines.Dispatchers
9+ import kotlinx.coroutines.GlobalScope
10+ import kotlinx.coroutines.launch
811import org.jetbrains.annotations.TestOnly
912import org.jetbrains.kotlin.config.KotlinCompilerVersion
1013import org.jetbrains.kotlinx.jupyter.api.Code
@@ -131,7 +134,8 @@ interface ReplForJupyter {
131134
132135 suspend fun serializeVariables (cellId : Int , descriptorsState : Map <String , SerializedVariablesState >, callback : (SerializationReply ) -> Unit )
133136
134- suspend fun serializeVariables (topLevelVarName : String , descriptorsState : Map <String , SerializedVariablesState >, callback : (SerializationReply ) -> Unit )
137+ suspend fun serializeVariables (topLevelVarName : String , descriptorsState : Map <String , SerializedVariablesState >, pathToDescriptor : List <String > = emptyList(),
138+ callback : (SerializationReply ) -> Unit )
135139
136140 val homeDir: File ?
137141
@@ -202,7 +206,7 @@ class ReplForJupyterImpl(
202206
203207 override val variablesSerializer = VariablesSerializer ()
204208
205- private val librariesScanner = LibrariesScanner (notebook)
209+ val librariesScanner = LibrariesScanner (notebook)
206210 private val resourcesProcessor = LibraryResourcesProcessorImpl ()
207211
208212 override var outputConfig
@@ -439,8 +443,10 @@ class ReplForJupyterImpl(
439443 // printUsagesInfo(jupyterId, cellVariables[jupyterId - 1])
440444 val serializedData = variablesSerializer.serializeVariables(jupyterId - 1 , notebook.variablesState, notebook.unchangedVariables())
441445
446+ GlobalScope .launch(Dispatchers .Default ) {
447+ variablesSerializer.tryValidateCache(jupyterId - 1 , notebook.cellVariables)
448+ }
442449
443- val variablesStateUpdate = notebook.variablesState.mapValues { " " }
444450 EvalResultEx (
445451 result.result.value,
446452 rendered,
@@ -543,8 +549,9 @@ class ReplForJupyterImpl(
543549 doWithLock(SerializationArgs (descriptorsState, cellId = cellId, callback = callback), serializationQueue, SerializationReply (cellId, descriptorsState), ::doSerializeVariables)
544550 }
545551
546- override suspend fun serializeVariables (topLevelVarName : String , descriptorsState : Map <String , SerializedVariablesState >, callback : (SerializationReply ) -> Unit ) {
547- doWithLock(SerializationArgs (descriptorsState, topLevelVarName = topLevelVarName, callback = callback), serializationQueue, SerializationReply (), ::doSerializeVariables)
552+ override suspend fun serializeVariables (topLevelVarName : String , descriptorsState : Map <String , SerializedVariablesState >, pathToDescriptor : List <String >,
553+ callback : (SerializationReply ) -> Unit ) {
554+ doWithLock(SerializationArgs (descriptorsState, topLevelVarName = topLevelVarName, callback = callback, pathToDescriptor = pathToDescriptor), serializationQueue, SerializationReply (), ::doSerializeVariables)
548555 }
549556
550557 private fun doSerializeVariables (args : SerializationArgs ): SerializationReply {
@@ -555,7 +562,7 @@ class ReplForJupyterImpl(
555562 finalAns
556563 }
557564 args.descriptorsState.forEach { (name, state) ->
558- resultMap[name] = variablesSerializer.doIncrementalSerialization(cellId - 1 , name, state)
565+ resultMap[name] = variablesSerializer.doIncrementalSerialization(cellId - 1 , name, state, args.pathToDescriptor )
559566 }
560567 log.debug(" Serialization cellID: $cellId " )
561568 log.debug(" Serialization answer: ${resultMap.entries.first().value.fieldDescriptor} " )
@@ -599,6 +606,7 @@ class ReplForJupyterImpl(
599606 val descriptorsState : Map <String , SerializedVariablesState >,
600607 var cellId : Int = -1 ,
601608 val topLevelVarName : String = " " ,
609+ val pathToDescriptor : List <String > = emptyList(),
602610 override val callback : (SerializationReply ) -> Unit
603611 ) : LockQueueArgs<SerializationReply>
604612
0 commit comments