提交 951dd140 编写于 作者: J Johannes Rieken

add `replaceNotebookMetadata` (should become `replaceMetadata`) to...

add `replaceNotebookMetadata` (should become `replaceMetadata`) to NotebookEditorEdit, https://github.com/microsoft/vscode/issues/105283
上级 52a7a9ec
......@@ -1355,12 +1355,18 @@ declare module 'vscode' {
replaceCellMetadata(uri: Uri, index: number, cellMetadata: NotebookCellMetadata, metadata?: WorkspaceEditEntryMetadata): void;
}
export interface NotebookEditorCellEdit {
export interface NotebookEditorEdit {
replaceNotebookMetadata(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 */
......@@ -1448,7 +1454,7 @@ declare module 'vscode' {
*/
asWebviewUri(localResource: Uri): Uri;
edit(callback: (editBuilder: NotebookEditorCellEdit) => void): Thenable<boolean>;
edit(callback: (editBuilder: NotebookEditorEdit) => void): Thenable<boolean>;
revealRange(range: NotebookCellRange, revealType?: NotebookEditorRevealType): void;
}
......
......@@ -153,14 +153,17 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
this.registerListeners();
}
async $tryApplyEdits(viewType: string, resource: UriComponents, modelVersionId: number, edits: ICellEditOperation[]): Promise<boolean> {
async $tryApplyEdits(_viewType: string, resource: UriComponents, modelVersionId: number, cellEdits: ICellEditOperation[], newMetadata: NotebookDocumentMetadata | undefined): Promise<boolean> {
const textModel = this._notebookService.getNotebookTextModel(URI.from(resource));
if (textModel) {
this._notebookService.transformEditsOutputs(textModel, edits);
return textModel.applyEdit(modelVersionId, edits, true);
if (!textModel) {
return false;
}
return false;
this._notebookService.transformEditsOutputs(textModel, cellEdits);
//TODO@rebornix should this go into applyEdit?
if (newMetadata) {
textModel.updateNotebookMetadata(newMetadata);
}
return textModel.applyEdit(modelVersionId, cellEdits, true);
}
async removeNotebookTextModel(uri: URI): Promise<void> {
......
......@@ -738,7 +738,7 @@ export interface MainThreadNotebookShape extends IDisposable {
$registerNotebookKernelProvider(extension: NotebookExtensionDescription, handle: number, documentFilter: INotebookDocumentFilter): Promise<void>;
$unregisterNotebookKernelProvider(handle: number): Promise<void>;
$onNotebookKernelChange(handle: number, uri: UriComponents | undefined): void;
$tryApplyEdits(viewType: string, resource: UriComponents, modelVersionId: number, edits: ICellEditOperation[]): Promise<boolean>;
$tryApplyEdits(viewType: string, resource: UriComponents, modelVersionId: number, edits: ICellEditOperation[], metadata: NotebookDocumentMetadata | undefined): Promise<boolean>;
$updateNotebookLanguages(viewType: string, resource: UriComponents, languages: string[]): Promise<void>;
$updateNotebookMetadata(viewType: string, resource: UriComponents, metadata: NotebookDocumentMetadata): Promise<void>;
$updateNotebookCellMetadata(viewType: string, resource: UriComponents, handle: number, metadata: NotebookCellMetadata | undefined): Promise<void>;
......
......@@ -22,7 +22,7 @@ import { IExtensionStoragePaths } from 'vs/workbench/api/common/extHostStoragePa
import * as typeConverters from 'vs/workbench/api/common/extHostTypeConverters';
import * as extHostTypes from 'vs/workbench/api/common/extHostTypes';
import { asWebviewUri, WebviewInitData } from 'vs/workbench/api/common/shared/webview';
import { addIdToOutput, CellEditType, CellOutputKind, CellStatusbarAlignment, CellUri, diff, ICellEditOperation, ICellReplaceEdit, IMainCellDto, INotebookCellStatusBarEntry, INotebookDisplayOrder, INotebookEditData, INotebookKernelInfoDto2, IProcessedOutput, NotebookCellMetadata, NotebookCellsChangedEventDto, NotebookCellsChangeType, NotebookCellsSplice2, NotebookDataDto, notebookDocumentMetadataDefaults } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { addIdToOutput, CellEditType, CellOutputKind, CellStatusbarAlignment, CellUri, diff, ICellEditOperation, ICellReplaceEdit, IMainCellDto, INotebookCellStatusBarEntry, INotebookDisplayOrder, INotebookEditData, INotebookKernelInfoDto2, IProcessedOutput, NotebookCellMetadata, NotebookCellsChangedEventDto, NotebookCellsChangeType, NotebookCellsSplice2, NotebookDataDto, NotebookDocumentMetadata, notebookDocumentMetadataDefaults } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import * as vscode from 'vscode';
import { Cache } from './cache';
import { ResourceMap } from 'vs/base/common/map';
......@@ -486,11 +486,13 @@ export class ExtHostNotebookDocument extends Disposable {
}
}
export class NotebookEditorCellEditBuilder implements vscode.NotebookEditorCellEdit {
export class NotebookEditorCellEditBuilder implements vscode.NotebookEditorEdit {
private readonly _documentVersionId: number;
private readonly _collectedEdits: ICellEditOperation[] = [];
private _finalized: boolean = false;
private _collectedEdits: ICellEditOperation[] = [];
private _newNotebookDocumentMetadata?: NotebookDocumentMetadata;
constructor(documentVersionId: number) {
this._documentVersionId = documentVersionId;
......@@ -500,7 +502,8 @@ export class NotebookEditorCellEditBuilder implements vscode.NotebookEditorCellE
this._finalized = true;
return {
documentVersionId: this._documentVersionId,
edits: this._collectedEdits,
cellEdits: this._collectedEdits,
newMetadata: this._newNotebookDocumentMetadata
};
}
......@@ -510,7 +513,12 @@ export class NotebookEditorCellEditBuilder implements vscode.NotebookEditorCellE
}
}
replaceMetadata(index: number, metadata: vscode.NotebookCellMetadata): void {
replaceNotebookMetadata(value: vscode.NotebookDocumentMetadata): void {
this._throwIfFinalized();
this._newNotebookDocumentMetadata = { ...notebookDocumentMetadataDefaults, ...value };
}
replaceCellMetadata(index: number, metadata: vscode.NotebookCellMetadata): void {
this._throwIfFinalized();
this._collectedEdits.push({
editType: CellEditType.Metadata,
......@@ -519,7 +527,13 @@ export class NotebookEditorCellEditBuilder implements vscode.NotebookEditorCellE
});
}
replaceOutput(index: number, outputs: vscode.CellOutput[]): void {
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({
editType: CellEditType.Output,
......@@ -528,6 +542,11 @@ export class NotebookEditorCellEditBuilder implements vscode.NotebookEditorCellE
});
}
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();
......@@ -693,16 +712,16 @@ export class ExtHostNotebookEditor extends Disposable implements vscode.Notebook
private _applyEdit(editData: INotebookEditData): Promise<boolean> {
// return when there is nothing to do
if (editData.edits.length === 0) {
if (editData.cellEdits.length === 0) {
return Promise.resolve(true);
}
const compressedEdits: ICellEditOperation[] = [];
let compressedEditsIndex = -1;
for (let i = 0; i < editData.edits.length; i++) {
for (let i = 0; i < editData.cellEdits.length; i++) {
if (compressedEditsIndex < 0) {
compressedEdits.push(editData.edits[i]);
compressedEdits.push(editData.cellEdits[i]);
compressedEditsIndex++;
continue;
}
......@@ -710,19 +729,19 @@ export class ExtHostNotebookEditor extends Disposable implements vscode.Notebook
const prevIndex = compressedEditsIndex;
const prev = compressedEdits[prevIndex];
if (prev.editType === CellEditType.Replace && editData.edits[i].editType === CellEditType.Replace) {
if (prev.index === editData.edits[i].index) {
prev.cells.push(...(editData.edits[i] as ICellReplaceEdit).cells);
prev.count += (editData.edits[i] as ICellReplaceEdit).count;
if (prev.editType === CellEditType.Replace && editData.cellEdits[i].editType === CellEditType.Replace) {
if (prev.index === editData.cellEdits[i].index) {
prev.cells.push(...(editData.cellEdits[i] as ICellReplaceEdit).cells);
prev.count += (editData.cellEdits[i] as ICellReplaceEdit).count;
continue;
}
}
compressedEdits.push(editData.edits[i]);
compressedEdits.push(editData.cellEdits[i]);
compressedEditsIndex++;
}
return this._proxy.$tryApplyEdits(this.viewType, this.uri, editData.documentVersionId, compressedEdits);
return this._proxy.$tryApplyEdits(this.viewType, this.uri, editData.documentVersionId, compressedEdits, editData.newMetadata);
}
revealRange(range: vscode.NotebookCellRange, revealType?: extHostTypes.NotebookEditorRevealType) {
......
......@@ -445,7 +445,8 @@ export type ICellEditOperation = ICellReplaceEdit | ICellOutputEdit | ICellMetad
export interface INotebookEditData {
documentVersionId: number;
edits: ICellEditOperation[];
cellEdits: ICellEditOperation[];
newMetadata?: NotebookDocumentMetadata;
}
export interface NotebookDataDto {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册