Accept single outputs or arrays in execution task output edit methods

Fix #119601
This commit is contained in:
Rob Lourens 2021-03-24 17:46:50 -07:00
parent 75ed057885
commit 1a425eacb8
3 changed files with 8 additions and 6 deletions

View file

@ -68,9 +68,9 @@ const kernel1 = new class implements vscode.NotebookKernel {
}
task.start();
await task.replaceOutput([new vscode.NotebookCellOutput([
await task.replaceOutput(new vscode.NotebookCellOutput([
new vscode.NotebookCellOutputItem('text/plain', ['my output'], undefined)
])]);
]));
task.end({ success: true });
return;
}

View file

@ -1573,8 +1573,8 @@ declare module 'vscode' {
readonly token: CancellationToken;
clearOutput(cellIndex?: number): Thenable<void>;
appendOutput(out: NotebookCellOutput[], cellIndex?: number): Thenable<void>;
replaceOutput(out: NotebookCellOutput[], cellIndex?: number): Thenable<void>;
appendOutput(out: NotebookCellOutput | NotebookCellOutput[], cellIndex?: number): Thenable<void>;
replaceOutput(out: NotebookCellOutput | NotebookCellOutput[], cellIndex?: number): Thenable<void>;
appendOutputItems(items: NotebookCellOutputItem[], outputId: string): Thenable<void>;
replaceOutputItems(items: NotebookCellOutputItem[], outputId: string): Thenable<void>;
}

View file

@ -1164,23 +1164,25 @@ class NotebookCellExecutionTask extends Disposable {
return this.replaceOutput([], cellIndex);
},
async appendOutput(outputs: vscode.NotebookCellOutput[], cellIndex?: number): Promise<void> {
async appendOutput(outputs: vscode.NotebookCellOutput | vscode.NotebookCellOutput[], cellIndex?: number): Promise<void> {
that.verifyStateForOutput();
const handle = that.cellIndexToHandle(cellIndex);
if (typeof handle !== 'number') {
return;
}
outputs = Array.isArray(outputs) ? outputs : [outputs];
return that.applyEdits([{ editType: CellEditType.Output, handle, append: true, outputs: outputs.map(typeConverters.NotebookCellOutput.from) }]);
},
async replaceOutput(outputs: vscode.NotebookCellOutput[], cellIndex?: number): Promise<void> {
async replaceOutput(outputs: vscode.NotebookCellOutput | vscode.NotebookCellOutput[], cellIndex?: number): Promise<void> {
that.verifyStateForOutput();
const handle = that.cellIndexToHandle(cellIndex);
if (typeof handle !== 'number') {
return;
}
outputs = Array.isArray(outputs) ? outputs : [outputs];
return that.applyEdits([{ editType: CellEditType.Output, handle, outputs: outputs.map(typeConverters.NotebookCellOutput.from) }]);
},