mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 05:19:39 +00:00
adopt changes after feedback round one
This commit is contained in:
parent
611bbad868
commit
08695ede81
|
@ -423,27 +423,24 @@ suite('Notebook API tests', () => {
|
|||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
|
||||
await vscode.notebook.activeNotebookEditor!.edit(editBuilder => {
|
||||
editBuilder.replaceCellOutput(0, [
|
||||
editBuilder.replaceCellOutput(0, [new vscode.NotebookCellOutputList([
|
||||
new vscode.NotebookCellOutput('application/foo', 'bar'),
|
||||
new vscode.NotebookCellOutput('application/json', { data: true }, { metadata: true }),
|
||||
]);
|
||||
])]);
|
||||
});
|
||||
|
||||
const document = vscode.notebook.activeNotebookEditor?.document!;
|
||||
assert.strictEqual(document.isDirty, true);
|
||||
assert.strictEqual(document.cells.length, 1);
|
||||
assert.strictEqual(document.cells[0].outputs.length, 2);
|
||||
assert.strictEqual(document.cells[0].outputs.length, 1);
|
||||
|
||||
// consuming is OLD api
|
||||
const [one, two] = document.cells[0].outputs;
|
||||
// consuming is OLD api (for now)
|
||||
const [output] = document.cells[0].outputs;
|
||||
|
||||
assert.strictEqual(one.outputKind, vscode.CellOutputKind.Rich);
|
||||
assert.strictEqual((<vscode.CellDisplayOutput>one).data['application/foo'], 'bar');
|
||||
assert.strictEqual((<vscode.CellDisplayOutput>one).metadata, undefined);
|
||||
|
||||
assert.strictEqual(two.outputKind, vscode.CellOutputKind.Rich);
|
||||
assert.deepStrictEqual((<vscode.CellDisplayOutput>two).data['application/json'], { data: true });
|
||||
assert.deepStrictEqual((<vscode.CellDisplayOutput>two).metadata, { custom: { metadata: true } });
|
||||
assert.strictEqual(output.outputKind, vscode.CellOutputKind.Rich);
|
||||
assert.strictEqual((<vscode.CellDisplayOutput>output).data['application/foo'], 'bar');
|
||||
assert.deepStrictEqual((<vscode.CellDisplayOutput>output).data['application/json'], { data: true });
|
||||
assert.deepStrictEqual((<vscode.CellDisplayOutput>output).metadata, { custom: { 'application/json': { metadata: true } } });
|
||||
|
||||
await saveAllFilesAndCloseAll(undefined);
|
||||
});
|
||||
|
|
10
src/vs/vscode.proposed.d.ts
vendored
10
src/vs/vscode.proposed.d.ts
vendored
|
@ -1235,6 +1235,14 @@ declare module 'vscode' {
|
|||
constructor(mime: string, value: unknown, metadata?: Record<string, string | number | boolean>);
|
||||
}
|
||||
|
||||
export class NotebookCellOutputList {
|
||||
|
||||
readonly outputs: NotebookCellOutput[];
|
||||
readonly metadata?: Record<string, string | number | boolean>;
|
||||
|
||||
constructor(outputs: NotebookCellOutput[], metadata?: Record<string, string | number | boolean>);
|
||||
}
|
||||
|
||||
export enum NotebookCellRunState {
|
||||
Running = 1,
|
||||
Idle = 2,
|
||||
|
@ -1423,7 +1431,7 @@ declare module 'vscode' {
|
|||
export interface NotebookEditorEdit {
|
||||
replaceMetadata(value: NotebookDocumentMetadata): void;
|
||||
replaceCells(start: number, end: number, cells: NotebookCellData[]): void;
|
||||
replaceCellOutput(index: number, outputs: (NotebookCellOutput | CellOutput)[]): void;
|
||||
replaceCellOutput(index: number, outputs: (NotebookCellOutputList | CellOutput)[]): void;
|
||||
replaceCellMetadata(index: number, metadata: NotebookCellMetadata): void;
|
||||
}
|
||||
|
||||
|
|
|
@ -1148,6 +1148,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
|||
NotebookRunState: extHostTypes.NotebookRunState,
|
||||
NotebookCellStatusBarAlignment: extHostTypes.NotebookCellStatusBarAlignment,
|
||||
NotebookEditorRevealType: extHostTypes.NotebookEditorRevealType,
|
||||
NotebookCellOutputList: extHostTypes.NotebookCellOutputList,
|
||||
NotebookCellOutput: extHostTypes.NotebookCellOutput,
|
||||
};
|
||||
};
|
||||
|
|
|
@ -7,7 +7,7 @@ import { readonly } from 'vs/base/common/errors';
|
|||
import { Emitter, Event } from 'vs/base/common/event';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { MainThreadNotebookShape } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { NotebookCellOutput } from 'vs/workbench/api/common/extHostTypeConverters';
|
||||
import { NotebookCellOutputList } from 'vs/workbench/api/common/extHostTypeConverters';
|
||||
import * as extHostTypes from 'vs/workbench/api/common/extHostTypes';
|
||||
import { addIdToOutput, CellEditType, ICellEditOperation, ICellReplaceEdit, INotebookEditData, notebookDocumentMetadataDefaults } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import * as vscode from 'vscode';
|
||||
|
@ -55,14 +55,14 @@ class NotebookEditorCellEditBuilder implements vscode.NotebookEditorEdit {
|
|||
});
|
||||
}
|
||||
|
||||
replaceCellOutput(index: number, outputs: (vscode.NotebookCellOutput | vscode.CellOutput)[]): void {
|
||||
replaceCellOutput(index: number, outputs: (vscode.NotebookCellOutputList | vscode.CellOutput)[]): void {
|
||||
this._throwIfFinalized();
|
||||
this._collectedEdits.push({
|
||||
editType: CellEditType.Output,
|
||||
index,
|
||||
outputs: outputs.map(output => {
|
||||
if (extHostTypes.NotebookCellOutput.isNotebookCellOutput(output)) {
|
||||
return addIdToOutput(NotebookCellOutput.from(output));
|
||||
if (extHostTypes.NotebookCellOutputList.isNotebookCellOutputList(output)) {
|
||||
return addIdToOutput(NotebookCellOutputList.from(output));
|
||||
} else {
|
||||
return addIdToOutput(output);
|
||||
}
|
||||
|
|
|
@ -1295,6 +1295,28 @@ export namespace LogLevel {
|
|||
}
|
||||
}
|
||||
|
||||
export namespace NotebookCellOutputList {
|
||||
export function from(output: types.NotebookCellOutputList): IDisplayOutput {
|
||||
|
||||
let data: { [key: string]: unknown; } = {};
|
||||
let custom: { [key: string]: unknown; } = {};
|
||||
let hasMetadata = false;
|
||||
|
||||
for (let item of output.outputs) {
|
||||
data[item.mime] = item.value;
|
||||
if (item.metadata) {
|
||||
custom[item.mime] = item.metadata;
|
||||
hasMetadata = true;
|
||||
}
|
||||
}
|
||||
return {
|
||||
outputKind: CellOutputKind.Rich,
|
||||
data,
|
||||
metadata: hasMetadata ? { custom } : undefined
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export namespace NotebookCellOutput {
|
||||
export function from(output: types.NotebookCellOutput): IDisplayOutput {
|
||||
return {
|
||||
|
|
|
@ -2785,6 +2785,18 @@ export class NotebookCellOutput {
|
|||
) { }
|
||||
}
|
||||
|
||||
export class NotebookCellOutputList {
|
||||
|
||||
static isNotebookCellOutputList(obj: unknown): obj is vscode.NotebookCellOutputList {
|
||||
return obj instanceof NotebookCellOutputList;
|
||||
}
|
||||
|
||||
constructor(
|
||||
readonly outputs: NotebookCellOutput[],
|
||||
readonly metadata?: Record<string, string | number | boolean>
|
||||
) { }
|
||||
}
|
||||
|
||||
export enum CellKind {
|
||||
Markdown = 1,
|
||||
Code = 2
|
||||
|
|
Loading…
Reference in a new issue