fix #116598. broadcast output items change.

This commit is contained in:
rebornix
2021-02-16 14:57:40 -08:00
parent 7459443550
commit 1267767472
4 changed files with 78 additions and 6 deletions

View File

@@ -13,7 +13,7 @@ import { CellKind, INotebookDocumentPropertiesChangeData } from 'vs/workbench/ap
import { ExtHostDocumentsAndEditors, IExtHostModelAddedData } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
import * as extHostTypeConverters from 'vs/workbench/api/common/extHostTypeConverters';
import * as extHostTypes from 'vs/workbench/api/common/extHostTypes';
import { IMainCellDto, IOutputDto, NotebookCellMetadata, NotebookCellsChangedEventDto, NotebookCellsChangeType, NotebookCellsSplice2, notebookDocumentMetadataDefaults } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { IMainCellDto, IOutputDto, IOutputItemDto, NotebookCellMetadata, NotebookCellsChangedEventDto, NotebookCellsChangeType, NotebookCellsSplice2, notebookDocumentMetadataDefaults } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import * as vscode from 'vscode';
class RawContentChangeEvent {
@@ -100,6 +100,17 @@ export class ExtHostCell {
this._outputs = newOutputs;
}
setOutputItems(outputId: string, append: boolean, newOutputItems: IOutputItemDto[]) {
const output = this._outputs.find(op => op.outputId === outputId);
if (output) {
if (append) {
output.outputs = [...output.outputs, ...newOutputItems];
} else {
output.outputs = newOutputItems;
}
}
}
setMetadata(newMetadata: NotebookCellMetadata): void {
this._metadata = extHostTypeConverters.NotebookCellMetadata.to(newMetadata);
}
@@ -211,6 +222,8 @@ export class ExtHostNotebookDocument extends Disposable {
this._moveCell(e.index, e.newIdx);
} else if (e.kind === NotebookCellsChangeType.Output) {
this._setCellOutputs(e.index, e.outputs);
} else if (e.kind === NotebookCellsChangeType.OutputItem) {
this._setCellOutputItems(e.index, e.outputId, e.append, e.outputItems);
} else if (e.kind === NotebookCellsChangeType.ChangeLanguage) {
this._changeCellLanguage(e.index, e.language);
} else if (e.kind === NotebookCellsChangeType.ChangeCellMetadata) {
@@ -301,6 +314,12 @@ export class ExtHostNotebookDocument extends Disposable {
this._emitter.emitCellOutputsChange({ document: this.notebookDocument, cells: [cell.cell] });
}
private _setCellOutputItems(index: number, outputId: string, append: boolean, outputItems: IOutputItemDto[]): void {
const cell = this._cells[index];
cell.setOutputItems(outputId, append, outputItems);
this._emitter.emitCellOutputsChange({ document: this.notebookDocument, cells: [cell.cell] });
}
private _changeCellLanguage(index: number, language: string): void {
const cell = this._cells[index];
const event: vscode.NotebookCellLanguageChangeEvent = { document: this.notebookDocument, cell: cell.cell, language };