From 06377cfaaa5edef12d5ee80ba14d20fe42b2cd98 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Mon, 14 Sep 2020 10:19:06 +0200 Subject: [PATCH] NotebookEditorEdit-api changes, https://github.com/microsoft/vscode/issues/105283 --- src/vs/vscode.proposed.d.ts | 23 +++++++------ .../api/common/extHostNotebookEditor.ts | 32 ++----------------- 2 files changed, 13 insertions(+), 42 deletions(-) diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index a2811eec418..b507e8c87d0 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -1405,21 +1405,10 @@ declare module 'vscode' { } export interface NotebookEditorEdit { - - replaceNotebookMetadata(value: NotebookDocumentMetadata): void; - + replaceMetadata(value: NotebookDocumentMetadata): void; replaceCells(start: number, end: number, cells: NotebookCellData[]): void; replaceCellOutput(index: number, outputs: CellOutput[]): void; replaceCellMetadata(index: number, metadata: NotebookCellMetadata): void; - - /** @deprecated */ - replaceOutput(index: number, outputs: CellOutput[]): void; - /** @deprecated */ - replaceMetadata(index: number, metadata: NotebookCellMetadata): void; - /** @deprecated */ - insert(index: number, content: string | string[], language: string, type: CellKind, outputs: CellOutput[], metadata: NotebookCellMetadata | undefined): void; - /** @deprecated */ - delete(index: number): void; } export interface NotebookCellRange { @@ -1503,6 +1492,16 @@ declare module 'vscode' { */ asWebviewUri(localResource: Uri): Uri; + /** + * Perform an edit on the notebook associated with this notebook editor. + * + * The given callback-function is invoked with an [edit-builder](#NotebookEditorEdit) which must + * be used to make edits. Note that the edit-builder is only valid while the + * callback executes. + * + * @param callback A function which can create edits using an [edit-builder](#NotebookEditorEdit). + * @return A promise that resolves with a value indicating if the edits could be applied. + */ edit(callback: (editBuilder: NotebookEditorEdit) => void): Thenable; revealRange(range: NotebookCellRange, revealType?: NotebookEditorRevealType): void; diff --git a/src/vs/workbench/api/common/extHostNotebookEditor.ts b/src/vs/workbench/api/common/extHostNotebookEditor.ts index 040362b6897..414ff8fea27 100644 --- a/src/vs/workbench/api/common/extHostNotebookEditor.ts +++ b/src/vs/workbench/api/common/extHostNotebookEditor.ts @@ -6,7 +6,7 @@ import { readonly } from 'vs/base/common/errors'; import { Emitter, Event } from 'vs/base/common/event'; import { Disposable } from 'vs/base/common/lifecycle'; -import { CellKind, MainThreadNotebookShape } from 'vs/workbench/api/common/extHost.protocol'; +import { MainThreadNotebookShape } from 'vs/workbench/api/common/extHost.protocol'; import * as extHostTypes from 'vs/workbench/api/common/extHostTypes'; import { addIdToOutput, CellEditType, ICellEditOperation, ICellReplaceEdit, INotebookEditData, notebookDocumentMetadataDefaults } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import * as vscode from 'vscode'; @@ -37,7 +37,7 @@ class NotebookEditorCellEditBuilder implements vscode.NotebookEditorEdit { } } - replaceNotebookMetadata(value: vscode.NotebookDocumentMetadata): void { + replaceMetadata(value: vscode.NotebookDocumentMetadata): void { this._throwIfFinalized(); this._collectedEdits.push({ editType: CellEditType.DocumentMetadata, @@ -54,12 +54,6 @@ class NotebookEditorCellEditBuilder implements vscode.NotebookEditorEdit { }); } - replaceMetadata(index: number, metadata: vscode.NotebookCellMetadata): void { - console.warn('DEPRECATED use "replaceCellMetadata" instead'); - this.replaceCellMetadata(index, metadata); - } - - replaceCellOutput(index: number, outputs: vscode.CellOutput[]): void { this._throwIfFinalized(); this._collectedEdits.push({ @@ -69,14 +63,8 @@ class NotebookEditorCellEditBuilder implements vscode.NotebookEditorEdit { }); } - replaceOutput(index: number, outputs: vscode.CellOutput[]): void { - console.warn('DEPRECATED use "replaceCellOutput" instead'); - this.replaceCellOutput(index, outputs); - } - replaceCells(from: number, to: number, cells: vscode.NotebookCellData[]): void { this._throwIfFinalized(); - this._collectedEdits.push({ editType: CellEditType.Replace, index: from, @@ -89,22 +77,6 @@ class NotebookEditorCellEditBuilder implements vscode.NotebookEditorEdit { }) }); } - - insert(index: number, content: string | string[], language: string, type: CellKind, outputs: vscode.CellOutput[], metadata: vscode.NotebookCellMetadata | undefined): void { - this._throwIfFinalized(); - this.replaceCells(index, index, [{ - language, - outputs, - metadata, - cellKind: type, - source: Array.isArray(content) ? content.join('\n') : content, - }]); - } - - delete(index: number): void { - this._throwIfFinalized(); - this.replaceCells(index, 1, []); - } } export class ExtHostNotebookEditor extends Disposable implements vscode.NotebookEditor {