Remove NotebookCellExecutionState.Idle

This commit is contained in:
Rob Lourens 2021-05-13 11:34:02 -07:00
parent 2b8d74c4a8
commit 5b13f40b47
7 changed files with 36 additions and 38 deletions

View file

@ -16,9 +16,8 @@ import { asWebviewUri } from 'vs/workbench/api/common/shared/webview';
import { ResourceMap } from 'vs/base/common/map';
import { timeout } from 'vs/base/common/async';
import { ExtHostCell, ExtHostNotebookDocument } from 'vs/workbench/api/common/extHostNotebookDocument';
import { CellEditType, IImmediateCellEditOperation, NullablePartialNotebookCellInternalMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellEditType, IImmediateCellEditOperation, NotebookCellExecutionState, NullablePartialNotebookCellInternalMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CancellationTokenSource } from 'vs/base/common/cancellation';
import { NotebookCellExecutionState } from 'vs/workbench/api/common/extHostTypes';
import { asArray } from 'vs/base/common/arrays';
import { ILogService } from 'vs/platform/log/common/log';
@ -426,7 +425,7 @@ class NotebookCellExecutionTask extends Disposable {
that._onDidChangeState.fire();
that.mixinMetadata({
runState: NotebookCellExecutionState.Idle,
runState: null,
lastRunSuccess: result?.success ?? null,
runEndTime: result?.endTime ?? null,
});

View file

@ -1254,12 +1254,12 @@ registerAction2(class ClearCellOutputsAction extends NotebookCellAction {
if (context.cell.internalMetadata.runState !== NotebookCellExecutionState.Executing) {
context.notebookEditor.viewModel.notebookDocument.applyEdits([{
editType: CellEditType.PartialInternalMetadata, index, internalMetadata: {
runState: NotebookCellExecutionState.Idle,
runStartTime: undefined,
runStartTimeAdjustment: undefined,
runEndTime: undefined,
executionOrder: undefined,
lastRunSuccess: undefined
runState: null,
runStartTime: null,
runStartTimeAdjustment: null,
runEndTime: null,
executionOrder: null,
lastRunSuccess: null
}
}], true, undefined, () => undefined, undefined);
}
@ -1467,12 +1467,12 @@ registerAction2(class ClearAllCellOutputsAction extends NotebookAction {
if (cell.internalMetadata.runState !== NotebookCellExecutionState.Executing) {
return {
editType: CellEditType.PartialInternalMetadata, index, internalMetadata: {
runState: NotebookCellExecutionState.Idle,
runStartTime: undefined,
runStartTimeAdjustment: undefined,
runEndTime: undefined,
executionOrder: undefined,
lastRunSuccess: undefined
runState: null,
runStartTime: null,
runStartTimeAdjustment: null,
runEndTime: null,
executionOrder: null,
lastRunSuccess: null
}
};
} else {

View file

@ -107,7 +107,7 @@ class ExecutionStateCellStatusBarHelper extends Disposable {
return;
}
const item = this._getItemForState(cell.internalMetadata.runState ?? NotebookCellExecutionState.Idle, cell.internalMetadata.lastRunSuccess);
const item = this._getItemForState(cell.internalMetadata.runState, cell.internalMetadata.lastRunSuccess);
// Show the execution spinner for a minimum time
if (cell.internalMetadata.runState === NotebookCellExecutionState.Executing) {
@ -123,7 +123,7 @@ class ExecutionStateCellStatusBarHelper extends Disposable {
}
private _getItemForState(runState: NotebookCellExecutionState | undefined, lastRunSuccess: boolean | undefined): INotebookCellStatusBarItem | undefined {
if (runState === NotebookCellExecutionState.Idle && lastRunSuccess) {
if (!runState && lastRunSuccess) {
return <INotebookCellStatusBarItem>{
text: '$(notebook-state-success)',
color: themeColorFromId(cellStatusIconSuccess),
@ -131,7 +131,7 @@ class ExecutionStateCellStatusBarHelper extends Disposable {
alignment: CellStatusbarAlignment.Left,
priority: Number.MAX_SAFE_INTEGER
};
} else if (runState === NotebookCellExecutionState.Idle && lastRunSuccess === false) {
} else if (!runState && lastRunSuccess === false) {
return <INotebookCellStatusBarItem>{
text: '$(notebook-state-error)',
color: themeColorFromId(cellStatusIconError),
@ -184,7 +184,7 @@ 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;
if (state === NotebookCellExecutionState.Executing) {
const startTime = this._cell.internalMetadata.runStartTime;
const adjustment = this._cell.internalMetadata.runStartTimeAdjustment;
@ -192,7 +192,7 @@ class TimerCellStatusBarHelper extends Disposable {
item = this._getTimeItem(startTime, Date.now(), adjustment);
this._scheduler.schedule();
}
} else if (state === NotebookCellExecutionState.Idle) {
} else if (!state) {
const startTime = this._cell.internalMetadata.runStartTime;
const endTime = this._cell.internalMetadata.runEndTime;
if (typeof startTime === 'number' && typeof endTime === 'number') {

View file

@ -71,7 +71,7 @@ export class NotebookEditorContextKeys {
}
if (c.internalMetadata.runState === NotebookCellExecutionState.Pending) {
executionCount++;
} else if (c.internalMetadata.runState === NotebookCellExecutionState.Idle) {
} else if (!c.internalMetadata.runState) {
executionCount--;
}
this._someCellRunning.set(executionCount > 0);

View file

@ -118,21 +118,19 @@ export class CellContextKeyManager extends Disposable {
const internalMetadata = this.element.internalMetadata;
this.cellEditable.set(!this.notebookEditor.viewModel?.options.isReadOnly);
const runState = internalMetadata.runState ?? NotebookCellExecutionState.Idle;
const runState = internalMetadata.runState;
if (this.element instanceof MarkdownCellViewModel) {
this.cellRunState.reset();
} else if (runState === NotebookCellExecutionState.Idle) {
if (internalMetadata.lastRunSuccess === true) {
this.cellRunState.set('succeeded');
} else if (internalMetadata.lastRunSuccess === false) {
this.cellRunState.set('failed');
} else {
this.cellRunState.set('idle');
}
} else if (runState === NotebookCellExecutionState.Executing) {
this.cellRunState.set('executing');
} else if (runState === NotebookCellExecutionState.Pending) {
this.cellRunState.set('pending');
} else if (internalMetadata.lastRunSuccess === true) {
this.cellRunState.set('succeeded');
} else if (internalMetadata.lastRunSuccess === false) {
this.cellRunState.set('failed');
} else {
this.cellRunState.set('idle');
}
}

View file

@ -1070,7 +1070,7 @@ export class RunStateRenderer {
}
}
renderState(runState: NotebookCellExecutionState = NotebookCellExecutionState.Idle, getCellIndex: () => number, lastRunSuccess: boolean | undefined = undefined) {
renderState(runState: NotebookCellExecutionState | undefined, getCellIndex: () => number, lastRunSuccess: boolean | undefined = undefined) {
if (this.spinnerTimer) {
this.pendingNewState = runState;
this.pendingLastRunSuccess = lastRunSuccess;
@ -1078,10 +1078,10 @@ export class RunStateRenderer {
}
let runStateTooltip: string | undefined;
if (runState === NotebookCellExecutionState.Idle && lastRunSuccess) {
if (!runState && lastRunSuccess) {
aria.alert(`Code cell at ${getCellIndex()} finishes running successfully`);
DOM.reset(this.element, renderIcon(successStateIcon));
} else if (runState === NotebookCellExecutionState.Idle && !lastRunSuccess) {
} else if (!runState && !lastRunSuccess) {
aria.alert(`Code cell at ${getCellIndex()} finishes running with errors`);
DOM.reset(this.element, renderIcon(errorStateIcon));
} else if (runState === NotebookCellExecutionState.Executing) {
@ -1105,7 +1105,7 @@ export class RunStateRenderer {
this.element.innerText = '';
}
if (runState === NotebookCellExecutionState.Idle && typeof lastRunSuccess !== 'boolean') {
if (!runState && typeof lastRunSuccess !== 'boolean') {
DOM.hide(this.element);
} else {
this.element.style.display = 'flex';

View file

@ -67,10 +67,10 @@ export interface NotebookDocumentMetadata {
[key: string]: unknown;
}
// Aligns with the vscode.d.ts version
export enum NotebookCellExecutionState {
Idle = 1,
Pending = 2,
Executing = 3,
Executing = 3
}
export interface INotebookCellPreviousExecutionResult {
@ -412,6 +412,7 @@ export interface ICellMetadataEdit {
metadata: NotebookCellMetadata;
}
// These types are nullable because we need to use 'null' on the EH side so it is JSON-stringified
export type NullablePartialNotebookCellMetadata = {
[Key in keyof Partial<NotebookCellMetadata>]: NotebookCellMetadata[Key] | null
};
@ -425,7 +426,7 @@ export interface ICellPartialMetadataEdit {
export interface ICellPartialMetadataEditByHandle {
editType: CellEditType.PartialMetadata;
handle: number;
metadata: Partial<NullablePartialNotebookCellMetadata>;
metadata: NullablePartialNotebookCellMetadata;
}
export type NullablePartialNotebookCellInternalMetadata = {
@ -440,7 +441,7 @@ export interface ICellPartialInternalMetadataEdit {
export interface ICellPartialInternalMetadataEditByHandle {
editType: CellEditType.PartialInternalMetadata;
handle: number;
internalMetadata: Partial<NullablePartialNotebookCellInternalMetadata>;
internalMetadata: NullablePartialNotebookCellInternalMetadata;
}
export interface ICellLanguageEdit {