-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstatusBar.ts
100 lines (91 loc) · 2.62 KB
/
statusBar.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { randomUUID } from "node:crypto";
import * as vscode from "vscode";
import { state } from "./utils/state";
import Logger from "./logger";
class StatusBar {
private activeTasks: Set<string> = new Set();
private error: string | null = null;
private statusBar: vscode.StatusBarItem | null = null;
public init(context: vscode.ExtensionContext) {
this.statusBar = vscode.window.createStatusBarItem(
vscode.StatusBarAlignment.Right,
100
);
this.statusBar.command = "firecoder.changeInlineSuggestMode";
context.subscriptions.push(this.statusBar);
this.setDefault();
setInterval(() => {
this.checkProgress();
}, 50);
Logger.info("Status Bar inited", {
component: "main",
sendTelemetry: true,
});
}
public startTask() {
const uuid = randomUUID();
this.activeTasks.add(uuid);
this.checkProgress();
return {
stopTask: () => {
this.activeTasks.delete(uuid);
this.checkProgress();
},
};
}
public checkProgress() {
if (this.error !== null) {
return;
}
if (this.activeTasks.size === 0) {
if (this.statusBar !== null) {
this.statusBar.text = `$(${this.getInlineSuggestModeIcon()}) FireCoder`;
this.statusBar.tooltip = `Change inline suggest mode. Currect: ${
this.getInlineSuggestMode() ? "Auto" : "Manually"
}`;
}
} else {
if (this.statusBar !== null) {
this.statusBar.text = `$(loading~spin) FireCoder`;
this.statusBar.tooltip = `Change inline suggest mode. Currect: ${
this.getInlineSuggestMode() ? "Auto" : "Manually"
}`;
}
}
}
public setError(tooltip: string) {
if (this.statusBar !== null) {
this.error = tooltip;
this.statusBar.text = `$(error) FireCoder`;
this.statusBar.tooltip = tooltip;
return () => {
this.error = null;
this.checkProgress();
};
}
}
private getInlineSuggestMode() {
const currentInlineSuggestModeAuto = state.workspace.get(
"inlineSuggestModeAuto"
);
return currentInlineSuggestModeAuto;
}
private getInlineSuggestModeIcon() {
if (this.getInlineSuggestMode()) {
return "check-all";
} else {
return "check";
}
}
private setDefault() {
if (this.statusBar !== null) {
this.statusBar.text = `$(${this.getInlineSuggestModeIcon()}) FireCoder`;
this.statusBar.tooltip = `Change inline suggest mode. Currect: ${
this.getInlineSuggestMode() ? "Auto" : "Manually"
}`;
this.statusBar.show();
}
}
}
const statusBar = new StatusBar();
export default statusBar;