-
Notifications
You must be signed in to change notification settings - Fork 30.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show cell execution state when collapsed. Fix #131200
- Loading branch information
1 parent
1d9e655
commit 679fc19
Showing
4 changed files
with
134 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/vs/workbench/contrib/notebook/browser/view/cellParts/codeCellExecutionIcon.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as DOM from 'vs/base/browser/dom'; | ||
import { renderLabelWithIcons } from 'vs/base/browser/ui/iconLabel/iconLabels'; | ||
import { Disposable } from 'vs/base/common/lifecycle'; | ||
import { localize } from 'vs/nls'; | ||
import { ThemeIcon } from 'vs/platform/theme/common/themeService'; | ||
import { ICellViewModel, INotebookEditorDelegate } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; | ||
import { errorStateIcon, executingStateIcon, pendingStateIcon, successStateIcon } from 'vs/workbench/contrib/notebook/browser/notebookIcons'; | ||
import { NotebookCellExecutionState, NotebookCellInternalMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon'; | ||
import { INotebookCellExecution, INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService'; | ||
|
||
interface IExecutionItem { | ||
text: string; | ||
tooltip?: string; | ||
} | ||
|
||
export class CodeCellExecutionIcon extends Disposable { | ||
private _visible = false; | ||
|
||
constructor( | ||
_notebookEditor: INotebookEditorDelegate, | ||
private readonly _cell: ICellViewModel, | ||
private readonly _element: HTMLElement, | ||
@INotebookExecutionStateService private _executionStateService: INotebookExecutionStateService, | ||
) { | ||
super(); | ||
|
||
this._update(); | ||
this._register(this._executionStateService.onDidChangeCellExecution(e => { | ||
if (e.affectsCell(this._cell.uri)) { | ||
this._update(); | ||
} | ||
})); | ||
this._register(this._cell.model.onDidChangeInternalMetadata(() => this._update())); | ||
} | ||
|
||
setVisibility(visible: boolean): void { | ||
this._visible = visible; | ||
this._update(); | ||
} | ||
|
||
private _update() { | ||
if (!this._visible) { | ||
return; | ||
} | ||
|
||
const runState = this._executionStateService.getCellExecution(this._cell.uri); | ||
const item = this._getItemForState(runState, this._cell.model.internalMetadata); | ||
if (item) { | ||
this._element.style.display = ''; | ||
DOM.reset(this._element, ...renderLabelWithIcons(item.text)); | ||
this._element.title = item.tooltip ?? ''; | ||
} else { | ||
this._element.style.display = 'none'; | ||
DOM.reset(this._element); | ||
} | ||
} | ||
|
||
private _getItemForState(runState: INotebookCellExecution | undefined, internalMetadata: NotebookCellInternalMetadata): IExecutionItem | undefined { | ||
const state = runState?.state; | ||
const { lastRunSuccess } = internalMetadata; | ||
if (!state && lastRunSuccess) { | ||
return <IExecutionItem>{ | ||
text: `$(${successStateIcon.id})`, | ||
tooltip: localize('notebook.cell.status.success', "Success"), | ||
}; | ||
} else if (!state && lastRunSuccess === false) { | ||
return <IExecutionItem>{ | ||
text: `$(${errorStateIcon.id})`, | ||
tooltip: localize('notebook.cell.status.failed', "Failed"), | ||
}; | ||
} else if (state === NotebookCellExecutionState.Pending) { | ||
return <IExecutionItem>{ | ||
text: `$(${pendingStateIcon.id})`, | ||
tooltip: localize('notebook.cell.status.pending', "Pending"), | ||
}; | ||
} else if (state === NotebookCellExecutionState.Executing) { | ||
const icon = runState?.isPaused ? | ||
executingStateIcon : | ||
ThemeIcon.modify(executingStateIcon, 'spin'); | ||
return <IExecutionItem>{ | ||
text: `$(${icon.id})`, | ||
tooltip: localize('notebook.cell.status.executing', "Executing"), | ||
}; | ||
} | ||
|
||
return; | ||
} | ||
} |