-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow value rendering using renderers processor from API #183
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
jupyter-lib/api/src/main/kotlin/org/jetbrains/kotlinx/jupyter/api/TypeRenderersProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.jetbrains.kotlinx.jupyter.api | ||
|
||
import org.jetbrains.kotlinx.jupyter.api.libraries.ExecutionHost | ||
|
||
/** | ||
* [TypeRenderersProcessor] is responsible for rendering objects. | ||
* You may use it to render values exactly like notebook renders results, | ||
* and also register new renderers in runtime. | ||
*/ | ||
interface TypeRenderersProcessor { | ||
/** | ||
* Renders [value] in context of this execution [host] | ||
*/ | ||
fun renderValue(host: ExecutionHost, value: Any?): Any? | ||
|
||
/** | ||
* Adds new [renderer] for this notebook. | ||
* Don't turn on the optimizations for [PrecompiledRendererTypeHandler] | ||
*/ | ||
fun registerWithoutOptimizing(renderer: RendererTypeHandler) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...er/src/main/kotlin/org/jetbrains/kotlinx/jupyter/codegen/ResultsTypeRenderersProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.jetbrains.kotlinx.jupyter.codegen | ||
|
||
import org.jetbrains.kotlinx.jupyter.api.Code | ||
import org.jetbrains.kotlinx.jupyter.api.FieldValue | ||
import org.jetbrains.kotlinx.jupyter.api.PrecompiledRendererTypeHandler | ||
import org.jetbrains.kotlinx.jupyter.api.RendererTypeHandler | ||
import org.jetbrains.kotlinx.jupyter.api.TypeRenderersProcessor | ||
import org.jetbrains.kotlinx.jupyter.api.libraries.ExecutionHost | ||
|
||
interface ResultsTypeRenderersProcessor : TypeRenderersProcessor { | ||
/** | ||
* Renders cell result [field] represented as [FieldValue] in the [host] context | ||
*/ | ||
fun renderResult(host: ExecutionHost, field: FieldValue): Any? | ||
|
||
/** | ||
* Adds new [renderer] for this notebook. | ||
* Returns code to be executed on execution host | ||
* for [PrecompiledRendererTypeHandler]'s. | ||
*/ | ||
fun register(renderer: RendererTypeHandler): Code? | ||
} |
13 changes: 0 additions & 13 deletions
13
...-compiler/src/main/kotlin/org/jetbrains/kotlinx/jupyter/codegen/TypeRenderersProcessor.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not clear what this function does. Documentation would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see a problem here. Suppose the value is a container (
List<Something>
). The type of actual element renderer could not be resolved in the runtime due to type erasure. Won't it require KType?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding documentation: I've added it.
Regarding renderers: yes, due to type erasure KClass is the most we can get in runtime. It is how all the rendering mechanics works, it only uses KClass for getting type information. We could add Ktype argument here, but it would require breaking the renderers API, and it will actually be useless because it cannot be used for cells results rendering.