Skip to content

Commit 807eb37

Browse files
committed
make sure replaceOutput updates the extension host side, update tests #105283
1 parent a3f414c commit 807eb37

File tree

6 files changed

+57
-31
lines changed

6 files changed

+57
-31
lines changed

extensions/vscode-notebook-tests/src/notebook.test.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,6 @@ suite('Notebook API tests', () => {
418418
});
419419

420420
test('edit API (replaceOutput)', async function () {
421-
// no output events yet...
422-
this.skip();
423-
424421
assertInitalState();
425422
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
426423
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
@@ -430,7 +427,7 @@ suite('Notebook API tests', () => {
430427
});
431428

432429
const document = vscode.notebook.activeNotebookEditor?.document!;
433-
assert.strictEqual(document.isDirty, false);
430+
assert.strictEqual(document.isDirty, true);
434431
assert.strictEqual(document.cells.length, 1);
435432
assert.strictEqual(document.cells[0].outputs.length, 1);
436433
assert.strictEqual(document.cells[0].outputs[0].outputKind, vscode.CellOutputKind.Rich);
@@ -439,9 +436,6 @@ suite('Notebook API tests', () => {
439436
});
440437

441438
test('edit API (replaceOutput, event)', async function () {
442-
// no output events yet...
443-
this.skip();
444-
445439
assertInitalState();
446440
const resource = await createRandomFile('', undefined, 'first', '.vsctestnb');
447441
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
@@ -453,6 +447,7 @@ suite('Notebook API tests', () => {
453447

454448
const value = await outputChangeEvent;
455449
assert.strictEqual(value.document === vscode.notebook.activeNotebookEditor?.document, true);
450+
assert.strictEqual(value.document.isDirty, true);
456451
assert.strictEqual(value.cells.length, 1);
457452
assert.strictEqual(value.cells[0].outputs.length, 1);
458453
assert.strictEqual(value.cells[0].outputs[0].outputKind, vscode.CellOutputKind.Rich);

src/vs/workbench/api/common/extHostNotebook.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ export class ExtHostCell extends Disposable {
139139
this._onDidDispose.fire();
140140
}
141141

142+
setOutputs(newOutputs: vscode.CellOutput[]): void {
143+
this._outputs = newOutputs;
144+
}
145+
142146
private _updateOutputs(newOutputs: vscode.CellOutput[]) {
143147
const rawDiffs = diff<vscode.CellOutput>(this._outputs || [], newOutputs || [], (a) => {
144148
return this._outputMapping.has(a);
@@ -321,6 +325,8 @@ export class ExtHostNotebookDocument extends Disposable {
321325
this._spliceNotebookCells(event.changes, false);
322326
} else if (event.kind === NotebookCellsChangeType.Move) {
323327
this._moveCell(event.index, event.newIdx);
328+
} else if (event.kind === NotebookCellsChangeType.Output) {
329+
this._setCellOutputs(event.index, event.outputs);
324330
} else if (event.kind === NotebookCellsChangeType.CellClearOutput) {
325331
this._clearCellOutputs(event.index);
326332
} else if (event.kind === NotebookCellsChangeType.CellsClearOutput) {
@@ -412,6 +418,12 @@ export class ExtHostNotebookDocument extends Disposable {
412418
});
413419
}
414420

421+
private _setCellOutputs(index: number, outputs: IProcessedOutput[]): void {
422+
const cell = this._cells[index];
423+
cell.setOutputs(outputs);
424+
this._emitter.emitCellOutputsChange({ document: this.notebookDocument, cells: [cell.cell] });
425+
}
426+
415427
private _clearCellOutputs(index: number): void {
416428
const cell = this._cells[index].cell;
417429
cell.outputs = [];

src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,13 +505,24 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
505505
// TODO@rebornix should this trigger content change event?
506506
spliceNotebookCellOutputs(cellHandle: number, splices: NotebookCellOutputsSplice[]): void {
507507
const cell = this._mapping.get(cellHandle);
508-
cell?.spliceNotebookCellOutputs(splices);
508+
if (cell) {
509509

510-
if (!this.transientOptions.transientOutputs) {
511-
this._increaseVersionId();
512-
this.setDirty(true);
513-
this._onDidChangeContent.fire();
510+
cell.spliceNotebookCellOutputs(splices);
511+
512+
if (!this.transientOptions.transientOutputs) {
513+
this._increaseVersionId();
514+
this.setDirty(true);
515+
this._onDidChangeContent.fire();
516+
}
517+
518+
this._onDidModelChangeProxy.fire({
519+
kind: NotebookCellsChangeType.Output,
520+
versionId: this.versionId,
521+
index: this.cells.indexOf(cell),
522+
outputs: cell.outputs ?? []
523+
});
514524
}
525+
515526
}
516527

517528
clearCellOutput(handle: number) {

src/vs/workbench/contrib/notebook/common/notebookCommon.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,15 @@ export interface IErrorOutput {
166166
/**
167167
* Exception Name
168168
*/
169-
ename?: string;
169+
ename: string;
170170
/**
171171
* Exception Value
172172
*/
173-
evalue?: string;
173+
evalue: string;
174174
/**
175175
* Exception call stacks
176176
*/
177-
traceback?: string[];
177+
traceback: string[];
178178
}
179179

180180
export interface NotebookCellOutputMetadata {
@@ -366,7 +366,8 @@ export enum NotebookCellsChangeType {
366366
CellsClearOutput = 4,
367367
ChangeLanguage = 5,
368368
Initialize = 6,
369-
ChangeMetadata = 7
369+
ChangeMetadata = 7,
370+
Output = 8,
370371
}
371372

372373
export interface NotebookCellsInitializeEvent {
@@ -388,6 +389,13 @@ export interface NotebookCellsModelMoveEvent {
388389
readonly versionId: number;
389390
}
390391

392+
export interface NotebookOutputChangedEvent {
393+
readonly kind: NotebookCellsChangeType.Output;
394+
readonly index: number;
395+
readonly versionId: number;
396+
readonly outputs: IProcessedOutput[];
397+
}
398+
391399
export interface NotebookCellClearOutputEvent {
392400
readonly kind: NotebookCellsChangeType.CellClearOutput;
393401
readonly index: number;
@@ -413,7 +421,7 @@ export interface NotebookCellsChangeMetadataEvent {
413421
readonly metadata: NotebookCellMetadata | undefined;
414422
}
415423

416-
export type NotebookCellsChangedEvent = NotebookCellsInitializeEvent | NotebookCellsModelChangedEvent | NotebookCellsModelMoveEvent | NotebookCellClearOutputEvent | NotebookCellsClearOutputEvent | NotebookCellsChangeLanguageEvent | NotebookCellsChangeMetadataEvent;
424+
export type NotebookCellsChangedEvent = NotebookCellsInitializeEvent | NotebookCellsModelChangedEvent | NotebookCellsModelMoveEvent | NotebookOutputChangedEvent | NotebookCellClearOutputEvent | NotebookCellsClearOutputEvent | NotebookCellsChangeLanguageEvent | NotebookCellsChangeMetadataEvent;
417425

418426
export const enum CellEditType {
419427
Replace = 1,

src/vs/workbench/test/browser/api/extHostNotebook.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ suite('NotebookCell#Document', function () {
178178
cellKind: CellKind.Code,
179179
outputs: [],
180180
}]]]
181-
});
181+
}, false);
182182

183183
await p;
184184

@@ -234,7 +234,7 @@ suite('NotebookCell#Document', function () {
234234
kind: NotebookCellsChangeType.ModelChange,
235235
versionId: 2,
236236
changes: [[0, 1, []]]
237-
});
237+
}, false);
238238

239239
assert.equal(notebook.notebookDocument.cells.length, 1);
240240
assert.equal(cell1.document.isClosed, true); // ref still alive!

src/vs/workbench/test/browser/api/extHostNotebookConcatDocument.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ suite('NotebookConcatDocument', function () {
143143
cellKind: CellKind.Code,
144144
outputs: [],
145145
}]]]
146-
});
146+
}, false);
147147

148148

149149
assert.equal(notebook.notebookDocument.cells.length, 1 + 2); // markdown and code
@@ -177,7 +177,7 @@ suite('NotebookConcatDocument', function () {
177177
cellKind: CellKind.Code,
178178
outputs: [],
179179
}]]]
180-
});
180+
}, false);
181181

