use metadata classes for cell and notebook document implementation, https://github.com/microsoft/vscode/issues/116333

This commit is contained in:
Johannes Rieken
2021-02-15 16:54:24 +01:00
parent f2a491fbc8
commit 5f48de03e6
3 changed files with 47 additions and 27 deletions

View File

@@ -12,6 +12,7 @@ import { URI } from 'vs/base/common/uri';
import { CellKind, INotebookDocumentPropertiesChangeData } from 'vs/workbench/api/common/extHost.protocol';
import { ExtHostDocumentsAndEditors, IExtHostModelAddedData } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
import * as extHostTypeConverters from 'vs/workbench/api/common/extHostTypeConverters';
import * as extHostTypes from 'vs/workbench/api/common/extHostTypes';
import { IMainCellDto, IOutputDto, NotebookCellMetadata, NotebookCellsChangedEventDto, NotebookCellsChangeType, NotebookCellsSplice2, notebookDocumentMetadataDefaults } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import * as vscode from 'vscode';
@@ -47,7 +48,7 @@ export class ExtHostCell {
readonly onDidDispose: Event<void> = this._onDidDispose.event;
private _outputs: IOutputDto[];
private _metadata: vscode.NotebookCellMetadata;
private _metadata: extHostTypes.NotebookCellMetadata;
readonly handle: number;
readonly uri: URI;
@@ -64,7 +65,7 @@ export class ExtHostCell {
this.uri = URI.revive(_cellData.uri);
this.cellKind = _cellData.cellKind;
this._outputs = _cellData.outputs;
this._metadata = _cellData.metadata ?? {};
this._metadata = extHostTypeConverters.NotebookCellMetadata.to(_cellData.metadata ?? {});
}
dispose() {
@@ -99,8 +100,8 @@ export class ExtHostCell {
this._outputs = newOutputs;
}
setMetadata(newMetadata: vscode.NotebookCellMetadata): void {
this._metadata = newMetadata;
setMetadata(newMetadata: NotebookCellMetadata): void {
this._metadata = extHostTypeConverters.NotebookCellMetadata.to(newMetadata);
}
}
@@ -138,7 +139,7 @@ export class ExtHostNotebookDocument extends Disposable {
private readonly _emitter: INotebookEventEmitter,
private readonly _viewType: string,
private readonly _contentOptions: vscode.NotebookDocumentContentOptions,
private _metadata: Required<vscode.NotebookDocumentMetadata>,
private _metadata: extHostTypes.NotebookDocumentMetadata,
public readonly uri: URI,
private readonly _storagePath: URI | undefined
) {
@@ -194,7 +195,7 @@ export class ExtHostNotebookDocument extends Disposable {
...notebookDocumentMetadataDefaults,
...data.metadata
};
this._metadata = newMetadata;
this._metadata = this._metadata.with(newMetadata);
this._emitter.emitDocumentMetadataChange({ document: this.notebookDocument });
}