aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/status_display.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/status_display.ts')
-rw-r--r--editors/code/src/status_display.ts34
1 files changed, 21 insertions, 13 deletions
diff --git a/editors/code/src/status_display.ts b/editors/code/src/status_display.ts
index c75fddf9d..51dbf388b 100644
--- a/editors/code/src/status_display.ts
+++ b/editors/code/src/status_display.ts
@@ -1,6 +1,6 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2 2
3import { WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressReport, WorkDoneProgressEnd } from 'vscode-languageclient'; 3import { WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressReport, WorkDoneProgressEnd, Disposable } from 'vscode-languageclient';
4 4
5import { Ctx } from './ctx'; 5import { Ctx } from './ctx';
6 6
@@ -9,15 +9,17 @@ const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '
9export function activateStatusDisplay(ctx: Ctx) { 9export function activateStatusDisplay(ctx: Ctx) {
10 const statusDisplay = new StatusDisplay(ctx.config.cargoWatchOptions.command); 10 const statusDisplay = new StatusDisplay(ctx.config.cargoWatchOptions.command);
11 ctx.pushCleanup(statusDisplay); 11 ctx.pushCleanup(statusDisplay);
12 ctx.onDidRestart(client => { 12 ctx.onDidRestart(client => ctx.pushCleanup(client.onProgress(
13 client.onProgress(WorkDoneProgress.type, 'rustAnalyzer/cargoWatcher', params => statusDisplay.handleProgressNotification(params)); 13 WorkDoneProgress.type,
14 }); 14 'rustAnalyzer/cargoWatcher',
15 params => statusDisplay.handleProgressNotification(params)
16 )));
15} 17}
16 18
17class StatusDisplay implements vscode.Disposable { 19class StatusDisplay implements Disposable {
18 packageName?: string; 20 packageName?: string;
19 21
20 private i = 0; 22 private i: number = 0;
21 private statusBarItem: vscode.StatusBarItem; 23 private statusBarItem: vscode.StatusBarItem;
22 private command: string; 24 private command: string;
23 private timer?: NodeJS.Timeout; 25 private timer?: NodeJS.Timeout;
@@ -37,11 +39,8 @@ class StatusDisplay implements vscode.Disposable {
37 this.timer = 39 this.timer =
38 this.timer || 40 this.timer ||
39 setInterval(() => { 41 setInterval(() => {
40 if (this.packageName) { 42 this.tick();
41 this.statusBarItem!.text = `${this.frame()} cargo ${this.command} [${this.packageName}]`; 43 this.refreshLabel();
42 } else {
43 this.statusBarItem!.text = `${this.frame()} cargo ${this.command}`;
44 }
45 }, 300); 44 }, 300);
46 45
47 this.statusBarItem.show(); 46 this.statusBarItem.show();
@@ -65,6 +64,14 @@ class StatusDisplay implements vscode.Disposable {
65 this.statusBarItem.dispose(); 64 this.statusBarItem.dispose();
66 } 65 }
67 66
67 refreshLabel() {
68 if (this.packageName) {
69 this.statusBarItem!.text = `${spinnerFrames[this.i]} cargo ${this.command} [${this.packageName}]`;
70 } else {
71 this.statusBarItem!.text = `${spinnerFrames[this.i]} cargo ${this.command}`;
72 }
73 }
74
68 handleProgressNotification(params: WorkDoneProgressBegin | WorkDoneProgressReport | WorkDoneProgressEnd) { 75 handleProgressNotification(params: WorkDoneProgressBegin | WorkDoneProgressReport | WorkDoneProgressEnd) {
69 switch (params.kind) { 76 switch (params.kind) {
70 case 'begin': 77 case 'begin':
@@ -74,6 +81,7 @@ class StatusDisplay implements vscode.Disposable {
74 case 'report': 81 case 'report':
75 if (params.message) { 82 if (params.message) {
76 this.packageName = params.message; 83 this.packageName = params.message;
84 this.refreshLabel();
77 } 85 }
78 break; 86 break;
79 87
@@ -83,7 +91,7 @@ class StatusDisplay implements vscode.Disposable {
83 } 91 }
84 } 92 }
85 93
86 private frame() { 94 private tick() {
87 return spinnerFrames[(this.i = ++this.i % spinnerFrames.length)]; 95 this.i = (this.i + 1) % spinnerFrames.length;
88 } 96 }
89} 97}