Skip to content

Commit

Permalink
Improve responsiveness of the cargo check status label
Browse files Browse the repository at this point in the history
  • Loading branch information
lnicola committed Jan 31, 2020
1 parent dc713ea commit d4d72e8
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions editors/code/src/status_display.ts
Expand Up @@ -17,7 +17,7 @@ export function activateStatusDisplay(ctx: Ctx) {
class StatusDisplay implements vscode.Disposable {
packageName?: string;

private i = 0;
private i: number = 0;
private statusBarItem: vscode.StatusBarItem;
private command: string;
private timer?: NodeJS.Timeout;
Expand All @@ -37,11 +37,8 @@ class StatusDisplay implements vscode.Disposable {
this.timer =
this.timer ||
setInterval(() => {
if (this.packageName) {
this.statusBarItem!.text = `${this.frame()} cargo ${this.command} [${this.packageName}]`;
} else {
this.statusBarItem!.text = `${this.frame()} cargo ${this.command}`;
}
this.tick();
this.refreshLabel();
}, 300);

this.statusBarItem.show();
Expand All @@ -65,6 +62,14 @@ class StatusDisplay implements vscode.Disposable {
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) {
switch (params.kind) {
case 'begin':
Expand All @@ -74,6 +79,7 @@ class StatusDisplay implements vscode.Disposable {
case 'report':
if (params.message) {
this.packageName = params.message;
this.refreshLabel();
}
break;

Expand All @@ -83,7 +89,7 @@ class StatusDisplay implements vscode.Disposable {
}
}

private frame() {
return spinnerFrames[(this.i = ++this.i % spinnerFrames.length)];
private tick() {
this.i = (this.i + 1) % spinnerFrames.length;
}
}

0 comments on commit d4d72e8

Please sign in to comment.