From 780ca84f9a5104591fbae4231c9323f14f6aab28 Mon Sep 17 00:00:00 2001 From: Lucy Zhang Date: Mon, 22 Mar 2021 14:54:13 -0700 Subject: [PATCH] Enable status bar for notebooks (#14817) * enable status bar for notebooks * add onCellExecutionStart event to notebook service * fix test, change var name --- src/sql/workbench/contrib/notebook/test/stubs.ts | 6 ++++++ .../workbench/contrib/query/browser/statusBarItems.ts | 9 ++++++--- .../workbench/services/notebook/browser/models/cell.ts | 2 ++ .../services/notebook/browser/notebookService.ts | 10 ++++++++++ .../services/notebook/browser/notebookServiceImpl.ts | 9 +++++++++ 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/sql/workbench/contrib/notebook/test/stubs.ts b/src/sql/workbench/contrib/notebook/test/stubs.ts index 49ca1bf014..f13dedcd83 100644 --- a/src/sql/workbench/contrib/notebook/test/stubs.ts +++ b/src/sql/workbench/contrib/notebook/test/stubs.ts @@ -289,6 +289,12 @@ export class NotebookServiceStub implements INotebookService { navigateTo(notebookUri: URI, sectionId: string): void { throw new Error('Method not implemented.'); } + get onCodeCellExecutionStart(): vsEvent.Event { + throw new Error('Method not implemented.'); + } + notifyCellExecutionStarted(): void { + throw new Error('Method not implemented.'); + } } export class ClientSessionStub implements IClientSession { diff --git a/src/sql/workbench/contrib/query/browser/statusBarItems.ts b/src/sql/workbench/contrib/query/browser/statusBarItems.ts index a0e43e001d..18e5944a09 100644 --- a/src/sql/workbench/contrib/query/browser/statusBarItems.ts +++ b/src/sql/workbench/contrib/query/browser/statusBarItems.ts @@ -5,6 +5,7 @@ import { parseNumAsTimeString } from 'sql/platform/connection/common/utils'; import { QueryEditorInput } from 'sql/workbench/common/editor/query/queryEditorInput'; +import { INotebookService } from 'sql/workbench/services/notebook/browser/notebookService'; import { IQueryModelService } from 'sql/workbench/services/query/common/queryModel'; import QueryRunner from 'sql/workbench/services/query/common/queryRunner'; import { IntervalTimer } from 'vs/base/common/async'; @@ -259,8 +260,9 @@ export class QueryResultSelectionSummaryStatusBarContribution extends Disposable constructor( @IStatusbarService private readonly statusbarService: IStatusbarService, - @IEditorService private editorService: IEditorService, - @IQueryModelService queryModelService: IQueryModelService + @IEditorService editorService: IEditorService, + @IQueryModelService queryModelService: IQueryModelService, + @INotebookService notebookService: INotebookService ) { super(); this.statusItem = this._register( @@ -274,6 +276,7 @@ export class QueryResultSelectionSummaryStatusBarContribution extends Disposable ); this._register(editorService.onDidActiveEditorChange(() => { this.hide(); }, this)); this._register(queryModelService.onRunQueryStart(() => { this.hide(); })); + this._register(notebookService.onCodeCellExecutionStart(() => { this.hide(); })); this._register(queryModelService.onCellSelectionChanged((data: string[]) => { this.onCellSelectionChanged(data); })); @@ -289,7 +292,7 @@ export class QueryResultSelectionSummaryStatusBarContribution extends Disposable private onCellSelectionChanged(data: string[]): void { const numericValues = data?.filter(value => !Number.isNaN(Number(value))).map(value => Number(value)); - if (numericValues?.length < 2 || !(this.editorService.activeEditor instanceof QueryEditorInput)) { + if (numericValues?.length < 2) { this.hide(); return; } diff --git a/src/sql/workbench/services/notebook/browser/models/cell.ts b/src/sql/workbench/services/notebook/browser/models/cell.ts index 31a19971eb..9c74c30c18 100644 --- a/src/sql/workbench/services/notebook/browser/models/cell.ts +++ b/src/sql/workbench/services/notebook/browser/models/cell.ts @@ -531,6 +531,7 @@ export class CellModel extends Disposable implements ICellModel { }, false); this.setFuture(future as FutureInternal); this.fireExecutionStateChanged(); + this._notebookService?.notifyCellExecutionStarted(); // For now, await future completion. Later we should just track and handle cancellation based on model notifications let result: nb.IExecuteReplyMsg = await future.done; if (result && result.content) { @@ -551,6 +552,7 @@ export class CellModel extends Disposable implements ICellModel { let commandExecuted = this._commandService?.executeCommand(result.commandId, result.args); // This will ensure that the run button turns into a stop button this.fireExecutionStateChanged(); + this._notebookService?.notifyCellExecutionStarted(); await commandExecuted; // For save files, if we output a message after saving the file, the file becomes dirty again. // Special casing this to avoid this particular issue. diff --git a/src/sql/workbench/services/notebook/browser/notebookService.ts b/src/sql/workbench/services/notebook/browser/notebookService.ts index dc9d1f868d..b3d332fdb5 100644 --- a/src/sql/workbench/services/notebook/browser/notebookService.ts +++ b/src/sql/workbench/services/notebook/browser/notebookService.ts @@ -129,6 +129,16 @@ export interface INotebookService { * @param isTrusted True if notebook is to be set to trusted, false otherwise. */ setTrusted(notebookUri: URI, isTrusted: boolean): Promise; + + /** + * Event that gets fired when a cell is executed. + */ + onCodeCellExecutionStart: Event; + + /** + * Fires the onCodeCellExecutionStart event. + */ + notifyCellExecutionStarted(): void; } export interface INotebookProvider { diff --git a/src/sql/workbench/services/notebook/browser/notebookServiceImpl.ts b/src/sql/workbench/services/notebook/browser/notebookServiceImpl.ts index e8816adc37..121a14cd02 100644 --- a/src/sql/workbench/services/notebook/browser/notebookServiceImpl.ts +++ b/src/sql/workbench/services/notebook/browser/notebookServiceImpl.ts @@ -108,6 +108,7 @@ export class NotebookService extends Disposable implements INotebookService { private _isRegistrationComplete = false; private _trustedCacheQueue: URI[] = []; private _unTrustedCacheQueue: URI[] = []; + private _onCodeCellExecutionStart: Emitter = new Emitter(); constructor( @ILifecycleService lifecycleService: ILifecycleService, @@ -639,4 +640,12 @@ export class NotebookService extends Disposable implements INotebookService { return isTrusted; } + + get onCodeCellExecutionStart(): Event { + return this._onCodeCellExecutionStart.event; + } + + notifyCellExecutionStarted(): void { + this._onCodeCellExecutionStart.fire(); + } }