From 9ef57b5c216fc98d65290668b3a67e45440ae10d Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Thu, 27 May 2021 14:55:25 +0200 Subject: [PATCH] remove NotebookCellOutputItem#value, https://github.com/microsoft/vscode/issues/123884 --- .../notebook/index.ts | 2 +- src/vs/vscode.proposed.d.ts | 8 +- .../api/common/extHostTypeConverters.ts | 19 +--- src/vs/workbench/api/common/extHostTypes.ts | 10 +-- .../view/output/transforms/richTransform.ts | 86 ++----------------- .../view/renderers/backLayerWebView.ts | 3 +- .../browser/view/renderers/webviewPreloads.ts | 6 +- .../contrib/notebook/common/notebookCommon.ts | 4 +- .../notebook/test/notebookDiff.test.ts | 28 +++--- .../notebook/test/notebookTextModel.test.ts | 45 +++++----- .../api/extHostNotebookKernel2.test.ts | 4 +- .../browser/api/extHostTypeConverter.test.ts | 2 - 12 files changed, 58 insertions(+), 159 deletions(-) diff --git a/extensions/markdown-language-features/notebook/index.ts b/extensions/markdown-language-features/notebook/index.ts index cecde581a9f..5ae7c219763 100644 --- a/extensions/markdown-language-features/notebook/index.ts +++ b/extensions/markdown-language-features/notebook/index.ts @@ -12,7 +12,7 @@ export function activate() { return { renderCell: (_id: string, context: { element: HTMLElement, value: string, text(): string }) => { - const rendered = markdownIt.render(context.value || context.text()); // todo@jrieken remove .value-usage + const rendered = markdownIt.render(context.text()); context.element.innerHTML = rendered; // Insert styles into markdown preview shadow dom so that they are applied diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index f024fc3a3f0..837ef3b7555 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -1316,11 +1316,6 @@ declare module 'vscode' { */ data: Uint8Array; - /** - * @deprecated - */ - value: unknown; - //todo@API metadata?: { [key: string]: any }; @@ -1520,8 +1515,9 @@ declare module 'vscode' { Preferred = 2 } - // todo@API this is called Controller + // todo@API rename to NotebookRendererScript export class NotebookKernelPreload { + /** * APIs that the preload provides to the renderer. These are matched * against the `dependencies` and `optionalDependencies` arrays in the diff --git a/src/vs/workbench/api/common/extHostTypeConverters.ts b/src/vs/workbench/api/common/extHostTypeConverters.ts index 9cb1fd3f72f..fade387e3fe 100644 --- a/src/vs/workbench/api/common/extHostTypeConverters.ts +++ b/src/vs/workbench/api/common/extHostTypeConverters.ts @@ -1534,30 +1534,15 @@ export namespace NotebookCellData { export namespace NotebookCellOutputItem { export function from(item: types.NotebookCellOutputItem): notebooks.IOutputItemDto { - let value: unknown; - let valueBytes: number[] | undefined; - if (item.data instanceof Uint8Array) { - //todo@jrieken this HACKY and SLOW... hoist VSBuffer instead - valueBytes = Array.from(item.data); - } else { - value = item.value; - } return { metadata: item.metadata, mime: item.mime, - value, - valueBytes, + valueBytes: Array.from(item.data), //todo@jrieken this HACKY and SLOW... hoist VSBuffer instead }; } export function to(item: notebooks.IOutputItemDto): types.NotebookCellOutputItem { - let value: Uint8Array | any; - if (Array.isArray(item.valueBytes)) { - value = new Uint8Array(item.valueBytes); - } else { - value = item.value; - } - return new types.NotebookCellOutputItem(value, item.mime, item.metadata); + return new types.NotebookCellOutputItem(new Uint8Array(item.valueBytes), item.mime, item.metadata); } } diff --git a/src/vs/workbench/api/common/extHostTypes.ts b/src/vs/workbench/api/common/extHostTypes.ts index cb45ef3fce5..7f0bcb9fc0f 100644 --- a/src/vs/workbench/api/common/extHostTypes.ts +++ b/src/vs/workbench/api/common/extHostTypes.ts @@ -3112,7 +3112,8 @@ export class NotebookCellOutputItem { if (!obj) { return false; } - return typeof (obj).mime === 'string'; + return typeof (obj).mime === 'string' + && (obj).data instanceof Uint8Array; } static error(err: Error | { name: string, message?: string, stack?: string }, metadata?: { [key: string]: any }): NotebookCellOutputItem { @@ -3148,18 +3149,11 @@ export class NotebookCellOutputItem { return NotebookCellOutputItem.text(rawStr, mime, metadata); } - /** @deprecated */ - public value: Uint8Array | unknown; // JSON'able - constructor( public data: Uint8Array, public mime: string, public metadata?: { [key: string]: any } ) { - if (!(data instanceof Uint8Array)) { - this.value = data; - } - const mimeNormalized = normalizeMimeType(mime, true); if (!mimeNormalized) { throw new Error('INVALID mime type, must not be empty or falsy: ' + mime); diff --git a/src/vs/workbench/contrib/notebook/browser/view/output/transforms/richTransform.ts b/src/vs/workbench/contrib/notebook/browser/view/output/transforms/richTransform.ts index 60c40a9e613..589f638644c 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/output/transforms/richTransform.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/output/transforms/richTransform.ts @@ -6,7 +6,6 @@ import * as DOM from 'vs/base/browser/dom'; import { Disposable, DisposableStore, toDisposable } from 'vs/base/common/lifecycle'; import { dirname } from 'vs/base/common/resources'; -import { isArray } from 'vs/base/common/types'; import { URI } from 'vs/base/common/uri'; import { MarkdownRenderer } from 'vs/editor/browser/core/markdownRenderer'; import { IEditorConstructionOptions } from 'vs/editor/browser/editorBrowser'; @@ -109,14 +108,7 @@ class JSONRendererContrib extends CodeRendererContrib { } override render(output: ICellOutputViewModel, items: IOutputItemDto[], container: HTMLElement): IRenderOutput { - const str = items.map(item => { - if (isArray(item.valueBytes)) { - return getStringValue(item); - } else { - return JSON.stringify(item.value, null, '\t'); - } - }).join(''); - + const str = items.map(getStringValue).join(''); return this._render(output, container, str, 'jsonc'); } } @@ -170,57 +162,6 @@ class StderrRendererContrib extends StreamRendererContrib { } } -/** @deprecated */ -class ErrorRendererContrib extends Disposable implements IOutputRendererContribution { - getType() { - return RenderOutputType.Mainframe; - } - - getMimetypes() { - return ['application/x.notebook.error-traceback']; - } - - constructor( - public notebookEditor: ICommonNotebookEditor, - @IThemeService private readonly themeService: IThemeService, - @IInstantiationService private readonly instantiationService: IInstantiationService, - - ) { - super(); - } - - render(output: ICellOutputViewModel, items: IOutputItemDto[], container: HTMLElement, notebookUri: URI): IRenderOutput { - const linkDetector = this.instantiationService.createInstance(LinkDetector); - items.forEach(item => { - const data: any = item.value; - const header = document.createElement('div'); - const headerMessage = data.ename && data.evalue - ? `${data.ename}: ${data.evalue}` - : data.ename || data.evalue; - if (headerMessage) { - header.innerText = headerMessage; - container.appendChild(header); - } - const traceback = document.createElement('pre'); - traceback.classList.add('traceback'); - if (data.traceback) { - for (let j = 0; j < data.traceback.length; j++) { - traceback.appendChild(handleANSIOutput(data.traceback[j], linkDetector, this.themeService, undefined)); - } - } - container.appendChild(traceback); - container.classList.add('error'); - return { type: RenderOutputType.Mainframe }; - - }); - - return { type: RenderOutputType.Mainframe }; - } - - _render() { - } -} - class JSErrorRendererContrib implements IOutputRendererContribution { constructor( @@ -381,17 +322,10 @@ class ImgRendererContrib extends Disposable implements IOutputRendererContributi for (let item of items) { - let src: string; - if (Array.isArray(item.valueBytes)) { - const bytes = new Uint8Array(item.valueBytes); - const blob = new Blob([bytes], { type: item.mime }); - src = URL.createObjectURL(blob); - disposable.add(toDisposable(() => URL.revokeObjectURL(src))); - } else { - // OLD - const imagedata = item.value; - src = `data:${item.mime};base64,${imagedata}`; - } + const bytes = new Uint8Array(item.valueBytes); + const blob = new Blob([bytes], { type: item.mime }); + const src = URL.createObjectURL(blob); + disposable.add(toDisposable(() => URL.revokeObjectURL(src))); const image = document.createElement('img'); image.src = src; @@ -414,17 +348,11 @@ OutputRendererRegistry.registerOutputTransform(CodeRendererContrib); OutputRendererRegistry.registerOutputTransform(JSErrorRendererContrib); OutputRendererRegistry.registerOutputTransform(StreamRendererContrib); OutputRendererRegistry.registerOutputTransform(StderrRendererContrib); -OutputRendererRegistry.registerOutputTransform(ErrorRendererContrib); // --- utils --- function getStringValue(item: IOutputItemDto): string { - if (Array.isArray(item.valueBytes)) { - // todo@jrieken NOT proper, should be VSBuffer - return new TextDecoder().decode(new Uint8Array(item.valueBytes)); - } else { - // "old" world - return Array.isArray(item.value) ? item.value.join('') : String(item.value); - } + // todo@jrieken NOT proper, should be VSBuffer + return new TextDecoder().decode(new Uint8Array(item.valueBytes)); } function getOutputSimpleEditorOptions(): IEditorConstructionOptions { 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 6c31eb26680..febd9112487 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts @@ -192,7 +192,7 @@ export interface ICreationRequestMessage { type: 'html'; content: | { type: RenderOutputType.Html; htmlContent: string } - | { type: RenderOutputType.Extension; outputId: string; value: unknown; valueBytes: Uint8Array, metadata: unknown; mimeType: string }; + | { type: RenderOutputType.Extension; outputId: string; valueBytes: Uint8Array, metadata: unknown; mimeType: string }; cellId: string; outputId: string; cellTop: number; @@ -1513,7 +1513,6 @@ var requirejs = (function() { type: RenderOutputType.Extension, outputId: output.outputId, mimeType: content.mimeType, - value: outputDto?.value, valueBytes: new Uint8Array(outputDto?.valueBytes ?? []), metadata: outputDto?.metadata, }, diff --git a/src/vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.ts b/src/vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.ts index ff86aa25c5f..d3ce5beb2cd 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.ts @@ -463,7 +463,6 @@ async function webviewPreloads(style: PreloadStyles, options: PreloadOptions, re outputId?: string; mime: string; - value: unknown; metadata: unknown; text(): string; @@ -643,15 +642,13 @@ async function webviewPreloads(style: PreloadStyles, options: PreloadOptions, re rendererApi.renderCell(outputId, { element: outputNode, mime: content.mimeType, - value: content.value, metadata: content.metadata, data() { return content.valueBytes; }, bytes() { return this.data(); }, text() { - return new TextDecoder().decode(content.valueBytes) - || String(content.value); //todo@jrieken remove this once `value` is gone! + return new TextDecoder().decode(content.valueBytes); }, json() { return JSON.parse(this.text()); @@ -1037,7 +1034,6 @@ async function webviewPreloads(style: PreloadStyles, options: PreloadOptions, re markdownRenderers[0].api?.renderCell(id, { element, - value: content, mime: 'text/markdown', metadata: undefined, outputId: undefined, diff --git a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts index de639c6c2a9..42bae022971 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts @@ -173,8 +173,7 @@ export interface IOrderedMimeType { export interface IOutputItemDto { readonly mime: string; - readonly value: unknown; - readonly valueBytes?: number[]; + readonly valueBytes: number[]; readonly metadata?: Record; } @@ -603,7 +602,6 @@ const _mimeTypeInfo = new Map([ ['application/x.notebook.stdout', { alwaysSecure: true, supportedByCore: true, mergeable: true }], ['application/x.notebook.stderr', { alwaysSecure: true, supportedByCore: true, mergeable: true }], ['application/x.notebook.stream', { alwaysSecure: true, supportedByCore: true, mergeable: true }], // deprecated - ['application/x.notebook.error-traceback', { alwaysSecure: true, supportedByCore: true }], // deprecated ]); export function mimeTypeIsAlwaysSecure(mimeType: string): boolean { diff --git a/src/vs/workbench/contrib/notebook/test/notebookDiff.test.ts b/src/vs/workbench/contrib/notebook/test/notebookDiff.test.ts index 724ff468ed0..3e612b388c9 100644 --- a/src/vs/workbench/contrib/notebook/test/notebookDiff.test.ts +++ b/src/vs/workbench/contrib/notebook/test/notebookDiff.test.ts @@ -14,9 +14,9 @@ suite('NotebookCommon', () => { test('diff different source', async () => { await withTestNotebookDiffModel([ - ['x', 'javascript', CellKind.Code, [{ outputId: 'someOtherId', outputs: [{ mime: 'text/plain', value: '3' }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 3 }], + ['x', 'javascript', CellKind.Code, [{ outputId: 'someOtherId', outputs: [{ mime: 'text/plain', valueBytes: [3] }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 3 }], ], [ - ['y', 'javascript', CellKind.Code, [{ outputId: 'someOtherId', outputs: [{ mime: 'text/plain', value: '3' }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 3 }], + ['y', 'javascript', CellKind.Code, [{ outputId: 'someOtherId', outputs: [{ mime: 'text/plain', valueBytes: [3] }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 3 }], ], (model, accessor) => { const diff = new LcsDiff(new CellSequence(model.original.notebook), new CellSequence(model.modified.notebook)); const diffResult = diff.ComputeDiff(false); @@ -44,10 +44,10 @@ suite('NotebookCommon', () => { test('diff different output', async () => { await withTestNotebookDiffModel([ - ['x', 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', value: '5' }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 5 }], + ['x', 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', valueBytes: [5] }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 5 }], ['', 'javascript', CellKind.Code, [], {}] ], [ - ['x', 'javascript', CellKind.Code, [{ outputId: 'someOtherId', outputs: [{ mime: 'text/plain', value: '3' }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 3 }], + ['x', 'javascript', CellKind.Code, [{ outputId: 'someOtherId', outputs: [{ mime: 'text/plain', valueBytes: [3] }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 3 }], ['', 'javascript', CellKind.Code, [], {}] ], (model, accessor) => { const diff = new LcsDiff(new CellSequence(model.original.notebook), new CellSequence(model.modified.notebook)); @@ -145,12 +145,12 @@ suite('NotebookCommon', () => { test('diff foo/foe', async () => { await withTestNotebookDiffModel([ - [['def foe(x, y):\n', ' return x + y\n', 'foe(3, 2)'].join(''), 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', value: '6' }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 5 }], - [['def foo(x, y):\n', ' return x * y\n', 'foo(1, 2)'].join(''), 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', value: '2' }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 6 }], + [['def foe(x, y):\n', ' return x + y\n', 'foe(3, 2)'].join(''), 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', valueBytes: [6] }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 5 }], + [['def foo(x, y):\n', ' return x * y\n', 'foo(1, 2)'].join(''), 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', valueBytes: [2] }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 6 }], ['', 'javascript', CellKind.Code, [], {}] ], [ - [['def foo(x, y):\n', ' return x * y\n', 'foo(1, 2)'].join(''), 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', value: '6' }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 5 }], - [['def foe(x, y):\n', ' return x + y\n', 'foe(3, 2)'].join(''), 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', value: '2' }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 6 }], + [['def foo(x, y):\n', ' return x * y\n', 'foo(1, 2)'].join(''), 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', valueBytes: [6] }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 5 }], + [['def foe(x, y):\n', ' return x + y\n', 'foe(3, 2)'].join(''), 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', valueBytes: [2] }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 6 }], ['', 'javascript', CellKind.Code, [], {}] ], (model, accessor) => { const diff = new LcsDiff(new CellSequence(model.original.notebook), new CellSequence(model.modified.notebook)); @@ -272,13 +272,13 @@ suite('NotebookCommon', () => { await withTestNotebookDiffModel([ ['# Description', 'markdown', CellKind.Markup, [], { custom: { metadata: {} } }], ['x = 3', 'javascript', CellKind.Code, [], { custom: { metadata: { collapsed: true } }, executionOrder: 1 }], - ['x', 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', value: '3' }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 1 }], + ['x', 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', valueBytes: [3] }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 1 }], ['x', 'javascript', CellKind.Code, [], { custom: { metadata: { collapsed: false } } }] ], [ ['# Description', 'markdown', CellKind.Markup, [], { custom: { metadata: {} } }], ['x = 3', 'javascript', CellKind.Code, [], { custom: { metadata: { collapsed: true } }, executionOrder: 1 }], ['x', 'javascript', CellKind.Code, [], { custom: { metadata: { collapsed: false } } }], - ['x', 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', value: '3' }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 1 }] + ['x', 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', valueBytes: [3] }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 1 }] ], async (model) => { const diff = new LcsDiff(new CellSequence(model.original.notebook), new CellSequence(model.modified.notebook)); const diffResult = diff.ComputeDiff(false); @@ -305,18 +305,18 @@ suite('NotebookCommon', () => { await withTestNotebookDiffModel([ ['# Description', 'markdown', CellKind.Markup, [], { custom: { metadata: {} } }], ['x = 3', 'javascript', CellKind.Code, [], { custom: { metadata: { collapsed: true } }, executionOrder: 1 }], - ['x', 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', value: '3' }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 1 }], + ['x', 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', valueBytes: [3] }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 1 }], ['x', 'javascript', CellKind.Code, [], { custom: { metadata: { collapsed: false } } }], ['x = 5', 'javascript', CellKind.Code, [], {}], ['x', 'javascript', CellKind.Code, [], {}], - ['x', 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', value: '5' }] }], {}], + ['x', 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', valueBytes: [5] }] }], {}], ], [ ['# Description', 'markdown', CellKind.Markup, [], { custom: { metadata: {} } }], ['x = 3', 'javascript', CellKind.Code, [], { custom: { metadata: { collapsed: true } }, executionOrder: 1 }], ['x', 'javascript', CellKind.Code, [], { custom: { metadata: { collapsed: false } } }], - ['x', 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', value: '3' }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 1 }], + ['x', 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', valueBytes: [3] }] }], { custom: { metadata: { collapsed: false } }, executionOrder: 1 }], ['x = 5', 'javascript', CellKind.Code, [], {}], - ['x', 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', value: '5' }] }], {}], + ['x', 'javascript', CellKind.Code, [{ outputId: 'someId', outputs: [{ mime: 'text/plain', valueBytes: [5] }] }], {}], ['x', 'javascript', CellKind.Code, [], {}], ], async (model) => { const diff = new LcsDiff(new CellSequence(model.original.notebook), new CellSequence(model.modified.notebook)); diff --git a/src/vs/workbench/contrib/notebook/test/notebookTextModel.test.ts b/src/vs/workbench/contrib/notebook/test/notebookTextModel.test.ts index 59bb65360de..3e799efe395 100644 --- a/src/vs/workbench/contrib/notebook/test/notebookTextModel.test.ts +++ b/src/vs/workbench/contrib/notebook/test/notebookTextModel.test.ts @@ -10,6 +10,11 @@ import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo'; import { IModeService } from 'vs/editor/common/services/modeService'; suite('NotebookTextModel', () => { + + function valueBytesFromString(value: string) { + return Array.from(new TextEncoder().encode(value)); + } + const instantiationService = setupInstantiationService(); const modeService = instantiationService.get(IModeService); instantiationService.spy(IUndoRedoService, 'pushElement'); @@ -184,7 +189,7 @@ suite('NotebookTextModel', () => { editType: CellEditType.Output, outputs: [{ outputId: 'someId', - outputs: [{ mime: 'text/markdown', value: '_Hello_' }] + outputs: [{ mime: 'text/markdown', valueBytes: valueBytesFromString('_Hello_') }] }] }], true, undefined, () => undefined, undefined); @@ -198,7 +203,7 @@ suite('NotebookTextModel', () => { append: true, outputs: [{ outputId: 'someId2', - outputs: [{ mime: 'text/markdown', value: '_Hello2_' }] + outputs: [{ mime: 'text/markdown', valueBytes: valueBytesFromString('_Hello2_') }] }] }], true, undefined, () => undefined, undefined); @@ -214,7 +219,7 @@ suite('NotebookTextModel', () => { editType: CellEditType.Output, outputs: [{ outputId: 'someId3', - outputs: [{ mime: 'text/plain', value: 'Last, replaced output' }] + outputs: [{ mime: 'text/plain', valueBytes: valueBytesFromString('Last, replaced output') }] }] }], true, undefined, () => undefined, undefined); @@ -242,7 +247,7 @@ suite('NotebookTextModel', () => { append: true, outputs: [{ outputId: 'append1', - outputs: [{ mime: 'text/markdown', value: 'append 1' }] + outputs: [{ mime: 'text/markdown', valueBytes: valueBytesFromString('append 1') }] }] }, { @@ -251,7 +256,7 @@ suite('NotebookTextModel', () => { append: true, outputs: [{ outputId: 'append2', - outputs: [{ mime: 'text/markdown', value: 'append 2' }] + outputs: [{ mime: 'text/markdown', valueBytes: valueBytesFromString('append 2') }] }] } ], true, undefined, () => undefined, undefined); @@ -418,7 +423,7 @@ suite('NotebookTextModel', () => { const success1 = model.applyEdits( [{ editType: CellEditType.Output, index: 0, outputs: [ - { outputId: 'out1', outputs: [{ mime: 'application/x.notebook.stream', value: 1 }] } + { outputId: 'out1', outputs: [{ mime: 'application/x.notebook.stream', valueBytes: [1] }] } ], append: false }], true, undefined, () => undefined, undefined, false @@ -430,7 +435,7 @@ suite('NotebookTextModel', () => { const success2 = model.applyEdits( [{ editType: CellEditType.Output, index: 0, outputs: [ - { outputId: 'out2', outputs: [{ mime: 'application/x.notebook.stream', value: 1 }] } + { outputId: 'out2', outputs: [{ mime: 'application/x.notebook.stream', valueBytes: [1] }] } ], append: true }], true, undefined, () => undefined, undefined, false @@ -457,7 +462,7 @@ suite('NotebookTextModel', () => { const success = model.applyEdits( [{ editType: CellEditType.Output, index: 0, outputs: [ - { outputId: 'out1', outputs: [{ mime: 'application/x.notebook.stream', value: 1 }] } + { outputId: 'out1', outputs: [{ mime: 'application/x.notebook.stream', valueBytes: [1] }] } ], append: false }], true, undefined, () => undefined, undefined, false @@ -563,14 +568,14 @@ suite('NotebookTextModel', () => { test('Destructive sorting in _doApplyEdits #121994', async function () { await withTestNotebook([ - ['var a = 1;', 'javascript', CellKind.Code, [{ outputId: 'i42', outputs: [{ mime: 'm/ime', value: 'test' }] }], {}] + ['var a = 1;', 'javascript', CellKind.Code, [{ outputId: 'i42', outputs: [{ mime: 'm/ime', valueBytes: valueBytesFromString('test') }] }], {}] ], async (editor) => { const notebook = editor.viewModel.notebookDocument; assert.strictEqual(notebook.cells[0].outputs.length, 1); assert.strictEqual(notebook.cells[0].outputs[0].outputs.length, 1); - assert.strictEqual(notebook.cells[0].outputs[0].outputs[0].value, 'test'); + assert.deepStrictEqual(notebook.cells[0].outputs[0].outputs[0].valueBytes, valueBytesFromString('test')); const edits: ICellEditOperation[] = [ { @@ -579,7 +584,7 @@ suite('NotebookTextModel', () => { { editType: CellEditType.Output, handle: 0, append: true, outputs: [{ outputId: 'newOutput', - outputs: [{ mime: 'text/plain', value: 'cba' }, { mime: 'application/foo', value: 'cba' }] + outputs: [{ mime: 'text/plain', valueBytes: valueBytesFromString('cba') }, { mime: 'application/foo', valueBytes: valueBytesFromString('cba') }] }] } ]; @@ -593,9 +598,9 @@ suite('NotebookTextModel', () => { test('Destructive sorting in _doApplyEdits #121994. cell splice between output changes', async function () { await withTestNotebook([ - ['var a = 1;', 'javascript', CellKind.Code, [{ outputId: 'i42', outputs: [{ mime: 'm/ime', value: 'test' }] }], {}], - ['var b = 2;', 'javascript', CellKind.Code, [{ outputId: 'i43', outputs: [{ mime: 'm/ime', value: 'test' }] }], {}], - ['var c = 3;', 'javascript', CellKind.Code, [{ outputId: 'i44', outputs: [{ mime: 'm/ime', value: 'test' }] }], {}] + ['var a = 1;', 'javascript', CellKind.Code, [{ outputId: 'i42', outputs: [{ mime: 'm/ime', valueBytes: valueBytesFromString('test') }] }], {}], + ['var b = 2;', 'javascript', CellKind.Code, [{ outputId: 'i43', outputs: [{ mime: 'm/ime', valueBytes: valueBytesFromString('test') }] }], {}], + ['var c = 3;', 'javascript', CellKind.Code, [{ outputId: 'i44', outputs: [{ mime: 'm/ime', valueBytes: valueBytesFromString('test') }] }], {}] ], async (editor) => { const notebook = editor.viewModel.notebookDocument; @@ -609,7 +614,7 @@ suite('NotebookTextModel', () => { { editType: CellEditType.Output, index: 2, append: true, outputs: [{ outputId: 'newOutput', - outputs: [{ mime: 'text/plain', value: 'cba' }, { mime: 'application/foo', value: 'cba' }] + outputs: [{ mime: 'text/plain', valueBytes: valueBytesFromString('cba') }, { mime: 'application/foo', valueBytes: valueBytesFromString('cba') }] }] } ]; @@ -626,9 +631,9 @@ suite('NotebookTextModel', () => { test('Destructive sorting in _doApplyEdits #121994. cell splice between output changes 2', async function () { await withTestNotebook([ - ['var a = 1;', 'javascript', CellKind.Code, [{ outputId: 'i42', outputs: [{ mime: 'm/ime', value: 'test' }] }], {}], - ['var b = 2;', 'javascript', CellKind.Code, [{ outputId: 'i43', outputs: [{ mime: 'm/ime', value: 'test' }] }], {}], - ['var c = 3;', 'javascript', CellKind.Code, [{ outputId: 'i44', outputs: [{ mime: 'm/ime', value: 'test' }] }], {}] + ['var a = 1;', 'javascript', CellKind.Code, [{ outputId: 'i42', outputs: [{ mime: 'm/ime', valueBytes: valueBytesFromString('test') }] }], {}], + ['var b = 2;', 'javascript', CellKind.Code, [{ outputId: 'i43', outputs: [{ mime: 'm/ime', valueBytes: valueBytesFromString('test') }] }], {}], + ['var c = 3;', 'javascript', CellKind.Code, [{ outputId: 'i44', outputs: [{ mime: 'm/ime', valueBytes: valueBytesFromString('test') }] }], {}] ], async (editor) => { const notebook = editor.viewModel.notebookDocument; @@ -636,7 +641,7 @@ suite('NotebookTextModel', () => { { editType: CellEditType.Output, index: 1, append: true, outputs: [{ outputId: 'newOutput', - outputs: [{ mime: 'text/plain', value: 'cba' }, { mime: 'application/foo', value: 'cba' }] + outputs: [{ mime: 'text/plain', valueBytes: valueBytesFromString('cba') }, { mime: 'application/foo', valueBytes: valueBytesFromString('cba') }] }] }, { @@ -645,7 +650,7 @@ suite('NotebookTextModel', () => { { editType: CellEditType.Output, index: 1, append: true, outputs: [{ outputId: 'newOutput2', - outputs: [{ mime: 'text/plain', value: 'cba' }, { mime: 'application/foo', value: 'cba' }] + outputs: [{ mime: 'text/plain', valueBytes: valueBytesFromString('cba') }, { mime: 'application/foo', valueBytes: valueBytesFromString('cba') }] }] } ]; diff --git a/src/vs/workbench/test/browser/api/extHostNotebookKernel2.test.ts b/src/vs/workbench/test/browser/api/extHostNotebookKernel2.test.ts index 7d5949f2f08..742118b48d0 100644 --- a/src/vs/workbench/test/browser/api/extHostNotebookKernel2.test.ts +++ b/src/vs/workbench/test/browser/api/extHostNotebookKernel2.test.ts @@ -223,10 +223,10 @@ suite('NotebookKernel', function () { await extHostNotebookKernels.$cancelCells(0, notebook.uri, [0]); assert.strictEqual(interruptCallCount, 1); - assert.strictEqual(tokenCancelCount, 1); + assert.strictEqual(tokenCancelCount, 0); await extHostNotebookKernels.$cancelCells(0, notebook.uri, [0]); assert.strictEqual(interruptCallCount, 2); - assert.strictEqual(tokenCancelCount, 1); + assert.strictEqual(tokenCancelCount, 0); }); }); diff --git a/src/vs/workbench/test/browser/api/extHostTypeConverter.test.ts b/src/vs/workbench/test/browser/api/extHostTypeConverter.test.ts index 324cdd3c071..9b9e68a2778 100644 --- a/src/vs/workbench/test/browser/api/extHostTypeConverter.test.ts +++ b/src/vs/workbench/test/browser/api/extHostTypeConverter.test.ts @@ -91,14 +91,12 @@ suite('ExtHostTypeConverter', function () { assert.strictEqual(dto.mime, 'foo/bar'); assert.strictEqual(dto.metadata, undefined); - assert.strictEqual(dto.value, undefined); assert.deepStrictEqual(dto.valueBytes, Array.from(new TextEncoder().encode('Hello'))); const item2 = NotebookCellOutputItem.to(dto); assert.strictEqual(item2.mime, item.mime); assert.strictEqual(item2.metadata, item.metadata); - assert.strictEqual(item2.value, item.value); assert.deepStrictEqual(item2.data, item.data); }); });