@@ -5,7 +5,6 @@ import jupyter.kotlin.DependsOn
55import jupyter.kotlin.KotlinContext
66import jupyter.kotlin.KotlinKernelHostProvider
77import jupyter.kotlin.Repository
8- import org.jetbrains.annotations.TestOnly
98import org.jetbrains.kotlin.config.KotlinCompilerVersion
109import org.jetbrains.kotlinx.jupyter.api.Code
1110import org.jetbrains.kotlinx.jupyter.api.ExecutionCallback
@@ -27,7 +26,6 @@ import org.jetbrains.kotlinx.jupyter.compiler.ScriptImportsCollector
2726import org.jetbrains.kotlinx.jupyter.compiler.util.Classpath
2827import org.jetbrains.kotlinx.jupyter.compiler.util.EvaluatedSnippetMetadata
2928import org.jetbrains.kotlinx.jupyter.compiler.util.SerializedCompiledScriptsData
30- import org.jetbrains.kotlinx.jupyter.compiler.util.SerializedVariablesState
3129import org.jetbrains.kotlinx.jupyter.config.catchAll
3230import org.jetbrains.kotlinx.jupyter.config.getCompilationConfiguration
3331import org.jetbrains.kotlinx.jupyter.dependencies.JupyterScriptDependenciesResolverImpl
@@ -49,7 +47,6 @@ import org.jetbrains.kotlinx.jupyter.repl.CellExecutor
4947import org.jetbrains.kotlinx.jupyter.repl.CompletionResult
5048import org.jetbrains.kotlinx.jupyter.repl.ContextUpdater
5149import org.jetbrains.kotlinx.jupyter.repl.EvalResult
52- import org.jetbrains.kotlinx.jupyter.repl.EvalResultEx
5350import org.jetbrains.kotlinx.jupyter.repl.InternalEvaluator
5451import org.jetbrains.kotlinx.jupyter.repl.KotlinCompleter
5552import org.jetbrains.kotlinx.jupyter.repl.ListErrorsResult
@@ -134,6 +131,8 @@ interface ReplForJupyter {
134131
135132 val notebook: NotebookImpl
136133
134+ val variablesSerializer: VariablesSerializer
135+
137136 val fileExtension: String
138137
139138 val isEmbedded: Boolean
@@ -185,7 +184,9 @@ class ReplForJupyterImpl(
185184
186185 override val notebook = NotebookImpl (runtimeProperties)
187186
188- val librariesScanner = LibrariesScanner (notebook)
187+ override val variablesSerializer = VariablesSerializer ()
188+
189+ private val librariesScanner = LibrariesScanner (notebook)
189190 private val resourcesProcessor = LibraryResourcesProcessorImpl ()
190191
191192 override var outputConfig
@@ -341,7 +342,7 @@ class ReplForJupyterImpl(
341342 )
342343
343344 private var evalContextEnabled = false
344- private fun < T > withEvalContext (action : () -> T ): T {
345+ private fun withEvalContext (action : () -> EvalResult ): EvalResult {
345346 return synchronized(this ) {
346347 evalContextEnabled = true
347348 try {
@@ -359,14 +360,14 @@ class ReplForJupyterImpl(
359360 else context.compilationConfiguration.asSuccess()
360361 }
361362
362- @TestOnly
363- @Suppress(" unused" )
363+ /* *
364+ * Used for debug purposes.
365+ * @see ReplCommand
366+ */
364367 private fun printVariables (isHtmlFormat : Boolean = false) = log.debug(
365368 if (isHtmlFormat) notebook.variablesReportAsHTML() else notebook.variablesReport()
366369 )
367370
368- @TestOnly
369- @Suppress(" unused" )
370371 private fun printUsagesInfo (cellId : Int , usedVariables : Set <String >? ) {
371372 log.debug(buildString {
372373 if (usedVariables == null || usedVariables.isEmpty()) {
@@ -380,7 +381,7 @@ class ReplForJupyterImpl(
380381 })
381382 }
382383
383- fun evalEx (code : Code , displayHandler : DisplayHandler ? , jupyterId : Int ): EvalResultEx {
384+ fun evalEx (code : Code , displayHandler : DisplayHandler ? , jupyterId : Int ): EvalResult {
384385 return withEvalContext {
385386 rethrowAsLibraryException(LibraryProblemPart .BEFORE_CELL_CALLBACKS ) {
386387 beforeCellExecution.forEach { executor.execute(it) }
@@ -418,15 +419,13 @@ class ReplForJupyterImpl(
418419 notebook.updateVariablesState(internalEvaluator)
419420 // printVars()
420421 // printUsagesInfo(jupyterId, cellVariables[jupyterId - 1])
422+ val entry = notebook.variablesState.entries.lastOrNull()
423+ val serializedVarsState = variablesSerializer.serializeVariableState(jupyterId - 1 , entry?.key, entry?.value)
424+ val serializedData = variablesSerializer.serializeVariables(jupyterId - 1 , notebook.variablesState)
421425
422-
423- val variablesStateUpdate = notebook.variablesState.mapValues { it.value.stringValue }
424- EvalResultEx (
426+ EvalResult (
425427 result.result.value,
426- rendered,
427- result.scriptInstance,
428- result.result.name,
429- EvaluatedSnippetMetadata (newClasspath, compiledData, newImports, SerializedVariablesState ()),
428+ EvaluatedSnippetMetadata (newClasspath, compiledData, newImports, serializedData),
430429 )
431430 }
432431 }
0 commit comments