Skip to content

Commit fbc8a34

Browse files
Add variable serializer to repl state; fixed some tests
1 parent 9148904 commit fbc8a34

File tree

4 files changed

+556
-127
lines changed

4 files changed

+556
-127
lines changed

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import org.jetbrains.kotlinx.jupyter.compiler.ScriptImportsCollector
2929
import org.jetbrains.kotlinx.jupyter.compiler.util.Classpath
3030
import org.jetbrains.kotlinx.jupyter.compiler.util.EvaluatedSnippetMetadata
3131
import org.jetbrains.kotlinx.jupyter.compiler.util.SerializedCompiledScriptsData
32-
import org.jetbrains.kotlinx.jupyter.compiler.util.SerializedVariablesState
3332
import org.jetbrains.kotlinx.jupyter.config.catchAll
3433
import org.jetbrains.kotlinx.jupyter.config.getCompilationConfiguration
3534
import org.jetbrains.kotlinx.jupyter.dependencies.JupyterScriptDependenciesResolverImpl
@@ -150,6 +149,8 @@ interface ReplForJupyter {
150149

151150
val notebook: NotebookImpl
152151

152+
val variablesSerializer: VariablesSerializer
153+
153154
val fileExtension: String
154155

155156
val isEmbedded: Boolean
@@ -201,7 +202,9 @@ class ReplForJupyterImpl(
201202

202203
override val notebook = NotebookImpl(runtimeProperties)
203204

204-
val librariesScanner = LibrariesScanner(notebook)
205+
override val variablesSerializer = VariablesSerializer()
206+
207+
private val librariesScanner = LibrariesScanner(notebook)
205208
private val resourcesProcessor = LibraryResourcesProcessorImpl()
206209

207210
override var outputConfig
@@ -442,13 +445,21 @@ class ReplForJupyterImpl(
442445
updateClasspath()
443446
} ?: emptyList()
444447

448+
notebook.updateVariablesState(internalEvaluator)
449+
// printVars()
450+
// printUsagesInfo(jupyterId, cellVariables[jupyterId - 1])
451+
val entry = notebook.variablesState.entries.lastOrNull()
452+
val serializedVarsState = variablesSerializer.serializeVariableState(jupyterId - 1, entry?.key, entry?.value)
453+
val serializedData = variablesSerializer.serializeVariables(jupyterId - 1, notebook.variablesState)
454+
455+
445456
val variablesStateUpdate = notebook.variablesState.mapValues { "" }
446457
EvalResultEx(
447458
result.result.value,
448459
rendered,
449460
result.scriptInstance,
450461
result.result.name,
451-
EvaluatedSnippetMetadata(newClasspath, compiledData, newImports, SerializedVariablesState()),
462+
EvaluatedSnippetMetadata(newClasspath, compiledData, newImports, serializedData),
452463
)
453464
}
454465
}

0 commit comments

Comments
 (0)