@@ -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
@@ -122,7 +125,8 @@ interface ReplForJupyter {
122125
123126 suspend fun serializeVariables (cellId : Int , descriptorsState : Map <String , SerializedVariablesState >, callback : (SerializationReply ) -> Unit )
124127
125- suspend fun serializeVariables (topLevelVarName : String , descriptorsState : Map <String , SerializedVariablesState >, callback : (SerializationReply ) -> Unit )
128+ suspend fun serializeVariables (topLevelVarName : String , descriptorsState : Map <String , SerializedVariablesState >, pathToDescriptor : List <String > = emptyList(),
129+ callback : (SerializationReply ) -> Unit )
126130
127131 val homeDir: File ?
128132
@@ -193,7 +197,7 @@ class ReplForJupyterImpl(
193197
194198 override val variablesSerializer = VariablesSerializer ()
195199
196- private val librariesScanner = LibrariesScanner (notebook)
200+ val librariesScanner = LibrariesScanner (notebook)
197201 private val resourcesProcessor = LibraryResourcesProcessorImpl ()
198202
199203 override var outputConfig
@@ -428,8 +432,10 @@ class ReplForJupyterImpl(
428432 // printUsagesInfo(jupyterId, cellVariables[jupyterId - 1])
429433 val serializedData = variablesSerializer.serializeVariables(jupyterId - 1 , notebook.variablesState, notebook.unchangedVariables())
430434
435+ GlobalScope .launch(Dispatchers .Default ) {
436+ variablesSerializer.tryValidateCache(jupyterId - 1 , notebook.cellVariables)
437+ }
431438
432- val variablesStateUpdate = notebook.variablesState.mapValues { " " }
433439 EvalResultEx (
434440 result.result.value,
435441 rendered,
@@ -532,8 +538,9 @@ class ReplForJupyterImpl(
532538 doWithLock(SerializationArgs (descriptorsState, cellId = cellId, callback = callback), serializationQueue, SerializationReply (cellId, descriptorsState), ::doSerializeVariables)
533539 }
534540
535- override suspend fun serializeVariables (topLevelVarName : String , descriptorsState : Map <String , SerializedVariablesState >, callback : (SerializationReply ) -> Unit ) {
536- doWithLock(SerializationArgs (descriptorsState, topLevelVarName = topLevelVarName, callback = callback), serializationQueue, SerializationReply (), ::doSerializeVariables)
541+ override suspend fun serializeVariables (topLevelVarName : String , descriptorsState : Map <String , SerializedVariablesState >, pathToDescriptor : List <String >,
542+ callback : (SerializationReply ) -> Unit ) {
543+ doWithLock(SerializationArgs (descriptorsState, topLevelVarName = topLevelVarName, callback = callback, pathToDescriptor = pathToDescriptor), serializationQueue, SerializationReply (), ::doSerializeVariables)
537544 }
538545
539546 private fun doSerializeVariables (args : SerializationArgs ): SerializationReply {
@@ -544,7 +551,7 @@ class ReplForJupyterImpl(
544551 finalAns
545552 }
546553 args.descriptorsState.forEach { (name, state) ->
547- resultMap[name] = variablesSerializer.doIncrementalSerialization(cellId - 1 , name, state)
554+ resultMap[name] = variablesSerializer.doIncrementalSerialization(cellId - 1 , name, state, args.pathToDescriptor )
548555 }
549556 log.debug(" Serialization cellID: $cellId " )
550557 log.debug(" Serialization answer: ${resultMap.entries.first().value.fieldDescriptor} " )
@@ -588,6 +595,7 @@ class ReplForJupyterImpl(
588595 val descriptorsState : Map <String , SerializedVariablesState >,
589596 var cellId : Int = -1 ,
590597 val topLevelVarName : String = " " ,
598+ val pathToDescriptor : List <String > = emptyList(),
591599 override val callback : (SerializationReply ) -> Unit
592600 ) : LockQueueArgs<SerializationReply>
593601
0 commit comments