Skip to content

Commit

Permalink
Add variable serializer to repl state; fixed some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolay-egorov committed Jul 23, 2021
1 parent f20216b commit 0e78ed1
Show file tree
Hide file tree
Showing 5 changed files with 286 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class EvaluatedSnippetMetadata(
val newClasspath: Classpath = emptyList(),
val compiledData: SerializedCompiledScriptsData = SerializedCompiledScriptsData.EMPTY,
val newImports: List<String> = emptyList(),
val evaluatedVariablesState: SerializedVariablesState = SerializedVariablesState()
val evaluatedVariablesState: Map<String, SerializedVariablesState> = emptyMap()
) {
companion object {
val EMPTY = EvaluatedSnippetMetadata()
Expand Down
11 changes: 8 additions & 3 deletions src/main/kotlin/org/jetbrains/kotlinx/jupyter/repl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ interface ReplForJupyter {

val notebook: NotebookImpl

val variablesSerializer: VariablesSerializer

val fileExtension: String

val isEmbedded: Boolean
Expand Down Expand Up @@ -187,6 +189,8 @@ class ReplForJupyterImpl(

override val notebook = NotebookImpl(runtimeProperties)

override val variablesSerializer = VariablesSerializer()

private val librariesScanner = LibrariesScanner(notebook)
private val resourcesProcessor = LibraryResourcesProcessorImpl()

Expand Down Expand Up @@ -420,10 +424,11 @@ class ReplForJupyterImpl(
notebook.updateVariablesState(internalEvaluator)
// printVars()
// printUsagesInfo(jupyterId, cellVariables[jupyterId - 1])
val entry = notebook.variablesState.entries.last()
val serializedVarsState = serializeVariableState(entry.key, entry.value)
val entry = notebook.variablesState.entries.lastOrNull()
val serializedVarsState = variablesSerializer.serializeVariableState(jupyterId - 1, entry?.key, entry?.value)
val serializedData = variablesSerializer.serializeVariables(jupyterId - 1, notebook.variablesState)

EvalResult(rendered, EvaluatedSnippetMetadata(newClasspath, compiledData, newImports, serializedVarsState))
EvalResult(rendered, EvaluatedSnippetMetadata(newClasspath, compiledData, newImports, serializedData))
}
}

Expand Down
Loading

0 comments on commit 0e78ed1

Please sign in to comment.