Skip to content

Commit

Permalink
Use status progress for 'Building... tasks
Browse files Browse the repository at this point in the history
Fixes #74602
  • Loading branch information
alexr00 committed Jun 4, 2019
1 parent 27c636a commit 7d698b4
Showing 1 changed file with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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(' ');
}

Expand All @@ -190,19 +186,24 @@ export class TaskStatusBarContributions extends Disposable implements IWorkbench

private registerListeners(): void {
this.markerService.onMarkerChanged(() => this.updateProblemsStatus());

let promise: Promise<void> | undefined = undefined;
let resolver: (value?: void | Thenable<void>) => void;
this.taskService.onDidStateChange(event => {
if (event.kind === TaskEventKind.Changed) {
this.updateRunningTasksStatus();
}

if (!this.ignoreEventForUpdateRunningTasksCount(event)) {
let needsUpdate = false;

switch (event.kind) {
case TaskEventKind.Active:
this.activeTasksCount++;
if (this.activeTasksCount === 1) {
if (!promise) {
promise = new Promise<void>((resolve) => {
resolver = resolve;
});
}
needsUpdate = true;
}
break;
Expand All @@ -212,13 +213,19 @@ export class TaskStatusBarContributions extends Disposable implements IWorkbench
if (this.activeTasksCount > 0) {
this.activeTasksCount--;
if (this.activeTasksCount === 0) {
if (promise && resolver!) {
resolver!();
}
needsUpdate = true;
}
}
break;
case TaskEventKind.Terminated:
if (this.activeTasksCount !== 0) {
this.activeTasksCount = 0;
if (promise && resolver!) {
resolver!();
}
needsUpdate = true;
}
break;
Expand All @@ -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;
});
}
});
}

Expand Down

0 comments on commit 7d698b4

Please sign in to comment.