-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
master: Progress Bar reporting for testing plus status bar info
- Loading branch information
Mate Pek
committed
May 22, 2022
1 parent
14d26c8
commit 73d33c5
Showing
4 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |