diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 07d093275ef..e956e67ffc7 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -1081,10 +1081,8 @@ declare module 'vscode' { readonly cellKind: CellKind; readonly document: TextDocument; readonly language: string; - /** @deprecated use WorkspaceEdit.replaceCellOutput */ - outputs: CellOutput[]; - /** @deprecated use WorkspaceEdit.replaceCellMetadata */ - metadata: NotebookCellMetadata; + readonly outputs: CellOutput[]; + readonly metadata: NotebookCellMetadata; } export interface NotebookDocumentMetadata { diff --git a/src/vs/workbench/api/browser/mainThreadNotebook.ts b/src/vs/workbench/api/browser/mainThreadNotebook.ts index 1a2b21cf966..8da7fd54186 100644 --- a/src/vs/workbench/api/browser/mainThreadNotebook.ts +++ b/src/vs/workbench/api/browser/mainThreadNotebook.ts @@ -569,29 +569,6 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo textModel?.updateLanguages(languages); } - async $spliceNotebookCellOutputs(viewType: string, resource: UriComponents, cellHandle: number, splices: NotebookCellOutputsSplice[]): Promise { - this.logService.debug('MainThreadNotebooks#spliceNotebookCellOutputs', resource.path, cellHandle); - const textModel = this._notebookService.getNotebookTextModel(URI.from(resource)); - - if (!textModel) { - return; - } - - const cell = textModel.cells.find(cell => cell.handle === cellHandle); - - if (!cell) { - return; - } - - textModel.applyEdits(textModel.versionId, [ - { - editType: CellEditType.OutputsSplice, - index: textModel.cells.indexOf(cell), - splices - } - ], true, undefined, () => undefined, undefined); - } - async $postMessage(editorId: string, forRendererId: string | undefined, value: any): Promise { const editor = this._notebookService.getNotebookEditor(editorId) as INotebookEditor | undefined; if (editor?.isNotebookEditor) { diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index a3b6da5c89b..c9fd1ee383c 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -789,7 +789,6 @@ export interface MainThreadNotebookShape extends IDisposable { $onNotebookKernelChange(handle: number, uri: UriComponents | undefined): void; $tryApplyEdits(viewType: string, resource: UriComponents, modelVersionId: number, edits: ICellEditOperation[]): Promise; $updateNotebookLanguages(viewType: string, resource: UriComponents, languages: string[]): Promise; - $spliceNotebookCellOutputs(viewType: string, resource: UriComponents, cellHandle: number, splices: NotebookCellOutputsSplice[]): Promise; $postMessage(editorId: string, forRendererId: string | undefined, value: any): Promise; $setStatusBarEntry(id: number, statusBarEntry: INotebookCellStatusBarEntryDto): Promise; $tryOpenDocument(uriComponents: UriComponents, viewType?: string): Promise; diff --git a/src/vs/workbench/api/common/extHostNotebookDocument.ts b/src/vs/workbench/api/common/extHostNotebookDocument.ts index 463590a32e7..f107d17ef31 100644 --- a/src/vs/workbench/api/common/extHostNotebookDocument.ts +++ b/src/vs/workbench/api/common/extHostNotebookDocument.ts @@ -72,7 +72,7 @@ export class ExtHostCell extends Disposable { private _onDidChangeOutputs = new Emitter[]>(); readonly onDidChangeOutputs: Event[]> = this._onDidChangeOutputs.event; - private _outputs: any[]; + private _outputs: any[]; // it's `IOutputDtop[]` private _outputMapping = new WeakMap(); private _metadata: vscode.NotebookCellMetadata; @@ -124,12 +124,9 @@ export class ExtHostCell extends Disposable { document: data.document, get language() { return data!.document.languageId; }, get outputs() { return that._outputs; }, - set outputs(value) { that._updateOutputs(value); }, + set outputs(value) { throw new Error('Use WorkspaceEdit to update cell outputs.'); }, get metadata() { return that._metadata; }, - set metadata(value) { - that.setMetadata(value); - that._updateMetadata(); - }, + set metadata(value) { throw new Error('Use WorkspaceEdit to update cell metadata.'); }, }); } return this._cell; @@ -140,33 +137,13 @@ export class ExtHostCell extends Disposable { this._onDidDispose.fire(); } - setOutputs(newOutputs: vscode.CellOutput[]): void { + setOutputs(newOutputs: IOutputDtoWithId[]): void { this._outputs = newOutputs; - } - - private _updateOutputs(newOutputs: vscode.CellOutput[]) { - const rawDiffs = diff(this._outputs || [], newOutputs || [], (a) => { - return this._outputMapping.has(a); - }); - - const transformedDiffs: ISplice[] = rawDiffs.map(diff => { - for (let i = diff.start; i < diff.start + diff.deleteCount; i++) { - this._outputMapping.delete(this._outputs[i]); - } - - return { - deleteCount: diff.deleteCount, - start: diff.start, - toInsert: diff.toInsert.map((output): IOutputDtoWithId => { - const uuid = UUID.generateUuid(); - this._outputMapping.set(output, uuid); - return { ...output, outputId: uuid }; - }) - }; - }); - - this._outputs = newOutputs; - this._onDidChangeOutputs.fire(transformedDiffs); + this._outputMapping = new WeakMap(); + for (const output of this._outputs) { + this._outputMapping.set(output, output.outputId); + delete output.outputId; + } } setMetadata(newMetadata: vscode.NotebookCellMetadata): void { @@ -390,12 +367,6 @@ export class ExtHostNotebookDocument extends Disposable { this._cellDisposableMapping.set(extCell.handle, store); } - const store = this._cellDisposableMapping.get(extCell.handle)!; - - store.add(extCell.onDidChangeOutputs((diffs) => { - this.eventuallyUpdateCellOutputs(extCell, diffs); - })); - return extCell; }); @@ -464,23 +435,6 @@ export class ExtHostNotebookDocument extends Disposable { this._emitter.emitCellMetadataChange(event); } - async eventuallyUpdateCellOutputs(cell: ExtHostCell, diffs: ISplice[]) { - const outputDtos: NotebookCellOutputsSplice[] = diffs.map(diff => { - const outputs = diff.toInsert; - return [diff.start, diff.deleteCount, outputs]; - }); - - if (!outputDtos.length) { - return; - } - - await this._proxy.$spliceNotebookCellOutputs(this._viewType, this.uri, cell.handle, outputDtos); - this._emitter.emitCellOutputsChange({ - document: this.notebookDocument, - cells: [cell.cell] - }); - } - getCell(cellHandle: number): ExtHostCell | undefined { return this._cells.find(cell => cell.handle === cellHandle); }