From 4821adfc12de834b294cce28a2a780c76bb5c87b Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Mon, 8 Feb 2021 09:09:42 +0100 Subject: [PATCH] move convert logic into extHostTypeConverters --- src/vs/workbench/api/common/extHostNotebookDocument.ts | 3 ++- src/vs/workbench/api/common/extHostTypeConverters.ts | 8 ++++++++ src/vs/workbench/api/common/extHostTypes.ts | 8 -------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/vs/workbench/api/common/extHostNotebookDocument.ts b/src/vs/workbench/api/common/extHostNotebookDocument.ts index cdced2eaf25..8bec8c0923a 100644 --- a/src/vs/workbench/api/common/extHostNotebookDocument.ts +++ b/src/vs/workbench/api/common/extHostNotebookDocument.ts @@ -13,6 +13,7 @@ import { URI } from 'vs/base/common/uri'; import { CellKind, INotebookDocumentPropertiesChangeData, IWorkspaceCellEditDto, MainThreadBulkEditsShape, MainThreadNotebookShape, WorkspaceEditType } from 'vs/workbench/api/common/extHost.protocol'; import { ExtHostDocumentsAndEditors, IExtHostModelAddedData } from 'vs/workbench/api/common/extHostDocumentsAndEditors'; import { NotebookCellOutput } from 'vs/workbench/api/common/extHostTypes'; +import * as extHostTypeConverters from 'vs/workbench/api/common/extHostTypeConverters'; import { CellEditType, IMainCellDto, IOutputDto, NotebookCellMetadata, NotebookCellsChangedEventDto, NotebookCellsChangeType, NotebookCellsSplice2, notebookDocumentMetadataDefaults } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import * as vscode from 'vscode'; @@ -117,7 +118,7 @@ export class ExtHostCell extends Disposable { return that._outputs.map(output => NotebookCellOutput._toOld(output)); }, set outputs(_value) { throw new Error('Use WorkspaceEdit to update cell outputs.'); }, - get outputs2() { return that._outputs.map(output => NotebookCellOutput._fromDto(output, output.outputId)); }, + get outputs2() { return that._outputs.map(extHostTypeConverters.NotebookCellOutput.to); }, set outputs2(_value) { throw new Error('Use WorkspaceEdit to update cell outputs.'); }, get metadata() { return that._metadata; }, set metadata(_value) { throw new Error('Use WorkspaceEdit to update cell metadata.'); }, diff --git a/src/vs/workbench/api/common/extHostTypeConverters.ts b/src/vs/workbench/api/common/extHostTypeConverters.ts index 874ef1a6568..20fa2b39525 100644 --- a/src/vs/workbench/api/common/extHostTypeConverters.ts +++ b/src/vs/workbench/api/common/extHostTypeConverters.ts @@ -1371,6 +1371,14 @@ export namespace NotebookCellOutput { metadata: isEmptyObject(custom) ? undefined : { custom } }; } + + export function to(output: IOutputDto): vscode.NotebookCellOutput { + const items: types.NotebookCellOutputItem[] = []; + for (const key in output.data) { + items.push(new types.NotebookCellOutputItem(key, output.data[key], output.metadata?.custom ? output.metadata?.custom[key] : undefined)); + } + return new types.NotebookCellOutput(items, output.outputId); + } } diff --git a/src/vs/workbench/api/common/extHostTypes.ts b/src/vs/workbench/api/common/extHostTypes.ts index c8348478b4f..bf0d53505ca 100644 --- a/src/vs/workbench/api/common/extHostTypes.ts +++ b/src/vs/workbench/api/common/extHostTypes.ts @@ -2888,14 +2888,6 @@ export class NotebookCellOutput { } } - static _fromDto(output: IOutputDto, id?: string) { - const items: NotebookCellOutputItem[] = []; - for (const key in output.data) { - items.push(new NotebookCellOutputItem(key, output.data[key], output.metadata?.custom ? output.metadata?.custom[key] : undefined)); - } - return new NotebookCellOutput(items, id); - } - static _fromOld(output: vscode.CellOutput, id?: string): NotebookCellOutput { switch (output.outputKind) { case CellOutputKind.Error: