Skip to content

Commit

Permalink
Restore animations when not paused in notebook cell.
Browse files Browse the repository at this point in the history
Restoring behavior that was there previously
  • Loading branch information
roblourens committed Jan 18, 2022
1 parent ecc1e95 commit fc183f2
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/


import { RunOnceScheduler } from 'vs/base/common/async';
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
import { ResourceMap } from 'vs/base/common/map';
import { Schemas } from 'vs/base/common/network';
Expand Down Expand Up @@ -133,22 +134,30 @@ Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).regi
class NotebookCellPausing extends Disposable implements IWorkbenchContribution {
private readonly _pausedCells = new Set<string>();

private _scheduler: RunOnceScheduler;

constructor(
@IDebugService private readonly _debugService: IDebugService,
@INotebookExecutionStateService private readonly _notebookExecutionStateService: INotebookExecutionStateService,
) {
super();

this._register(_debugService.getModel().onDidChangeCallStack(() => this.onDidChangeCallStack()));
this._register(_debugService.getModel().onDidChangeCallStack(() => {
// First update using the stale callstack if the real callstack is empty, to reduce blinking while stepping.
// After not pausing for 2s, update again with the latest callstack.
this.onDidChangeCallStack(true);
this._scheduler.schedule();
}));
this._scheduler = this._register(new RunOnceScheduler(() => this.onDidChangeCallStack(false), 2000));
}

private async onDidChangeCallStack(): Promise<void> {
private async onDidChangeCallStack(fallBackOnStaleCallstack: boolean): Promise<void> {
const newPausedCells = new Set<string>();

for (const session of this._debugService.getModel().getSessions()) {
for (const thread of session.getAllThreads()) {
let callStack = thread.getCallStack();
if (!callStack.length) {
if (fallBackOnStaleCallstack && !callStack.length) {
callStack = (thread as Thread).getStaleCallStack();
}

Expand All @@ -174,12 +183,13 @@ class NotebookCellPausing extends Disposable implements IWorkbenchContribution {

private editIsPaused(cellUri: URI, isPaused: boolean) {
const parsed = CellUri.parse(cellUri);
if (parsed && isPaused) {
if (parsed) {
const exeState = this._notebookExecutionStateService.getCellExecutionState(cellUri);
if (exeState) {
if (exeState && (exeState.isPaused !== isPaused || !exeState.didPause)) {
this._notebookExecutionStateService.updateNotebookCellExecution(parsed.notebook, parsed.handle, [{
editType: CellExecutionUpdateType.ExecutionState,
didPause: true
didPause: true,
isPaused
}]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class ExecutionStateCellStatusBarItem extends Disposable {
*/
private _getItemsForCell(): INotebookCellStatusBarItem[] | undefined {
const runState = this._executionStateService.getCellExecutionState(this._cell.uri);
if (this._currentExecutingStateTimer && !runState?.didPause) {
if (this._currentExecutingStateTimer && !runState?.isPaused) {
return;
}

Expand Down Expand Up @@ -159,7 +159,7 @@ class ExecutionStateCellStatusBarItem extends Disposable {
priority: Number.MAX_SAFE_INTEGER
};
} else if (state === NotebookCellExecutionState.Executing) {
const icon = runState?.didPause ?
const icon = runState?.isPaused ?
executingStateIcon :
ThemeIcon.modify(executingStateIcon, 'spin');
return <INotebookCellStatusBarItem>{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class ExecutionEditorProgressController extends Disposable implements INo

return false;
};
if (!executing.length || executing.some(executionIsVisible) || executing.some(e => e.didPause)) {
if (!executing.length || executing.some(executionIsVisible) || executing.some(e => e.isPaused)) {
this._notebookEditor.hideProgress();
} else {
this._notebookEditor.showProgress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ export class NotebookCellOutline extends Disposable implements IOutline<OutlineE
}

const exeState = !isMarkdown && this._notebookExecutionStateService.getCellExecutionState(cell.uri);
entries.push(new OutlineEntry(entries.length, 7, cell, preview, !!exeState, exeState ? exeState.didPause : false));
entries.push(new OutlineEntry(entries.length, 7, cell, preview, !!exeState, exeState ? exeState.isPaused : false));
}

if (cell.handle === focused) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ILogService } from 'vs/platform/log/common/log';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { CellEditType, CellUri, ICellEditOperation, NotebookCellExecutionState, NotebookCellInternalMetadata, NotebookTextModelWillAddRemoveEvent } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellExecutionUpdateType, INotebookExecutionService } from 'vs/workbench/contrib/notebook/common/notebookExecutionService';
import { ICellExecuteUpdate, ICellExecutionComplete, ICellExecutionEntry, ICellExecutionStateChangedEvent, INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService';
import { ICellExecuteUpdate, ICellExecutionComplete, ICellExecutionEntry, ICellExecutionStateChangedEvent, ICellExecutionStateUpdate, INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService';
import { INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService';
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';

Expand Down Expand Up @@ -300,6 +300,11 @@ class CellExecution implements ICellExecutionEntry {
return this._didPause;
}

private _isPaused = false;
get isPaused() {
return this._isPaused;
}

constructor(
readonly cellHandle: number,
private readonly _notebookModel: NotebookTextModel,
Expand Down Expand Up @@ -327,6 +332,11 @@ class CellExecution implements ICellExecutionEntry {
this._didPause = true;
}

const lastIsPausedUpdate = [...updates].reverse().find(u => u.editType === CellExecutionUpdateType.ExecutionState && typeof u.isPaused === 'boolean');
if (lastIsPausedUpdate) {
this._isPaused = (lastIsPausedUpdate as ICellExecutionStateUpdate).isPaused!;
}

const edits = updates.map(update => updateToEdit(update, this.cellHandle));
this._applyExecutionEdits(edits);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class CellProgressBar extends CellPart {
private _updateForExecutionState(element: ICellViewModel, e?: ICellExecutionStateChangedEvent): void {
const exeState = e?.changed ?? this._notebookExecutionStateService.getCellExecutionState(element.uri);
const progressBar = element.isInputCollapsed ? this._collapsedProgressBar : this._progressBar;
if (exeState?.state === NotebookCellExecutionState.Executing && !exeState.didPause) {
if (exeState?.state === NotebookCellExecutionState.Executing && !exeState.isPaused) {
showProgressBar(progressBar);
} else {
progressBar.hide();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface ICellExecutionStateUpdate {
executionOrder?: number;
runStartTime?: number;
didPause?: boolean;
isPaused?: boolean;
}

export interface ICellExecutionComplete {
Expand All @@ -28,6 +29,7 @@ export interface ICellExecutionEntry {
cellHandle: number;
state: NotebookCellExecutionState;
didPause: boolean;
isPaused: boolean;
}

export interface ICellExecutionStateChangedEvent {
Expand Down

0 comments on commit fc183f2

Please sign in to comment.