Skip to content

Commit

Permalink
master: Progress Bar reporting for testing plus status bar info
Browse files Browse the repository at this point in the history
  • Loading branch information
Mate Pek committed May 22, 2022
1 parent 14d26c8 commit 73d33c5
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

## [4.2.2]

### Added

- improved progress bar and status bar message

## [4.2.1] - 2022-05-21

### Added
Expand Down
5 changes: 4 additions & 1 deletion src/ConfigOfExecGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { debugBreak } from './util/DevelopmentHelper';
import { FrameworkType } from './framework/Framework';
import { readFileSync } from 'fs';
import { getModiTime } from './Util';
import { SubProgressReporter } from './util/ProgressReporter';

///

Expand Down Expand Up @@ -57,7 +58,7 @@ export class ConfigOfExecGroup implements vscode.Disposable {

private readonly _executables: Map<string /*fsPath*/, AbstractExecutable> = new Map();

async load(): Promise<unknown[]> {
async load(progressReporter: SubProgressReporter): Promise<unknown[]> {
const pattern = await this._pathProcessor(this._pattern);

this._shared.log.info('pattern', this._pattern, this._shared.workspaceFolder.uri.fsPath, pattern);
Expand Down Expand Up @@ -99,6 +100,7 @@ export class ConfigOfExecGroup implements vscode.Disposable {
this._shared.log.exceptionS(e, "Couldn't watch pattern");
}

progressReporter.setMax(filePaths.length);
const suiteCreationAndLoadingTasks: Promise<void>[] = [];

for (let i = 0; i < filePaths.length; i++) {
Expand Down Expand Up @@ -145,6 +147,7 @@ export class ConfigOfExecGroup implements vscode.Disposable {
} catch (reason) {
this._shared.log.debug('Not an executable:', file, reason);
}
progressReporter.incrementBy1();
})(),
);
}
Expand Down
14 changes: 12 additions & 2 deletions src/WorkspaceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ConfigOfExecGroup } from './ConfigOfExecGroup';
import { generateId } from './Util';
import { AbstractTest } from './framework/AbstractTest';
import { TestItemManager } from './TestItemManager';
import { ProgressReporter } from './util/ProgressReporter';

//TODO:release if workspace contains ".vscode/testMate.cpp.json" we have to start loading the tests
export class WorkspaceManager implements vscode.Disposable {
Expand Down Expand Up @@ -209,19 +210,28 @@ export class WorkspaceManager implements vscode.Disposable {
async load(): Promise<void> {
this._executableConfig.forEach(c => c.dispose());

const sbm = vscode.window.setStatusBarMessage('TestMate C++: loading tests...');

return vscode.window.withProgress(
{ location: { viewId: 'workbench.view.extension.test' } },
async (
_progress: vscode.Progress<{ message?: string; increment?: number }>,
progress: vscode.Progress<{ message?: string; increment?: number }>,
_token: vscode.CancellationToken,
): Promise<void> => {
await new Promise<void>(r => setTimeout(r, 500)); // there are some race condition, this fixes it: maybe async dispose would fix it too?

const configuration = this._getConfiguration(this.log);
const executableConfig = configuration.getExecutableConfigs(this._shared);
this._executableConfig = executableConfig;
const progressReporter = new ProgressReporter(progress);

await Promise.allSettled(executableConfig.map(x => x.load().catch(e => this.log.errorS(e))));
await Promise.allSettled(
executableConfig.map(x => {
const subProgressReporter = progressReporter.createSubProgressReporter();
return x.load(subProgressReporter).catch(e => this.log.errorS(e));
}),
);
sbm.dispose();
},
);
}
Expand Down
46 changes: 46 additions & 0 deletions src/util/ProgressReporter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as vscode from 'vscode';

export class ProgressReporter {
constructor(private readonly progress: vscode.Progress<{ message?: string; increment?: number }>) {}

private readonly subs: SubProgressReporter[] = [];
private alreadySetCount = 0;
private maxValue = 0;
private currentValue = 0;
private reportedPercent = 0;

createSubProgressReporter(): SubProgressReporter {
const s = new SubProgressReporter(this);
this.subs.push(s);
return s;
}

_setMax(_sub: SubProgressReporter, max: number): void {
this.alreadySetCount++;
this.maxValue += max;
}

_incrementBy1(_sub: SubProgressReporter): void {
this.currentValue++;

if (this.alreadySetCount === this.subs.length) {
const currentPercent = Math.floor((100 * this.currentValue) / this.maxValue);
if (currentPercent > this.reportedPercent) {
this.progress.report({ increment: currentPercent - this.reportedPercent });
this.reportedPercent = currentPercent;
}
}
}
}

export class SubProgressReporter {
constructor(private readonly parent: ProgressReporter) {}

setMax(max: number): void {
this.parent._setMax(this, max);
}

incrementBy1(): void {
this.parent._incrementBy1(this);
}
}

0 comments on commit 73d33c5

Please sign in to comment.