182182

183183
assert.equal(notebook.notebookDocument.cells.length, 1 + 2); // markdown and code
@@ -210,7 +210,7 @@ suite('NotebookConcatDocument', function () {
210210
cellKind: CellKind.Code,
211211
outputs: [],
212212
}]]]
213-
});
213+
}, false);
214214
assert.equal(notebook.notebookDocument.cells.length, 1 + 1);
215215
assert.equal(doc.version, 1);
216216
assertLines(doc, 'Hello', 'World', 'Hello World!');
@@ -233,7 +233,7 @@ suite('NotebookConcatDocument', function () {
233233
cellKind: CellKind.Code,
234234
outputs: [],
235235
}]]]
236-
});
236+
}, false);
237237

238238
assert.equal(notebook.notebookDocument.cells.length, 1 + 2);
239239
assert.equal(doc.version, 2);
@@ -249,7 +249,7 @@ suite('NotebookConcatDocument', function () {
249249
kind: NotebookCellsChangeType.ModelChange,
250250
versionId: notebook.notebookDocument.version + 1,
251251
changes: [[1, 1, []]]
252-
});
252+
}, false);
253253
assert.equal(notebook.notebookDocument.cells.length, 1 + 1);
254254
assert.equal(doc.version, 3);
255255
assertLines(doc, 'Hello', 'World', 'Hello World!');
@@ -283,7 +283,7 @@ suite('NotebookConcatDocument', function () {
283283
cellKind: CellKind.Code,
284284
outputs: [],
285285
}]]]
286-
});
286+
}, false);
287287
assert.equal(notebook.notebookDocument.cells.length, 1 + 2);
288288
assert.equal(doc.version, 1);
289289

