Skip to content

Commit

Permalink
Merge pull request #115817 from microsoft/notebook/outputs
Browse files Browse the repository at this point in the history
notebook outputs api
  • Loading branch information
jrieken committed Feb 11, 2021
2 parents c514299 + 6c92a66 commit 0d7c8ec
Show file tree
Hide file tree
Showing 42 changed files with 1,387 additions and 1,406 deletions.
641 changes: 353 additions & 288 deletions extensions/vscode-notebook-tests/src/notebook.test.ts

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions extensions/vscode-notebook-tests/src/notebookSmokeTestMain.ts
Expand Up @@ -70,27 +70,26 @@ export function smokeTestActivate(context: vscode.ExtensionContext): any {
label: 'notebookSmokeTest',
isPreferred: true,
executeAllCells: async (_document: vscode.NotebookDocument) => {
const edit = new vscode.WorkspaceEdit();
for (let i = 0; i < _document.cells.length; i++) {
_document.cells[i].outputs = [{
outputKind: vscode.CellOutputKind.Rich,
data: {
'text/html': ['test output']
}
}];
edit.replaceNotebookCellOutput(_document.uri, i, [new vscode.NotebookCellOutput([
new vscode.NotebookCellOutputItem('text/html', ['test output'], undefined)
])]);
}

await vscode.workspace.applyEdit(edit);
},
cancelAllCellsExecution: async () => { },
executeCell: async (_document: vscode.NotebookDocument, _cell: vscode.NotebookCell | undefined) => {
if (!_cell) {
_cell = _document.cells[0];
}

_cell.outputs = [{
outputKind: vscode.CellOutputKind.Rich,
data: {
'text/html': ['test output']
}
}];
const edit = new vscode.WorkspaceEdit();
edit.replaceNotebookCellOutput(_document.uri, _cell.index, [new vscode.NotebookCellOutput([
new vscode.NotebookCellOutputItem('text/html', ['test output'], undefined)
])]);
await vscode.workspace.applyEdit(edit);
return;
},
cancelCellExecution: async () => { }
Expand Down
84 changes: 33 additions & 51 deletions extensions/vscode-notebook-tests/src/notebookTestMain.ts
Expand Up @@ -61,15 +61,12 @@ export function activate(context: vscode.ExtensionContext): any {
label: 'Notebook Test Kernel',
isPreferred: true,
executeAllCells: async (_document: vscode.NotebookDocument) => {
const cell = _document.cells[0];

cell.outputs = [{
outputKind: vscode.CellOutputKind.Rich,
data: {
'text/plain': ['my output']
}
}];
return;
const edit = new vscode.WorkspaceEdit();

edit.replaceNotebookCellOutput(_document.uri, 0, [new vscode.NotebookCellOutput([
new vscode.NotebookCellOutputItem('text/plain', ['my output'], undefined)
])]);
return vscode.workspace.applyEdit(edit);
},
cancelAllCellsExecution: async (_document: vscode.NotebookDocument) => { },
executeCell: async (document: vscode.NotebookDocument, cell: vscode.NotebookCell | undefined) => {
Expand All @@ -78,26 +75,21 @@ export function activate(context: vscode.ExtensionContext): any {
}

if (document.uri.path.endsWith('customRenderer.vsctestnb')) {
cell.outputs = [{
outputKind: vscode.CellOutputKind.Rich,
data: {
'text/custom': 'test'
}
}];
const edit = new vscode.WorkspaceEdit();
edit.replaceNotebookCellOutput(document.uri, cell.index, [new vscode.NotebookCellOutput([
new vscode.NotebookCellOutputItem('text/custom', ['test'], undefined)
])]);

return;
return vscode.workspace.applyEdit(edit);
}

const edit = new vscode.WorkspaceEdit();
// const previousOutputs = cell.outputs;
const newOutputs: vscode.CellOutput[] = [{
outputKind: vscode.CellOutputKind.Rich,
data: {
'text/plain': ['my output']
}
}];

cell.outputs = newOutputs;
return;
edit.replaceNotebookCellOutput(document.uri, cell.index, [new vscode.NotebookCellOutput([
new vscode.NotebookCellOutputItem('text/plain', ['my output'], undefined)
])]);

return vscode.workspace.applyEdit(edit);
},
cancelCellExecution: async (_document: vscode.NotebookDocument, _cell: vscode.NotebookCell) => { }
};
Expand All @@ -107,42 +99,32 @@ export function activate(context: vscode.ExtensionContext): any {
label: 'Notebook Secondary Test Kernel',
isPreferred: false,
executeAllCells: async (_document: vscode.NotebookDocument) => {
const cell = _document.cells[0];

cell.outputs = [{
outputKind: vscode.CellOutputKind.Rich,
data: {
'text/plain': ['my second output']
}
}];
return;
const edit = new vscode.WorkspaceEdit();
edit.replaceNotebookCellOutput(_document.uri, 0, [new vscode.NotebookCellOutput([
new vscode.NotebookCellOutputItem('text/plain', ['my second output'], undefined)
])]);

return vscode.workspace.applyEdit(edit);
},
cancelAllCellsExecution: async (_document: vscode.NotebookDocument) => { },
executeCell: async (document: vscode.NotebookDocument, cell: vscode.NotebookCell | undefined) => {
if (!cell) {
cell = document.cells[0];
}

if (document.uri.path.endsWith('customRenderer.vsctestnb')) {
cell.outputs = [{
outputKind: vscode.CellOutputKind.Rich,
data: {
'text/custom': 'test 2'
}
}];
const edit = new vscode.WorkspaceEdit();

return;
if (document.uri.path.endsWith('customRenderer.vsctestnb')) {
edit.replaceNotebookCellOutput(document.uri, cell.index, [new vscode.NotebookCellOutput([
new vscode.NotebookCellOutputItem('text/custom', ['test 2'], undefined)
])]);
} else {
edit.replaceNotebookCellOutput(document.uri, cell.index, [new vscode.NotebookCellOutput([
new vscode.NotebookCellOutputItem('text/plain', ['my second output'], undefined)
])]);
}

const newOutputs: vscode.CellOutput[] = [{
outputKind: vscode.CellOutputKind.Rich,
data: {
'text/plain': ['my second output']
}
}];

cell.outputs = newOutputs;
return;
return vscode.workspace.applyEdit(edit);
},
cancelCellExecution: async (_document: vscode.NotebookDocument, _cell: vscode.NotebookCell) => { }
};
Expand Down

0 comments on commit 0d7c8ec

Please sign in to comment.