Skip to content

Commit

Permalink
debt - simplify metadata edit because we now have CellEditType.Docume…
Browse files Browse the repository at this point in the history
…ntMetadata
  • Loading branch information
jrieken committed Sep 10, 2020
1 parent 533ca9b commit 01f9355
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/vs/workbench/api/browser/mainThreadBulkEdits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function reviveWorkspaceEditDto2(data: IWorkspaceEditDto | undefined): ResourceE
} else if (edit._type === WorkspaceEditType.Text) {
result.push(new ResourceTextEdit(edit.resource, edit.edit, edit.modelVersionId, edit.metadata));
} else if (edit._type === WorkspaceEditType.Cell) {
result.push(new ResourceNotebookCellEdit(edit.resource, edit.edit, edit.notebookMetadata, edit.notebookVersionId, edit.metadata));
result.push(new ResourceNotebookCellEdit(edit.resource, edit.edit, edit.notebookVersionId, edit.metadata));
}
}
return result;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/browser/mainThreadEditors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function reviveWorkspaceEditDto2(data: IWorkspaceEditDto | undefined): ResourceE
} else if (edit._type === WorkspaceEditType.Text) {
result.push(new ResourceTextEdit(edit.resource, edit.edit, edit.modelVersionId, edit.metadata));
} else if (edit._type === WorkspaceEditType.Cell) {
result.push(new ResourceNotebookCellEdit(edit.resource, edit.edit, edit.notebookMetadata, edit.notebookVersionId, edit.metadata));
result.push(new ResourceNotebookCellEdit(edit.resource, edit.edit, edit.notebookVersionId, edit.metadata));
}
}
return result;
Expand Down
12 changes: 2 additions & 10 deletions src/vs/workbench/api/browser/mainThreadNotebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookB
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { INotebookCellStatusBarService } from 'vs/workbench/contrib/notebook/common/notebookCellStatusBarService';
import { ACCESSIBLE_NOTEBOOK_DISPLAY_ORDER, CellEditType, DisplayOrderKey, ICellEditOperation, ICellRange, IEditor, IMainCellDto, INotebookDocumentFilter, NotebookCellOutputsSplice, NotebookCellsChangeType, NotebookDocumentMetadata, NOTEBOOK_DISPLAY_ORDER, TransientMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { ACCESSIBLE_NOTEBOOK_DISPLAY_ORDER, CellEditType, DisplayOrderKey, ICellEditOperation, ICellRange, IEditor, IMainCellDto, INotebookDocumentFilter, NotebookCellOutputsSplice, NotebookCellsChangeType, NOTEBOOK_DISPLAY_ORDER, TransientMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { IMainNotebookController, INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';
Expand Down Expand Up @@ -156,20 +156,12 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
this.registerListeners();
}

async $tryApplyEdits(_viewType: string, resource: UriComponents, modelVersionId: number, cellEdits: ICellEditOperation[], newMetadata: NotebookDocumentMetadata | undefined): Promise<boolean> {
async $tryApplyEdits(_viewType: string, resource: UriComponents, modelVersionId: number, cellEdits: ICellEditOperation[]): Promise<boolean> {
const textModel = this._notebookService.getNotebookTextModel(URI.from(resource));
if (!textModel) {
return false;
}
this._notebookService.transformEditsOutputs(textModel, cellEdits);
if (newMetadata) {
textModel.applyEdit(textModel.versionId, [
{
editType: CellEditType.DocumentMetadata,
metadata: newMetadata
}
], true);
}
return textModel.applyEdit(modelVersionId, cellEdits, true);
}

Expand Down
5 changes: 2 additions & 3 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,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[], metadata: NotebookDocumentMetadata | undefined): Promise<boolean>;
$tryApplyEdits(viewType: string, resource: UriComponents, modelVersionId: number, edits: ICellEditOperation[]): Promise<boolean>;
$updateNotebookLanguages(viewType: string, resource: UriComponents, languages: string[]): Promise<void>;
$spliceNotebookCellOutputs(viewType: string, resource: UriComponents, cellHandle: number, splices: NotebookCellOutputsSplice[]): Promise<void>;
$postMessage(editorId: string, forRendererId: string | undefined, value: any): Promise<boolean>;
Expand Down Expand Up @@ -1275,8 +1275,7 @@ export interface IWorkspaceTextEditDto {
export interface IWorkspaceCellEditDto {
_type: WorkspaceEditType.Cell;
resource: UriComponents;
edit?: ICellEditOperation;
notebookMetadata?: NotebookDocumentMetadata;
edit: ICellEditOperation;
notebookVersionId?: number;
metadata?: IWorkspaceEditEntryMetadataDto;
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/extHostNotebookDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export class ExtHostNotebookDocument extends Disposable {
const edit: IWorkspaceCellEditDto = {
_type: WorkspaceEditType.Cell,
metadata: undefined,
notebookMetadata: this._metadata,
edit: { editType: CellEditType.DocumentMetadata, metadata: this._metadata },
resource: this.uri,
notebookVersionId: this.notebookDocument.version,
};
Expand Down
13 changes: 7 additions & 6 deletions src/vs/workbench/api/common/extHostNotebookEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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 * as extHostTypes from 'vs/workbench/api/common/extHostTypes';
import { addIdToOutput, CellEditType, ICellEditOperation, ICellReplaceEdit, INotebookEditData, NotebookDocumentMetadata, notebookDocumentMetadataDefaults } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { addIdToOutput, CellEditType, ICellEditOperation, ICellReplaceEdit, INotebookEditData, notebookDocumentMetadataDefaults } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import * as vscode from 'vscode';
import { ExtHostNotebookDocument } from './extHostNotebookDocument';

Expand All @@ -18,7 +18,6 @@ class NotebookEditorCellEditBuilder implements vscode.NotebookEditorEdit {

private _finalized: boolean = false;
private _collectedEdits: ICellEditOperation[] = [];
private _newNotebookDocumentMetadata?: NotebookDocumentMetadata;

constructor(documentVersionId: number) {
this._documentVersionId = documentVersionId;
Expand All @@ -28,8 +27,7 @@ class NotebookEditorCellEditBuilder implements vscode.NotebookEditorEdit {
this._finalized = true;
return {
documentVersionId: this._documentVersionId,
cellEdits: this._collectedEdits,
newMetadata: this._newNotebookDocumentMetadata
cellEdits: this._collectedEdits
};
}

Expand All @@ -41,7 +39,10 @@ class NotebookEditorCellEditBuilder implements vscode.NotebookEditorEdit {

replaceNotebookMetadata(value: vscode.NotebookDocumentMetadata): void {
this._throwIfFinalized();
this._newNotebookDocumentMetadata = { ...notebookDocumentMetadataDefaults, ...value };
this._collectedEdits.push({
editType: CellEditType.DocumentMetadata,
metadata: { ...notebookDocumentMetadataDefaults, ...value }
});
}

replaceCellMetadata(index: number, metadata: vscode.NotebookCellMetadata): void {
Expand Down Expand Up @@ -235,7 +236,7 @@ export class ExtHostNotebookEditor extends Disposable implements vscode.Notebook
compressedEditsIndex++;
}

return this._proxy.$tryApplyEdits(this._viewType, this.document.uri, editData.documentVersionId, compressedEdits, editData.newMetadata);
return this._proxy.$tryApplyEdits(this._viewType, this.document.uri, editData.documentVersionId, compressedEdits);
}

revealRange(range: vscode.NotebookCellRange, revealType?: extHostTypes.NotebookEditorRevealType) {
Expand Down
22 changes: 3 additions & 19 deletions src/vs/workbench/contrib/bulkEdit/browser/bulkCellEdits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ import { URI } from 'vs/base/common/uri';
import { ResourceEdit } from 'vs/editor/browser/services/bulkEditService';
import { WorkspaceEditMetadata } from 'vs/editor/common/modes';
import { IProgress } from 'vs/platform/progress/common/progress';
import { CellEditType, ICellEditOperation, NotebookDocumentMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { ICellEditOperation } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookEditorModelResolverService } from 'vs/workbench/contrib/notebook/common/notebookEditorModelResolverService';
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';

export class ResourceNotebookCellEdit extends ResourceEdit {

constructor(
readonly resource: URI,
readonly cellEdit?: ICellEditOperation,
readonly notebookMetadata?: NotebookDocumentMetadata,
readonly cellEdit: ICellEditOperation,
readonly versionId?: number,
readonly metadata?: WorkspaceEditMetadata
) {
Expand Down Expand Up @@ -49,23 +48,8 @@ export class BulkCellEdits {
// throw new Error(`Notebook '${first.resource}' has changed in the meantime`);
// }

const edits: ICellEditOperation[] = [];
let newMetadata: NotebookDocumentMetadata | undefined;
for (let edit of group) {
if (edit.cellEdit) {
edits.push(edit.cellEdit);
}
newMetadata = edit.notebookMetadata ?? newMetadata;
}

// set metadata
if (newMetadata) {
edits.push({
editType: CellEditType.DocumentMetadata,
metadata: newMetadata
});
}
// apply edits
const edits = group.map(entry => entry.cellEdit);
this._notebookService.transformEditsOutputs(ref.object.notebook, edits);
ref.object.notebook.applyEdit(ref.object.notebook.versionId, edits, true);
ref.dispose();
Expand Down
1 change: 0 additions & 1 deletion src/vs/workbench/contrib/notebook/common/notebookCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ export type ICellEditOperation = ICellReplaceEdit | ICellOutputEdit | ICellMetad
export interface INotebookEditData {
documentVersionId: number;
cellEdits: ICellEditOperation[];
newMetadata?: NotebookDocumentMetadata;
}

export interface NotebookDataDto {
Expand Down

0 comments on commit 01f9355

Please sign in to comment.