Improve responsiveness of the cargo check status label

This commit is contained in:
Laurențiu Nicola 2020-01-31 20:55:10 +02:00
parent dc713ea21b
commit d4d72e8b9b

View file

@ -17,7 +17,7 @@ export function activateStatusDisplay(ctx: Ctx) {
class StatusDisplay implements vscode.Disposable { class StatusDisplay implements vscode.Disposable {
packageName?: string; packageName?: string;
private i = 0; private i: number = 0;
private statusBarItem: vscode.StatusBarItem; private statusBarItem: vscode.StatusBarItem;
private command: string; private command: string;
private timer?: NodeJS.Timeout; private timer?: NodeJS.Timeout;
@ -37,11 +37,8 @@ class StatusDisplay implements vscode.Disposable {
this.timer = this.timer =
this.timer || this.timer ||
setInterval(() => { setInterval(() => {
if (this.packageName) { this.tick();
this.statusBarItem!.text = `${this.frame()} cargo ${this.command} [${this.packageName}]`; this.refreshLabel();
} else {
this.statusBarItem!.text = `${this.frame()} cargo ${this.command}`;
}
}, 300); }, 300);
this.statusBarItem.show(); this.statusBarItem.show();
@ -65,6 +62,14 @@ class StatusDisplay implements vscode.Disposable {
this.statusBarItem.dispose(); this.statusBarItem.dispose();
} }
refreshLabel() {
if (this.packageName) {
this.statusBarItem!.text = `${spinnerFrames[this.i]} cargo ${this.command} [${this.packageName}]`;
} else {
this.statusBarItem!.text = `${spinnerFrames[this.i]} cargo ${this.command}`;
}
}
handleProgressNotification(params: WorkDoneProgressBegin | WorkDoneProgressReport | WorkDoneProgressEnd) { handleProgressNotification(params: WorkDoneProgressBegin | WorkDoneProgressReport | WorkDoneProgressEnd) {
switch (params.kind) { switch (params.kind) {
case 'begin': case 'begin':
@ -74,6 +79,7 @@ class StatusDisplay implements vscode.Disposable {
case 'report': case 'report':
if (params.message) { if (params.message) {
this.packageName = params.message; this.packageName = params.message;
this.refreshLabel();
} }
break; break;
@ -83,7 +89,7 @@ class StatusDisplay implements vscode.Disposable {
} }
} }
private frame() { private tick() {
return spinnerFrames[(this.i = ++this.i % spinnerFrames.length)]; this.i = (this.i + 1) % spinnerFrames.length;
} }
} }