Skip to content
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

Compress streams in notebook outputs #160946

Merged
merged 10 commits into from
Oct 11, 2022
Merged

Conversation

DonJayamanne
Copy link
Contributor

@DonJayamanne DonJayamanne commented Sep 14, 2022

Fixes #161023

@@ -271,17 +270,21 @@ type JupyterOutput =

function convertStreamOutput(output: NotebookCellOutput): JupyterOutput {
const outputs: string[] = [];
const compressedStream = output.items.length ? new TextDecoder().decode(compressOutputItemStreams(output.items[0].mime, output.items)) : '';
// Ensure each line is a separate entry in an array (ending with \n).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted code from previous PR

* Given a stream of individual stdout outputs, this function will return the compressed lines, escaping some of the common terminal escape codes.
* E.g. some terminal escape codes would result in the previous line getting cleared, such if we had 3 lines and
* last line contained such a code, then the result string would be just the first two lines.
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved into a common area

@@ -110,6 +110,14 @@ export class ExtHostCell {
output.items.length = 0;
}
output.items.push(...newItems);
if (output.items.every(item => notebookCommon.isTextStreamMime(item.mime))) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: This needs to be via a proposed API, have a specific method such as appendStreamOutputItem or the like

* E.g. some terminal escape codes would result in the previous line getting cleared, such if we had 3 lines and
* last line contained such a code, then the result string would be just the first two lines.
*/
export function compressOutputItemStreams(mimeType: string, outputs: IOutputItemDto[]) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to a common area so the code can be shared

@DonJayamanne DonJayamanne force-pushed the donjayamanne/nbOutputHandling branch 2 times, most recently from 7649cd1 to 2803c8f Compare September 26, 2022 03:07
@DonJayamanne DonJayamanne marked this pull request as ready for review October 9, 2022 23:01
roblourens
roblourens previously approved these changes Oct 11, 2022
src/vs/workbench/contrib/notebook/common/notebookCommon.ts Outdated Show resolved Hide resolved
if (output.items.length > 1 && output.items.every(item => notebookCommon.isTextStreamMime(item.mime))) {
// Look for the mimes in the items, and keep track of their order.
// Merge the streams into one output item, per mime type.
const mimeOutputs = new Map<string, Uint8Array[]>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be useful to share code between here and notebookCellTextModel?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roblourens where would i place such a common (shared) block of code.
I need to share code between the two files

  • src/vs/workbench/api/common/extHostNotebookDocument.ts
  • src/vs/workbench/contrib/notebook/common/model/notebookCellTextModel.ts

I couldn't find a way to share a file that ends up importing NotebookCellOutputItem.
Tried to add such a function in the following locations and got eslint errors about imports not being allowed

  • src/vs/workbench/common/notebookCommon.ts
  • src/vs/workbench/contrib/notebook/common/notebookCommon.ts

Hgere's the error I get
Screen Shot 2022-10-12 at 07 12 50

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're already calling into notebookCommon and that makes sense as a place to keep it, but you would have to do it in a way that doesn't directly import 'vscode', eg work with a different interface. Whatever you wanna do though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, missed this, will work on that in debt.

@DonJayamanne DonJayamanne merged commit 43957cc into main Oct 11, 2022
@DonJayamanne DonJayamanne deleted the donjayamanne/nbOutputHandling branch October 11, 2022 21:43
@github-actions github-actions bot locked and limited conversation to collaborators Nov 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Changes to how stream outputs are handled in Notebooks
3 participants