Show editor progress bar when executing cell is scrolled out of view

#130611
This commit is contained in:
Rob Lourens 2021-12-30 10:37:32 -08:00
parent 973684056e
commit 7ad85a67e9
4 changed files with 82 additions and 0 deletions

View file

@ -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);

View file

@ -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';

View file

@ -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 {

View file

@ -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.$;
@ -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;
}
@ -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;
@ -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) {