Make metadata/internalMetadata non-optional
This commit is contained in:
parent
dfb8c467ca
commit
2b8d74c4a8
20 changed files with 50 additions and 49 deletions
|
@ -440,12 +440,12 @@ suite('Notebook API tests', function () {
|
|||
await cellsChangeEvent;
|
||||
await cellMetadataChangeEvent;
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.document.cellCount, 3);
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.document.cellAt(0)?.metadata?.inputCollapsed, false);
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.document.cellAt(0)?.metadata.inputCollapsed, false);
|
||||
assert.strictEqual(version + 1, vscode.window.activeNotebookEditor!.document.version);
|
||||
|
||||
await vscode.commands.executeCommand('undo');
|
||||
assert.strictEqual(version + 2, vscode.window.activeNotebookEditor!.document.version);
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.document.cellAt(0)?.metadata?.inputCollapsed, undefined);
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.document.cellAt(0)?.metadata.inputCollapsed, undefined);
|
||||
assert.strictEqual(vscode.window.activeNotebookEditor!.document.cellCount, 2);
|
||||
});
|
||||
|
||||
|
|
|
@ -803,7 +803,7 @@ async function runCell(accessor: ServicesAccessor, context: INotebookActionConte
|
|||
}
|
||||
|
||||
if (context.ui && context.cell) {
|
||||
if (context.cell.internalMetadata?.runState === NotebookCellExecutionState.Executing) {
|
||||
if (context.cell.internalMetadata.runState === NotebookCellExecutionState.Executing) {
|
||||
return;
|
||||
}
|
||||
return context.notebookEditor.executeNotebookCells(Iterable.single(context.cell));
|
||||
|
@ -1251,7 +1251,7 @@ registerAction2(class ClearCellOutputsAction extends NotebookCellAction {
|
|||
|
||||
editor.viewModel.notebookDocument.applyEdits([{ editType: CellEditType.Output, index, outputs: [] }], true, undefined, () => undefined, undefined);
|
||||
|
||||
if (context.cell.internalMetadata?.runState !== NotebookCellExecutionState.Executing) {
|
||||
if (context.cell.internalMetadata.runState !== NotebookCellExecutionState.Executing) {
|
||||
context.notebookEditor.viewModel.notebookDocument.applyEdits([{
|
||||
editType: CellEditType.PartialInternalMetadata, index, internalMetadata: {
|
||||
runState: NotebookCellExecutionState.Idle,
|
||||
|
@ -1464,7 +1464,7 @@ registerAction2(class ClearAllCellOutputsAction extends NotebookAction {
|
|||
})), true, undefined, () => undefined, undefined);
|
||||
|
||||
const clearExecutionMetadataEdits = editor.viewModel.notebookDocument.cells.map((cell, index) => {
|
||||
if (cell.internalMetadata?.runState !== NotebookCellExecutionState.Executing) {
|
||||
if (cell.internalMetadata.runState !== NotebookCellExecutionState.Executing) {
|
||||
return {
|
||||
editType: CellEditType.PartialInternalMetadata, index, internalMetadata: {
|
||||
runState: NotebookCellExecutionState.Idle,
|
||||
|
|
|
@ -107,13 +107,13 @@ class ExecutionStateCellStatusBarHelper extends Disposable {
|
|||
return;
|
||||
}
|
||||
|
||||
const item = this._getItemForState(cell.internalMetadata?.runState ?? NotebookCellExecutionState.Idle, cell.internalMetadata?.lastRunSuccess);
|
||||
const item = this._getItemForState(cell.internalMetadata.runState ?? NotebookCellExecutionState.Idle, cell.internalMetadata.lastRunSuccess);
|
||||
|
||||
// Show the execution spinner for a minimum time
|
||||
if (cell.internalMetadata?.runState === NotebookCellExecutionState.Executing) {
|
||||
if (cell.internalMetadata.runState === NotebookCellExecutionState.Executing) {
|
||||
this._currentExecutingStateTimer = setTimeout(() => {
|
||||
this._currentExecutingStateTimer = undefined;
|
||||
if (cell.internalMetadata?.runState !== NotebookCellExecutionState.Executing) {
|
||||
if (cell.internalMetadata.runState !== NotebookCellExecutionState.Executing) {
|
||||
this._update();
|
||||
}
|
||||
}, ExecutionStateCellStatusBarHelper.MIN_SPINNER_TIME);
|
||||
|
@ -184,17 +184,17 @@ class TimerCellStatusBarHelper extends Disposable {
|
|||
|
||||
private async _update() {
|
||||
let item: INotebookCellStatusBarItem | undefined;
|
||||
const state = this._cell.internalMetadata?.runState ?? NotebookCellExecutionState.Idle;
|
||||
const state = this._cell.internalMetadata.runState ?? NotebookCellExecutionState.Idle;
|
||||
if (state === NotebookCellExecutionState.Executing) {
|
||||
const startTime = this._cell.internalMetadata?.runStartTime;
|
||||
const adjustment = this._cell.internalMetadata?.runStartTimeAdjustment;
|
||||
const startTime = this._cell.internalMetadata.runStartTime;
|
||||
const adjustment = this._cell.internalMetadata.runStartTimeAdjustment;
|
||||
if (typeof startTime === 'number') {
|
||||
item = this._getTimeItem(startTime, Date.now(), adjustment);
|
||||
this._scheduler.schedule();
|
||||
}
|
||||
} else if (state === NotebookCellExecutionState.Idle) {
|
||||
const startTime = this._cell.internalMetadata?.runStartTime;
|
||||
const endTime = this._cell.internalMetadata?.runEndTime;
|
||||
const startTime = this._cell.internalMetadata.runStartTime;
|
||||
const endTime = this._cell.internalMetadata.runEndTime;
|
||||
if (typeof startTime === 'number' && typeof endTime === 'number') {
|
||||
item = this._getTimeItem(startTime, endTime);
|
||||
}
|
||||
|
@ -262,7 +262,7 @@ class KeybindingPlaceholderStatusBarHelper extends Disposable {
|
|||
}
|
||||
|
||||
private _getItemsForCell(cell: ICellViewModel): INotebookCellStatusBarItem[] {
|
||||
if (typeof cell.internalMetadata?.runState !== 'undefined' || typeof cell.internalMetadata?.lastRunSuccess !== 'undefined') {
|
||||
if (typeof cell.internalMetadata.runState !== 'undefined' || typeof cell.internalMetadata.lastRunSuccess !== 'undefined') {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ class NotebookViewportContribution extends Disposable implements INotebookEditor
|
|||
cellRangesToIndexes(visibleRanges).forEach(index => {
|
||||
const cell = this._notebookEditor.viewModel?.viewCells[index];
|
||||
|
||||
if (cell?.cellKind === CellKind.Markup && cell?.getEditState() === CellEditState.Preview && !cell.metadata?.inputCollapsed) {
|
||||
if (cell?.cellKind === CellKind.Markup && cell?.getEditState() === CellEditState.Preview && !cell.metadata.inputCollapsed) {
|
||||
this._notebookEditor.createMarkdownPreview(cell);
|
||||
} else if (cell?.cellKind === CellKind.Code) {
|
||||
const viewCell = (cell as CodeCellViewModel);
|
||||
|
|
|
@ -318,7 +318,7 @@ class CellInfoContentProvider {
|
|||
|
||||
for (const cell of ref.object.notebook.cells) {
|
||||
if (cell.handle === data.handle) {
|
||||
const metadataSource = getFormatedMetadataJSON(ref.object.notebook, cell.metadata || {}, cell.language);
|
||||
const metadataSource = getFormatedMetadataJSON(ref.object.notebook, cell.metadata, cell.language);
|
||||
result = this._modelService.createModel(
|
||||
metadataSource,
|
||||
mode,
|
||||
|
|
|
@ -133,7 +133,7 @@ export interface IGenericCellViewModel {
|
|||
id: string;
|
||||
handle: number;
|
||||
uri: URI;
|
||||
metadata: NotebookCellMetadata | undefined;
|
||||
metadata: NotebookCellMetadata;
|
||||
outputIsHovered: boolean;
|
||||
outputIsFocused: boolean;
|
||||
outputsViewModels: ICellOutputViewModel[];
|
||||
|
@ -262,8 +262,8 @@ export interface ICellViewModel extends IGenericCellViewModel {
|
|||
getText(): string;
|
||||
getTextLength(): number;
|
||||
getHeight(lineHeight: number): number;
|
||||
metadata: NotebookCellMetadata | undefined;
|
||||
internalMetadata: NotebookCellInternalMetadata | undefined;
|
||||
metadata: NotebookCellMetadata;
|
||||
internalMetadata: NotebookCellInternalMetadata;
|
||||
textModel: ITextModel | undefined;
|
||||
hasModel(): this is IEditableCellViewModel;
|
||||
resolveTextModel(): Promise<ITextModel>;
|
||||
|
|
|
@ -47,7 +47,7 @@ export class NotebookEditorKernelManager extends Disposable {
|
|||
|
||||
const cellHandles: number[] = [];
|
||||
for (const cell of cells) {
|
||||
if (cell.cellKind !== CellKind.Code || cell.internalMetadata?.runState === NotebookCellExecutionState.Pending || cell.internalMetadata?.runState === NotebookCellExecutionState.Executing) {
|
||||
if (cell.cellKind !== CellKind.Code || cell.internalMetadata.runState === NotebookCellExecutionState.Pending || cell.internalMetadata.runState === NotebookCellExecutionState.Executing) {
|
||||
continue;
|
||||
}
|
||||
if (!kernel.supportedLanguages.includes(cell.language)) {
|
||||
|
|
|
@ -69,9 +69,9 @@ export class NotebookEditorContextKeys {
|
|||
if (!e.runStateChanged) {
|
||||
return;
|
||||
}
|
||||
if (c.internalMetadata?.runState === NotebookCellExecutionState.Pending) {
|
||||
if (c.internalMetadata.runState === NotebookCellExecutionState.Pending) {
|
||||
executionCount++;
|
||||
} else if (c.internalMetadata?.runState === NotebookCellExecutionState.Idle) {
|
||||
} else if (c.internalMetadata.runState === NotebookCellExecutionState.Idle) {
|
||||
executionCount--;
|
||||
}
|
||||
this._someCellRunning.set(executionCount > 0);
|
||||
|
|
|
@ -177,7 +177,7 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> implements ID
|
|||
this._localDisposableStore.add(this.view.onMouseDblClick(() => {
|
||||
const focus = this.getFocusedElements()[0];
|
||||
|
||||
if (focus && focus.cellKind === CellKind.Markup && !focus.metadata?.inputCollapsed) {
|
||||
if (focus && focus.cellKind === CellKind.Markup && !focus.metadata.inputCollapsed) {
|
||||
focus.updateEditState(CellEditState.Editing, 'dbclick');
|
||||
focus.focusMode = CellFocusMode.Editor;
|
||||
}
|
||||
|
|
|
@ -1181,7 +1181,7 @@ var requirejs = (function() {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (cell.metadata?.outputCollapsed) {
|
||||
if (cell.metadata.outputCollapsed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -145,8 +145,8 @@ export class CellContextKeyManager extends Disposable {
|
|||
}
|
||||
|
||||
private updateForCollapseState() {
|
||||
this.cellContentCollapsed.set(!!this.element.metadata?.inputCollapsed);
|
||||
this.cellOutputCollapsed.set(!!this.element.metadata?.outputCollapsed);
|
||||
this.cellContentCollapsed.set(!!this.element.metadata.inputCollapsed);
|
||||
this.cellOutputCollapsed.set(!!this.element.metadata.outputCollapsed);
|
||||
}
|
||||
|
||||
private updateForOutputs() {
|
||||
|
|
|
@ -263,11 +263,11 @@ abstract class AbstractCellRenderer {
|
|||
return;
|
||||
}
|
||||
|
||||
if (templateData.currentRenderedCell.metadata?.inputCollapsed) {
|
||||
if (templateData.currentRenderedCell.metadata.inputCollapsed) {
|
||||
textModel.applyEdits([
|
||||
{ editType: CellEditType.Metadata, index, metadata: { ...templateData.currentRenderedCell.metadata, inputCollapsed: false } }
|
||||
], true, undefined, () => undefined, undefined);
|
||||
} else if (templateData.currentRenderedCell.metadata?.outputCollapsed) {
|
||||
} else if (templateData.currentRenderedCell.metadata.outputCollapsed) {
|
||||
textModel.applyEdits([
|
||||
{ editType: CellEditType.Metadata, index, metadata: { ...templateData.currentRenderedCell.metadata, outputCollapsed: false } }
|
||||
], true, undefined, () => undefined, undefined);
|
||||
|
@ -519,7 +519,7 @@ export class MarkdownCellRenderer extends AbstractCellRenderer implements IListR
|
|||
}
|
||||
|
||||
private updateCollapsedState(element: MarkdownCellViewModel) {
|
||||
if (element.metadata?.inputCollapsed) {
|
||||
if (element.metadata.inputCollapsed) {
|
||||
this.notebookEditor.hideMarkdownPreviews([element]);
|
||||
} else {
|
||||
this.notebookEditor.unhideMarkdownPreviews([element]);
|
||||
|
@ -787,8 +787,8 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
|
|||
const clickedOnInput = e.offsetY < (cell.layoutInfo as CodeCellLayoutInfo).outputContainerOffset;
|
||||
const viewModel = this.notebookEditor.viewModel!;
|
||||
const metadata: Partial<NotebookCellMetadata> = clickedOnInput ?
|
||||
{ inputCollapsed: !cell.metadata?.inputCollapsed } :
|
||||
{ outputCollapsed: !cell.metadata?.outputCollapsed };
|
||||
{ inputCollapsed: !cell.metadata.inputCollapsed } :
|
||||
{ outputCollapsed: !cell.metadata.outputCollapsed };
|
||||
viewModel.notebookDocument.applyEdits([
|
||||
{
|
||||
editType: CellEditType.PartialMetadata,
|
||||
|
@ -804,7 +804,7 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
|
|||
return;
|
||||
}
|
||||
|
||||
const metadata: Partial<NotebookCellMetadata> = cell.metadata?.inputCollapsed ?
|
||||
const metadata: Partial<NotebookCellMetadata> = cell.metadata.inputCollapsed ?
|
||||
{ inputCollapsed: false } :
|
||||
{ outputCollapsed: false };
|
||||
const viewModel = this.notebookEditor.viewModel!;
|
||||
|
|
|
@ -225,11 +225,11 @@ export class CodeCell extends Disposable {
|
|||
|
||||
this.viewCell.layoutChange({});
|
||||
|
||||
if (this.viewCell.metadata?.inputCollapsed && this.viewCell.metadata.outputCollapsed) {
|
||||
if (this.viewCell.metadata.inputCollapsed && this.viewCell.metadata.outputCollapsed) {
|
||||
this.viewUpdateAllCollapsed();
|
||||
} else if (this.viewCell.metadata?.inputCollapsed) {
|
||||
} else if (this.viewCell.metadata.inputCollapsed) {
|
||||
this.viewUpdateInputCollapsed();
|
||||
} else if (this.viewCell.metadata?.outputCollapsed && this.viewCell.outputsViewModels.length) {
|
||||
} else if (this.viewCell.metadata.outputCollapsed && this.viewCell.outputsViewModels.length) {
|
||||
this.viewUpdateOutputCollapsed();
|
||||
} else {
|
||||
this.viewUpdateExpanded();
|
||||
|
|
|
@ -242,7 +242,7 @@ export class StatefulMarkdownCell extends Disposable {
|
|||
}
|
||||
|
||||
private viewUpdate(): void {
|
||||
if (this.viewCell.metadata?.inputCollapsed) {
|
||||
if (this.viewCell.metadata.inputCollapsed) {
|
||||
this.viewUpdateCollapsed();
|
||||
} else if (this.viewCell.getEditState() === CellEditState.Editing) {
|
||||
this.viewUpdateEditing();
|
||||
|
|
|
@ -117,11 +117,11 @@ export class CodeCellViewModel extends BaseCellViewModel implements ICellViewMod
|
|||
}));
|
||||
|
||||
this._register(this.model.onDidChangeMetadata(e => {
|
||||
if (this.metadata?.outputCollapsed) {
|
||||
if (this.metadata.outputCollapsed) {
|
||||
this._onDidHideOutputs.fire(this.outputsViewModels.slice(0));
|
||||
}
|
||||
|
||||
if (this.metadata?.inputCollapsed) {
|
||||
if (this.metadata.inputCollapsed) {
|
||||
this._onDidHideInput.fire();
|
||||
}
|
||||
}));
|
||||
|
@ -150,9 +150,9 @@ export class CodeCellViewModel extends BaseCellViewModel implements ICellViewMod
|
|||
this._ensureOutputsTop();
|
||||
const notebookLayoutConfiguration = this.viewContext.notebookOptions.getLayoutConfiguration();
|
||||
const outputShowMoreContainerHeight = state.outputShowMoreContainerHeight ? state.outputShowMoreContainerHeight : this._layoutInfo.outputShowMoreContainerHeight;
|
||||
let outputTotalHeight = Math.max(this._outputMinHeight, this.metadata?.outputCollapsed ? notebookLayoutConfiguration.collapsedIndicatorHeight : this._outputsTop!.getTotalValue());
|
||||
let outputTotalHeight = Math.max(this._outputMinHeight, this.metadata.outputCollapsed ? notebookLayoutConfiguration.collapsedIndicatorHeight : this._outputsTop!.getTotalValue());
|
||||
|
||||
if (!this.metadata?.inputCollapsed) {
|
||||
if (!this.metadata.inputCollapsed) {
|
||||
let newState: CodeCellLayoutState;
|
||||
let editorHeight: number;
|
||||
let totalHeight: number;
|
||||
|
@ -201,7 +201,7 @@ export class CodeCellViewModel extends BaseCellViewModel implements ICellViewMod
|
|||
layoutState: newState
|
||||
};
|
||||
} else {
|
||||
outputTotalHeight = Math.max(this._outputMinHeight, this.metadata?.inputCollapsed && this.metadata.outputCollapsed ? 0 : outputTotalHeight);
|
||||
outputTotalHeight = Math.max(this._outputMinHeight, this.metadata.inputCollapsed && this.metadata.outputCollapsed ? 0 : outputTotalHeight);
|
||||
const indicatorHeight = notebookLayoutConfiguration.collapsedIndicatorHeight + outputTotalHeight + outputShowMoreContainerHeight;
|
||||
|
||||
const outputContainerOffset = notebookLayoutConfiguration.cellTopMargin + notebookLayoutConfiguration.collapsedIndicatorHeight;
|
||||
|
|
|
@ -129,7 +129,7 @@ export class MarkdownCellViewModel extends BaseCellViewModel implements ICellVie
|
|||
}));
|
||||
|
||||
this._register(model.onDidChangeMetadata(e => {
|
||||
if (this.metadata?.inputCollapsed) {
|
||||
if (this.metadata.inputCollapsed) {
|
||||
this._onDidHideInput.fire();
|
||||
}
|
||||
}));
|
||||
|
@ -153,7 +153,7 @@ export class MarkdownCellViewModel extends BaseCellViewModel implements ICellVie
|
|||
|
||||
layoutChange(state: MarkdownCellLayoutChangeEvent) {
|
||||
// recompute
|
||||
if (!this.metadata?.inputCollapsed) {
|
||||
if (!this.metadata.inputCollapsed) {
|
||||
const editorWidth = state.outerWidth !== undefined
|
||||
? this.viewContext.notebookOptions.computeMarkdownCellEditorWidth(state.outerWidth)
|
||||
: this._layoutInfo.editorWidth;
|
||||
|
|
|
@ -169,8 +169,8 @@ export class NotebookCellTextModel extends Disposable implements ICell {
|
|||
) {
|
||||
super();
|
||||
this._outputs = outputs.map(op => new NotebookCellOutputTextModel(op));
|
||||
this._metadata = metadata || {};
|
||||
this._internalMetadata = internalMetadata || {};
|
||||
this._metadata = metadata ?? {};
|
||||
this._internalMetadata = internalMetadata ?? {};
|
||||
}
|
||||
|
||||
getValue(): string {
|
||||
|
|
|
@ -284,7 +284,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
|
|||
const mainCells = cells.map(cell => {
|
||||
const cellHandle = this._cellhandlePool++;
|
||||
const cellUri = CellUri.generate(this.uri, cellHandle);
|
||||
return new NotebookCellTextModel(cellUri, cellHandle, cell.source, cell.language, cell.cellKind, cell.outputs || [], cell.metadata, cell.internalMetadata, this.transientOptions, this._modeService);
|
||||
return new NotebookCellTextModel(cellUri, cellHandle, cell.source, cell.language, cell.cellKind, cell.outputs, cell.metadata, cell.internalMetadata, this.transientOptions, this._modeService);
|
||||
});
|
||||
|
||||
for (let i = 0; i < mainCells.length; i++) {
|
||||
|
|
|
@ -195,7 +195,8 @@ export interface ICell {
|
|||
language: string;
|
||||
cellKind: CellKind;
|
||||
outputs: ICellOutput[];
|
||||
metadata?: NotebookCellMetadata;
|
||||
metadata: NotebookCellMetadata;
|
||||
internalMetadata: NotebookCellInternalMetadata;
|
||||
onDidChangeOutputs?: Event<NotebookCellOutputsSplice[]>;
|
||||
onDidChangeLanguage: Event<string>;
|
||||
onDidChangeMetadata: Event<void>;
|
||||
|
|
|
@ -304,7 +304,7 @@ suite('NotebookTextModel', () => {
|
|||
}], true, undefined, () => undefined, undefined);
|
||||
|
||||
assert.strictEqual(textModel.cells.length, 1);
|
||||
assert.strictEqual(textModel.cells[0].metadata?.customProperty, undefined);
|
||||
assert.strictEqual(textModel.cells[0].metadata.customProperty, undefined);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -330,7 +330,7 @@ suite('NotebookTextModel', () => {
|
|||
}], true, undefined, () => undefined, undefined);
|
||||
|
||||
assert.strictEqual(textModel.cells.length, 1);
|
||||
assert.strictEqual(textModel.cells[0].metadata?.customProperty, 15);
|
||||
assert.strictEqual(textModel.cells[0].metadata.customProperty, 15);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue