From 7d698b43eb1b3b94514c8aba19fcc54b0bd55db9 Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Tue, 4 Jun 2019 14:48:44 +0200 Subject: [PATCH] Use status progress for 'Building... tasks Fixes #74602 --- .../electron-browser/task.contribution.ts | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/vs/workbench/contrib/tasks/electron-browser/task.contribution.ts b/src/vs/workbench/contrib/tasks/electron-browser/task.contribution.ts index 9151937e337fa..5cff2c708c770 100644 --- a/src/vs/workbench/contrib/tasks/electron-browser/task.contribution.ts +++ b/src/vs/workbench/contrib/tasks/electron-browser/task.contribution.ts @@ -115,7 +115,8 @@ export class TaskStatusBarContributions extends Disposable implements IWorkbench constructor( @ITaskService private readonly taskService: ITaskService, @IMarkerService private readonly markerService: IMarkerService, - @IStatusbarService private readonly statusbarService: IStatusbarService + @IStatusbarService private readonly statusbarService: IStatusbarService, + @IProgressService private readonly progressService: IProgressService ) { super(); @@ -174,11 +175,6 @@ export class TaskStatusBarContributions extends Disposable implements IWorkbench problemsText.push('$(info) ' + this.packNumber(stats.infos)); } - // Building (only if any running tasks) - if (this.activeTasksCount > 0) { - problemsText.push(nls.localize('building', 'Building...')); - } - return problemsText.join(' '); } @@ -190,7 +186,8 @@ export class TaskStatusBarContributions extends Disposable implements IWorkbench private registerListeners(): void { this.markerService.onMarkerChanged(() => this.updateProblemsStatus()); - + let promise: Promise | undefined = undefined; + let resolver: (value?: void | Thenable) => void; this.taskService.onDidStateChange(event => { if (event.kind === TaskEventKind.Changed) { this.updateRunningTasksStatus(); @@ -198,11 +195,15 @@ export class TaskStatusBarContributions extends Disposable implements IWorkbench if (!this.ignoreEventForUpdateRunningTasksCount(event)) { let needsUpdate = false; - switch (event.kind) { case TaskEventKind.Active: this.activeTasksCount++; if (this.activeTasksCount === 1) { + if (!promise) { + promise = new Promise((resolve) => { + resolver = resolve; + }); + } needsUpdate = true; } break; @@ -212,6 +213,9 @@ export class TaskStatusBarContributions extends Disposable implements IWorkbench if (this.activeTasksCount > 0) { this.activeTasksCount--; if (this.activeTasksCount === 0) { + if (promise && resolver!) { + resolver!(); + } needsUpdate = true; } } @@ -219,6 +223,9 @@ export class TaskStatusBarContributions extends Disposable implements IWorkbench case TaskEventKind.Terminated: if (this.activeTasksCount !== 0) { this.activeTasksCount = 0; + if (promise && resolver!) { + resolver!(); + } needsUpdate = true; } break; @@ -228,6 +235,15 @@ export class TaskStatusBarContributions extends Disposable implements IWorkbench this.updateProblemsStatus(); } } + + if (promise && (event.kind === TaskEventKind.Active) && (this.activeTasksCount === 1)) { + this.progressService.withProgress({ location: ProgressLocation.Window }, progress => { + progress.report({ message: nls.localize('building', 'Building...') }); + return promise!; + }).then(() => { + promise = undefined; + }); + } }); }