@@ -337,7 +337,7 @@ suite('NotebookConcatDocument', function () {
337337
cellKind: CellKind.Code,
338338
outputs: [],
339339
}]]]
340-
});
340+
}, false);
341341

342342
const mixedDoc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
343343
const fooLangDoc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, 'fooLang');
@@ -359,7 +359,7 @@ suite('NotebookConcatDocument', function () {
359359
cellKind: CellKind.Code,
360360
outputs: [],
361361
}]]]
362-
});
362+
}, false);
363363

364364
assertLines(mixedDoc, 'fooLang-document', 'barLang-document', 'barLang-document2');
365365
assertLines(fooLangDoc, 'fooLang-document');
@@ -401,7 +401,7 @@ suite('NotebookConcatDocument', function () {
401401
cellKind: CellKind.Code,
402402
outputs: [],
403403
}]]]
404-
});
404+
}, false);
405405

406406
assert.equal(notebook.notebookDocument.cells.length, 1 + 2); // markdown and code
407407

@@ -454,7 +454,7 @@ suite('NotebookConcatDocument', function () {
454454
cellKind: CellKind.Code,
455455
outputs: [],
456456
}]]]
457-
});
457+
}, false);
458458

459459
assert.equal(notebook.notebookDocument.cells.length, 1 + 2); // markdown and code
460460

@@ -491,7 +491,7 @@ suite('NotebookConcatDocument', function () {
491491
cellKind: CellKind.Code,
492492
outputs: [],
493493
}]]]
494-
});
494+
}, false);
495495

496496
assert.equal(notebook.notebookDocument.cells.length, 1 + 2); // markdown and code
497497

@@ -525,7 +525,7 @@ suite('NotebookConcatDocument', function () {
525525
cellKind: CellKind.Code,
526526
outputs: [],
527527
}]]]
528-
});
528+
}, false);
529529

530530
assert.equal(notebook.notebookDocument.cells.length, 1 + 2); // markdown and code
531531

0 commit comments

Comments
 (0)