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.ts105
1 files changed, 105 insertions, 0 deletions
diff --git a/editors/code/src/status_display.ts b/editors/code/src/status_display.ts
new file mode 100644
index 000000000..48cf0655b
--- /dev/null
+++ b/editors/code/src/status_display.ts
@@ -0,0 +1,105 @@
1import * as vscode from 'vscode';
2
3const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
4
5export class StatusDisplay implements vscode.Disposable {
6 packageName?: string;
7
8 private i = 0;
9 private statusBarItem: vscode.StatusBarItem;
10 private command: string;
11 private timer?: NodeJS.Timeout;
12
13 constructor(command: string) {
14 this.statusBarItem = vscode.window.createStatusBarItem(
15 vscode.StatusBarAlignment.Left,
16 10,
17 );
18 this.command = command;
19 this.statusBarItem.hide();
20 }
21
22 show() {
23 this.packageName = undefined;
24
25 this.timer =
26 this.timer ||
27 setInterval(() => {
28 if (this.packageName) {
29 this.statusBarItem!.text = `cargo ${this.command} [${
30 this.packageName
31 }] ${this.frame()}`;
32 } else {
33 this.statusBarItem!.text = `cargo ${
34 this.command
35 } ${this.frame()}`;
36 }
37 }, 300);
38
39 this.statusBarItem.show();
40 }
41
42 hide() {
43 if (this.timer) {
44 clearInterval(this.timer);
45 this.timer = undefined;
46 }
47
48 this.statusBarItem.hide();
49 }
50
51 dispose() {
52 if (this.timer) {
53 clearInterval(this.timer);
54 this.timer = undefined;
55 }
56
57 this.statusBarItem.dispose();
58 }
59
60 handleProgressNotification(params: ProgressParams) {
61 const { token, value } = params;
62 if (token !== 'rustAnalyzer/cargoWatcher') {
63 return;
64 }
65
66 switch (value.kind) {
67 case 'begin':
68 this.show();
69 break;
70
71 case 'report':
72 if (value.message) {
73 this.packageName = value.message;
74 }
75 break;
76
77 case 'end':
78 this.hide();
79 break;
80 }
81 }
82
83 private frame() {
84 return spinnerFrames[(this.i = ++this.i % spinnerFrames.length)];
85 }
86}
87
88// FIXME: Replace this once vscode-languageclient is updated to LSP 3.15
89interface ProgressParams {
90 token: string;
91 value: WorkDoneProgress;
92}
93
94enum WorkDoneProgressKind {
95 Begin = 'begin',
96 Report = 'report',
97 End = 'end',
98}
99
100interface WorkDoneProgress {
101 kind: WorkDoneProgressKind;
102 message?: string;
103 cancelable?: boolean;
104 percentage?: string;
105}