mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 13:29:44 +00:00
remove NotebookCellOutputItem#value, https://github.com/microsoft/vscode/issues/123884
This commit is contained in:
parent
da1193950a
commit
9ef57b5c21
|
@ -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
|
||||
|
|
8
src/vs/vscode.proposed.d.ts
vendored
8
src/vs/vscode.proposed.d.ts
vendored
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3112,7 +3112,8 @@ export class NotebookCellOutputItem {
|
|||
if (!obj) {
|
||||
return false;
|
||||
}
|
||||
return typeof (<vscode.NotebookCellOutputItem>obj).mime === 'string';
|
||||
return typeof (<vscode.NotebookCellOutputItem>obj).mime === 'string'
|
||||
&& (<vscode.NotebookCellOutputItem>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);
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<string, unknown>;
|
||||
}
|
||||
|
||||
|
@ -603,7 +602,6 @@ const _mimeTypeInfo = new Map<string, MimeTypeInfo>([
|
|||
['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 {
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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') }]
|
||||
}]
|
||||
}
|
||||
];
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue