diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/notebook.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/notebook.test.ts index 293913f62a1..f3bc83e7fb3 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/notebook.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/notebook.test.ts @@ -61,13 +61,13 @@ class Kernel { task.executionOrder = 1; if (cell.notebook.uri.path.endsWith('customRenderer.vsctestnb')) { await task.replaceOutput([new vscode.NotebookCellOutput([ - vscode.NotebookCellOutputItem.text('test', 'text/custom', undefined) + vscode.NotebookCellOutputItem.text('test', 'text/custom') ])]); return; } await task.replaceOutput([new vscode.NotebookCellOutput([ - vscode.NotebookCellOutputItem.text('my output', 'text/plain', undefined) + vscode.NotebookCellOutputItem.text('my output', 'text/plain') ])]); task.end({ success: true }); } @@ -130,9 +130,12 @@ suite('Notebook API tests', function () { kind: vscode.NotebookCellKind.Code, outputs: [ new vscode.NotebookCellOutput([ - vscode.NotebookCellOutputItem.text('Hello World', 'text/plain', { testOutputItemMetadata: true }) + vscode.NotebookCellOutputItem.text('Hello World', 'text/plain') ], - { testOutputMetadata: true }) + { + testOutputMetadata: true, + ['text/plain']: { testOutputItemMetadata: true } + }) ], executionSummary: { executionOrder: 5, success: true }, metadata: new vscode.NotebookCellMetadata().with({ custom: { testCellMetadata: 456 } }) @@ -183,7 +186,7 @@ suite('Notebook API tests', function () { const task = this.controller.createNotebookCellExecution(cell); task.start(); await task.replaceOutput([new vscode.NotebookCellOutput([ - vscode.NotebookCellOutputItem.text('my second output', 'text/plain', undefined) + vscode.NotebookCellOutputItem.text('my second output', 'text/plain') ])]); task.end({ success: true }); } @@ -474,12 +477,11 @@ suite('Notebook API tests', function () { const secondCell = vscode.window.activeNotebookEditor!.document.cellAt(1); assert.strictEqual(secondCell!.outputs.length, 1); - assert.deepStrictEqual(secondCell!.outputs[0].metadata, { testOutputMetadata: true }); + assert.deepStrictEqual(secondCell!.outputs[0].metadata, { testOutputMetadata: true, ['text/plain']: { testOutputItemMetadata: true } }); assert.strictEqual((secondCell!.outputs[0]).outputs.length, 1); //todo@jrieken will FAIL once the backwards compatibility is gone assert.strictEqual(secondCell!.outputs[0].items.length, 1); assert.strictEqual(secondCell!.outputs[0].items[0].mime, 'text/plain'); assert.strictEqual(new TextDecoder().decode(secondCell!.outputs[0].items[0].data), 'Hello World'); - assert.deepStrictEqual(secondCell!.outputs[0].items[0].metadata, { testOutputItemMetadata: true }); assert.strictEqual(secondCell!.executionSummary?.executionOrder, 5); assert.strictEqual(secondCell!.executionSummary?.success, true); @@ -777,7 +779,7 @@ suite('Notebook API tests', function () { task.start(); task.token.onCancellationRequested(async () => { await task.replaceOutput([new vscode.NotebookCellOutput([ - vscode.NotebookCellOutputItem.text('Canceled', 'text/plain', undefined) + vscode.NotebookCellOutputItem.text('Canceled', 'text/plain') ])]); task.end({}); }); @@ -822,7 +824,7 @@ suite('Notebook API tests', function () { async interrupt() { await this._task!.replaceOutput([new vscode.NotebookCellOutput([ - vscode.NotebookCellOutputItem.text('Interrupted', 'text/plain', undefined) + vscode.NotebookCellOutputItem.text('Interrupted', 'text/plain') ])]); this._task!.end({}); } @@ -1182,7 +1184,7 @@ suite('Notebook API tests', function () { const task = this.controller.createNotebookCellExecution(cell); task.start(); await task.replaceOutput([new vscode.NotebookCellOutput([ - vscode.NotebookCellOutputItem.text('Some output', 'text/plain', undefined) + vscode.NotebookCellOutputItem.text('Some output', 'text/plain') ])]); assert.strictEqual(cell.notebook.cellAt(0).outputs.length, 1); assert.deepStrictEqual(new TextDecoder().decode(cell.notebook.cellAt(0).outputs[0].items[0].data), 'Some output'); diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index 2e4b0364460..7d724feffd1 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -11578,10 +11578,9 @@ declare module 'vscode' { * * @param value A string. * @param mime Optional MIME type, defaults to `text/plain`. - * @param metadata Optional metadata. * @returns A new output item object. */ - static text(value: string, mime?: string, metadata?: { [key: string]: any }): NotebookCellOutputItem; + static text(value: string, mime?: string): NotebookCellOutputItem; /** * Factory function to create a `NotebookCellOutputItem` from @@ -11593,40 +11592,36 @@ declare module 'vscode' { * * @param value A JSON-stringifyable value. * @param mime Optional MIME type, defaults to `application/json` - * @param metadata Optional metadata. * @returns A new output item object. */ - static json(value: any, mime?: string, metadata?: { [key: string]: any }): NotebookCellOutputItem; + static json(value: any, mime?: string): NotebookCellOutputItem; /** * Factory function to create a `NotebookCellOutputItem` that uses * uses the `application/vnd.code.notebook.stdout` mime type. * * @param value A string. - * @param metadata Optional metadata. * @returns A new output item object. */ - static stdout(value: string, metadata?: { [key: string]: any }): NotebookCellOutputItem; + static stdout(value: string): NotebookCellOutputItem; /** * Factory function to create a `NotebookCellOutputItem` that uses * uses the `application/vnd.code.notebook.stderr` mime type. * * @param value A string. - * @param metadata Optional metadata. * @returns A new output item object. */ - static stderr(value: string, metadata?: { [key: string]: any }): NotebookCellOutputItem; + static stderr(value: string): NotebookCellOutputItem; /** * Factory function to create a `NotebookCellOutputItem` that uses * uses the `application/vnd.code.notebook.error` mime type. * * @param value An error object. - * @param metadata Optional metadata. * @returns A new output item object. */ - static error(value: Error, metadata?: { [key: string]: any }): NotebookCellOutputItem; + static error(value: Error): NotebookCellOutputItem; /** * The mime type which determines how the {@link NotebookCellOutputItem.value `value`}-property @@ -11642,17 +11637,13 @@ declare module 'vscode' { */ data: Uint8Array; - //todo@API remove in favour of NotebookCellOutput#metadata - metadata?: { [key: string]: any }; - /** * Create a new notbook cell output item. * * @param data The value of the output item. * @param mime The mime type of the output item. - * @param metadata Optional metadata for this output item. */ - constructor(data: Uint8Array, mime: string, metadata?: { [key: string]: any }); + constructor(data: Uint8Array, mime: string); } /** @@ -11685,7 +11676,7 @@ declare module 'vscode' { items: NotebookCellOutputItem[]; /** - * Arbitrary metadata for this cell output. . + * Arbitrary metadata for this cell output. Can be anything but must be JSON-stringifyable. */ metadata?: { [key: string]: any }; diff --git a/src/vs/workbench/api/common/extHostTypeConverters.ts b/src/vs/workbench/api/common/extHostTypeConverters.ts index 2c5ca31f62a..d186b6cf851 100644 --- a/src/vs/workbench/api/common/extHostTypeConverters.ts +++ b/src/vs/workbench/api/common/extHostTypeConverters.ts @@ -1535,14 +1535,13 @@ export namespace NotebookCellData { export namespace NotebookCellOutputItem { export function from(item: types.NotebookCellOutputItem): notebooks.IOutputItemDto { return { - metadata: item.metadata, mime: item.mime, valueBytes: Array.from(item.data), //todo@jrieken this HACKY and SLOW... hoist VSBuffer instead }; } export function to(item: notebooks.IOutputItemDto): types.NotebookCellOutputItem { - return new types.NotebookCellOutputItem(new Uint8Array(item.valueBytes), item.mime, item.metadata); + return new types.NotebookCellOutputItem(new Uint8Array(item.valueBytes), item.mime); } } diff --git a/src/vs/workbench/api/common/extHostTypes.ts b/src/vs/workbench/api/common/extHostTypes.ts index 14bafd76896..37e48d92def 100644 --- a/src/vs/workbench/api/common/extHostTypes.ts +++ b/src/vs/workbench/api/common/extHostTypes.ts @@ -3116,43 +3116,42 @@ export class NotebookCellOutputItem { && (obj).data instanceof Uint8Array; } - static error(err: Error | { name: string, message?: string, stack?: string }, metadata?: { [key: string]: any }): NotebookCellOutputItem { + static error(err: Error | { name: string, message?: string, stack?: string }): NotebookCellOutputItem { const obj = { name: err.name, message: err.message, stack: err.stack }; - return NotebookCellOutputItem.json(obj, 'application/vnd.code.notebook.error', metadata); + return NotebookCellOutputItem.json(obj, 'application/vnd.code.notebook.error'); } - static stdout(value: string, metadata?: { [key: string]: any }): NotebookCellOutputItem { - return NotebookCellOutputItem.text(value, 'application/vnd.code.notebook.stdout', metadata); + static stdout(value: string): NotebookCellOutputItem { + return NotebookCellOutputItem.text(value, 'application/vnd.code.notebook.stdout'); } - static stderr(value: string, metadata?: { [key: string]: any }): NotebookCellOutputItem { - return NotebookCellOutputItem.text(value, 'application/vnd.code.notebook.stderr', metadata); + static stderr(value: string): NotebookCellOutputItem { + return NotebookCellOutputItem.text(value, 'application/vnd.code.notebook.stderr'); } - static bytes(value: Uint8Array, mime: string = 'application/octet-stream', metadata?: { [key: string]: any }): NotebookCellOutputItem { - return new NotebookCellOutputItem(value, mime, metadata); + static bytes(value: Uint8Array, mime: string = 'application/octet-stream'): NotebookCellOutputItem { + return new NotebookCellOutputItem(value, mime); } static #encoder = new TextEncoder(); - static text(value: string, mime: string = 'text/plain', metadata?: { [key: string]: any }): NotebookCellOutputItem { + static text(value: string, mime: string = 'text/plain'): NotebookCellOutputItem { const bytes = NotebookCellOutputItem.#encoder.encode(String(value)); - return new NotebookCellOutputItem(bytes, mime, metadata); + return new NotebookCellOutputItem(bytes, mime); } - static json(value: any, mime: string = 'application/json', metadata?: { [key: string]: any }): NotebookCellOutputItem { + static json(value: any, mime: string = 'application/json'): NotebookCellOutputItem { const rawStr = JSON.stringify(value, undefined, '\t'); - return NotebookCellOutputItem.text(rawStr, mime, metadata); + return NotebookCellOutputItem.text(rawStr, mime); } constructor( public data: Uint8Array, public mime: string, - public metadata?: { [key: string]: any } ) { const mimeNormalized = normalizeMimeType(mime, true); if (!mimeNormalized) { diff --git a/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts b/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts index 2071be77e6f..577e01f2045 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts @@ -1523,7 +1523,7 @@ var requirejs = (function() { outputId: output.outputId, mimeType: content.mimeType, valueBytes: new Uint8Array(outputDto?.valueBytes ?? []), - metadata: outputDto?.metadata, + metadata: output.metadata, metadata2: output.metadata }, }; diff --git a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts index a56c0f70456..d0ce1ca8713 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts @@ -174,7 +174,6 @@ export interface IOrderedMimeType { export interface IOutputItemDto { readonly mime: string; readonly valueBytes: number[]; - readonly metadata?: Record; } export interface IOutputDto { diff --git a/src/vs/workbench/test/browser/api/extHostTypeConverter.test.ts b/src/vs/workbench/test/browser/api/extHostTypeConverter.test.ts index 9b9e68a2778..e766008f374 100644 --- a/src/vs/workbench/test/browser/api/extHostTypeConverter.test.ts +++ b/src/vs/workbench/test/browser/api/extHostTypeConverter.test.ts @@ -96,7 +96,6 @@ suite('ExtHostTypeConverter', function () { const item2 = NotebookCellOutputItem.to(dto); assert.strictEqual(item2.mime, item.mime); - assert.strictEqual(item2.metadata, item.metadata); assert.deepStrictEqual(item2.data, item.data); }); });