-
Notifications
You must be signed in to change notification settings - Fork 29.5k
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
Notebook rendering approaches and API #88243
Comments
It would be great if you could also investigate vega and vega-lite output types. Both JupyterLab and nteract support the vega and vega-lite MIME output types out-of-the box. CC @domoritz from the vega team. |
Vega and Vega-Lite work if you use https://github.com/microsoft/vscode-python for Python notebooks. I think you could use the same approach (using nteract components) here. |
Thanks for the update @rebornix
|
@davidanthoff @domoritz thanks for the pointers, I'll take Vega into account while testing. @DonJayamanne thanks for the good questions, we don't know all the answers yet but here is what we thought
Yes, an extension can register multiple notebook providers, but for each resource, there should be one active provider. For example, an extension can register one provider for
The extension which contributes the notebook provider should be able to access that. Like you mentioned, it would be somewhat similar to
Can you elaborate more on this one? Are you saying multiple extensions contributing to the same notebook file/editor? |
Does this mean we can have two separate extensions one that contribute a notebook provider, and another that doesn't, but only wishes to read the contents of an active notebook editor (like TextDocument).
Yes. Can we have other extensions add adornments or behaviors to the UI (but not provide any functionality for execution of cells, and the like). Thanks for answering the questions. |
I don't have concrete answer for this one. If there is no obvious security or any other concern, I think the notebook content can be public to all extensions.
We can probably support but not sure how/what yet. It might be similar to a normal Monaco Editor that extensions can contribute Editor Actions, Keybindings, or Decorations. What and How is not clear yet at this moment. |
@rebornix One more item. Other variations include hiding editor cells selectively, i.e. not all. |
I'm a maintainer of Google Colaboratory's output isolation feature and am a strong proponent of isolating notebook outputs- very happy to see this work being explored (the current notebook editor's approach seems a bit risky, can expand on this offline if desired but I suspect the issues are known). A few things-
|
The purpose this issue (exploring rendering approaches and first cut of API) was archived so we are going to close it and track our work in new issues. Thanks everyone for your contribution to this topic! |
Last iteration we built a prototype for rendering Notebook in the core and based on the lessons we learnt while dealing with Notebook outputs, we found that Notebook outputs can be arbitrary, it can contain text, streams, images, html and scripts. More over, some of the output types expect them to be in the same browser environment and can access the DOM structure directly. It leads to challenges of rendering outputs in the core as we can't just insert them into the UI. Out current approach is rendering insecure outputs in a web view and lay code cells on top of the web view.
This month, we will set up a test extension which can emit different types of outputs (acting like a mock Notebook kernel) and we hook the extension up with the core. We will use this extension to test output rendering and figure out what's the missing part with current implementation.
The work is happening now in #86632.
Notebook rendering improvement and testing
The rendering approach we take here is rendering secure outputs in the core (like markdown, text, ansi) and insecure ones in webview. The core will sync their positioning and dimensions.
Our major focus is improving the scrolling experience for insecure outputs and exploring how we can support full Jupyter notebook outputs (nteract, ipywidgets) but still keep VS Code core free of any Jupyter Notebook concept.
<script>
tags.API exploration
To test different types of notebook outputs, we started the sketch of notebook API. The first prototype was as simple as a language provider, which can provide content for a notebook opened in the editor:
As we noted in #86632, a notebook document consists of code cells and outputs. Every code cell is a text document and will be loaded in Monaco Editor when visible. A notebook document should have following functionalities:
string | string[]
orvscode.TextDocument
?)The challenge here is how to describe a code cell: how will notebook provide generate them, how to access their latest content when they are updated in the UI, etc.
Alternative implementation
The major UX challenge with current approach is we are syncing notebook scrolling and notebook cells/outputs sizes between the core UI and the web view. Users can see the lagging in the webview while scrolling the editor. We will continue with current approach and see how far we can go but we also need to look into alternative implementations.
Notes
RequireJS/AMD
Jupyter uses RequireJS to handle JavaScript libraries and the whole ecosystem seems be on top of it (correct me if I'm wrong). With RequireJs or any AMD loader, notebooks can load dependencies dynamically and this is a fundamental infrastructure for interactive outputs, like ipywidgets and Vega.
While implementing the notebook rendering in the core, we still want to keep the core clean and free of Jupyter knowledge, especially how and what Jupyter needs to render outputs. The JavaScript dependencies an output requires should all come from notebook providers.
VS Code has a builtin AMD loader and we can inject this loader to Output rendering environment in advance. Jupyter Notebook providers can take it for granted (assuming that there is always a AMD loader so Notebook providers don't need to inject RequireJS themselves). The heavy lifting work for Jupyter Notebook providers is declaring dynamic dependencies it needs for rendering an interactive output. Thus some output marshaling is required.
Let's use Vega as an example, the outputs we receive from Jupyter Notebook is similar to below
As you can see above, the output takes following assumptions:
nbextensions/jupyter-vega/index
element
is a jQuery wrapped DOM element inside the output areathis
contains output informationIf VS Code core insert this script directly into the DOM tree, it won't execute successfully as the core is not aware of above assumptions. While the notebook provider can wrap it with all required information:
The text was updated successfully, but these errors were encountered: