Skip to content

Commit

Permalink
Show editor progress bar when executing cell is scrolled out of view
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Dec 30, 2021
1 parent 9736840 commit 7ad85a6
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { throttle } from 'vs/base/common/decorators';
import { Disposable } from 'vs/base/common/lifecycle';
import { INotebookEditor, INotebookEditorContribution } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { registerNotebookContribution } from 'vs/workbench/contrib/notebook/browser/notebookEditorExtensions';
import { NotebookCellExecutionState } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { ICellExecutionEntry, INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService';

export class ExecutionEditorProgressController extends Disposable implements INotebookEditorContribution {
static id: string = 'workbench.notebook.executionEditorProgress';

constructor(
private readonly _notebookEditor: INotebookEditor,
@INotebookExecutionStateService private readonly _notebookExecutionStateService: INotebookExecutionStateService
) {
super();

this._register(_notebookEditor.onDidChangeVisibleRanges(() => this._update()));

this._register(_notebookExecutionStateService.onDidChangeCellExecution(e => {
if (e.notebook !== this._notebookEditor.textModel?.uri) {
return;
}

this._update();
}));

this._register(_notebookEditor.onDidChangeModel(() => this._update()));
}

@throttle(100)
private _update() {
if (!this._notebookEditor.hasModel()) {
return;
}

const executing = this._notebookExecutionStateService.getCellExecutionStatesForNotebook(this._notebookEditor.textModel?.uri)
.filter(exe => exe.state === NotebookCellExecutionState.Executing);
const executionIsVisible = (exe: ICellExecutionEntry) => {
for (const range of this._notebookEditor.visibleRanges) {
for (const cell of this._notebookEditor.getCellsInRange(range)) {
if (cell.handle === exe.cellHandle) {
return true;
}
}
}

return false;
};
if (!executing.length || executing.some(executionIsVisible)) {
this._notebookEditor.hideProgress();
} else {
this._notebookEditor.showProgress();
}
}
}


registerNotebookContribution(ExecutionEditorProgressController.id, ExecutionEditorProgressController);
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ import 'vs/workbench/contrib/notebook/browser/contrib/viewportCustomMarkdown/vie
import 'vs/workbench/contrib/notebook/browser/contrib/troubleshoot/layout';
import 'vs/workbench/contrib/notebook/browser/contrib/codeRenderer/codeRenderer';
import 'vs/workbench/contrib/notebook/browser/contrib/breakpoints/notebookBreakpoints';
import 'vs/workbench/contrib/notebook/browser/contrib/execute/executionEditorProgress';

// Diff Editor Contribution
import 'vs/workbench/contrib/notebook/browser/diff/notebookDiffActions';
Expand Down
3 changes: 3 additions & 0 deletions src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,9 @@ export interface INotebookEditor {
getCellByHandle(handle: number): ICellViewModel | undefined;
getCellIndex(cell: ICellViewModel): number | undefined;
getNextVisibleCellIndex(index: number): number | undefined;

showProgress(): void;
hideProgress(): void;
}

export interface IActiveNotebookEditor extends INotebookEditor {
Expand Down
15 changes: 15 additions & 0 deletions src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
import { INotebookRendererMessagingService } from 'vs/workbench/contrib/notebook/common/notebookRendererMessagingService';
import { editorGutterModifiedBackground } from 'vs/workbench/contrib/scm/browser/dirtydiffDecorator';
import { IWebview } from 'vs/workbench/contrib/webview/browser/webview';
import { IEditorProgressService, IProgressRunner } from 'vs/platform/progress/common/progress';

const $ = DOM.$;

Expand Down Expand Up @@ -383,6 +384,8 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
private readonly instantiationService: IInstantiationService;
private readonly _notebookOptions: NotebookOptions;

private _currentProgress: IProgressRunner | undefined;

get notebookOptions() {
return this._notebookOptions;
}
Expand All @@ -402,6 +405,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
@ITelemetryService private readonly telemetryService: ITelemetryService,
@INotebookExecutionService private readonly notebookExecutionService: INotebookExecutionService,
@INotebookExecutionStateService notebookExecutionStateService: INotebookExecutionStateService,
@IEditorProgressService private readonly editorProgressService: IEditorProgressService,
) {
super();
this.isEmbedded = creationOptions.isEmbedded ?? false;
Expand Down Expand Up @@ -585,6 +589,17 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
return !!this._notebookViewModel;
}

showProgress(): void {
this._currentProgress = this.editorProgressService.show(true);
}

hideProgress(): void {
if (this._currentProgress) {
this._currentProgress.done();
this._currentProgress = undefined;
}
}

//#region Editor Core
private _updateForNotebookConfiguration() {
if (!this._overlayContainer) {
Expand Down

0 comments on commit 7ad85a6

Please sign in to comment.