Skip to content

Commit 2b43c34

Browse files
Add variable serializer to repl state; fixed some tests
1 parent c4fc163 commit 2b43c34

File tree

5 files changed

+286
-132
lines changed

5 files changed

+286
-132
lines changed

jupyter-lib/shared-compiler/src/main/kotlin/org/jetbrains/kotlinx/jupyter/compiler/util/serializedCompiledScript.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class EvaluatedSnippetMetadata(
3636
val newClasspath: Classpath = emptyList(),
3737
val compiledData: SerializedCompiledScriptsData = SerializedCompiledScriptsData.EMPTY,
3838
val newImports: List<String> = emptyList(),
39-
val evaluatedVariablesState: SerializedVariablesState = SerializedVariablesState()
39+
val evaluatedVariablesState: Map<String, SerializedVariablesState> = emptyMap()
4040
) {
4141
companion object {
4242
val EMPTY = EvaluatedSnippetMetadata()

src/main/kotlin/org/jetbrains/kotlinx/jupyter/repl.kt

+8-3
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ interface ReplForJupyter {
136136

137137
val notebook: NotebookImpl
138138

139+
val variablesSerializer: VariablesSerializer
140+
139141
val fileExtension: String
140142

141143
val isEmbedded: Boolean
@@ -187,6 +189,8 @@ class ReplForJupyterImpl(
187189

188190
override val notebook = NotebookImpl(runtimeProperties)
189191

192+
override val variablesSerializer = VariablesSerializer()
193+
190194
private val librariesScanner = LibrariesScanner(notebook)
191195
private val resourcesProcessor = LibraryResourcesProcessorImpl()
192196

@@ -420,10 +424,11 @@ class ReplForJupyterImpl(
420424
notebook.updateVariablesState(internalEvaluator)
421425
// printVars()
422426
// printUsagesInfo(jupyterId, cellVariables[jupyterId - 1])
423-
val entry = notebook.variablesState.entries.last()
424-
val serializedVarsState = serializeVariableState(entry.key, entry.value)
427+
val entry = notebook.variablesState.entries.lastOrNull()
428+
val serializedVarsState = variablesSerializer.serializeVariableState(jupyterId - 1, entry?.key, entry?.value)
429+
val serializedData = variablesSerializer.serializeVariables(jupyterId - 1, notebook.variablesState)
425430

426-
EvalResult(rendered, EvaluatedSnippetMetadata(newClasspath, compiledData, newImports, serializedVarsState))
431+
EvalResult(rendered, EvaluatedSnippetMetadata(newClasspath, compiledData, newImports, serializedData))
427432
}
428433
}
429434

0 commit comments

Comments
 (0)