2019-03-31 07:51:17 -05:00
|
|
|
import * as vscode from 'vscode';
|
|
|
|
|
|
|
|
const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
|
|
|
2019-04-13 15:13:21 -05:00
|
|
|
export class StatusDisplay implements vscode.Disposable {
|
2019-12-30 13:16:07 -06:00
|
|
|
packageName?: string;
|
2019-04-02 12:46:47 -05:00
|
|
|
|
2019-03-31 07:51:17 -05:00
|
|
|
private i = 0;
|
|
|
|
private statusBarItem: vscode.StatusBarItem;
|
2019-06-24 05:02:20 -05:00
|
|
|
private command: string;
|
2019-03-31 07:51:17 -05:00
|
|
|
private timer?: NodeJS.Timeout;
|
|
|
|
|
2019-06-24 05:02:20 -05:00
|
|
|
constructor(command: string) {
|
2019-03-31 08:21:14 -05:00
|
|
|
this.statusBarItem = vscode.window.createStatusBarItem(
|
|
|
|
vscode.StatusBarAlignment.Left,
|
2019-12-09 12:57:55 -06:00
|
|
|
10,
|
2019-03-31 08:21:14 -05:00
|
|
|
);
|
2019-06-24 05:02:20 -05:00
|
|
|
this.command = command;
|
2019-03-31 07:51:17 -05:00
|
|
|
this.statusBarItem.hide();
|
|
|
|
}
|
|
|
|
|
2019-12-30 13:16:07 -06:00
|
|
|
show() {
|
2019-04-02 12:46:47 -05:00
|
|
|
this.packageName = undefined;
|
|
|
|
|
2019-03-31 08:21:14 -05:00
|
|
|
this.timer =
|
|
|
|
this.timer ||
|
|
|
|
setInterval(() => {
|
2019-04-02 12:46:47 -05:00
|
|
|
if (this.packageName) {
|
2019-06-24 05:02:20 -05:00
|
|
|
this.statusBarItem!.text = `cargo ${this.command} [${
|
2019-04-02 12:46:47 -05:00
|
|
|
this.packageName
|
2019-12-30 16:30:35 -06:00
|
|
|
}] ${this.frame()}`;
|
2019-04-02 12:46:47 -05:00
|
|
|
} else {
|
2019-06-24 05:50:34 -05:00
|
|
|
this.statusBarItem!.text = `cargo ${
|
|
|
|
this.command
|
2019-12-30 16:30:35 -06:00
|
|
|
} ${this.frame()}`;
|
2019-04-02 12:46:47 -05:00
|
|
|
}
|
2019-03-31 08:21:14 -05:00
|
|
|
}, 300);
|
2019-03-31 07:51:17 -05:00
|
|
|
|
2019-04-13 15:13:21 -05:00
|
|
|
this.statusBarItem.show();
|
2019-03-31 07:51:17 -05:00
|
|
|
}
|
|
|
|
|
2019-12-30 13:16:07 -06:00
|
|
|
hide() {
|
2019-03-31 07:51:17 -05:00
|
|
|
if (this.timer) {
|
|
|
|
clearInterval(this.timer);
|
|
|
|
this.timer = undefined;
|
|
|
|
}
|
|
|
|
|
2019-04-13 15:13:21 -05:00
|
|
|
this.statusBarItem.hide();
|
|
|
|
}
|
|
|
|
|
2019-12-30 13:16:07 -06:00
|
|
|
dispose() {
|
2019-04-13 15:13:21 -05:00
|
|
|
if (this.timer) {
|
|
|
|
clearInterval(this.timer);
|
|
|
|
this.timer = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.statusBarItem.dispose();
|
2019-03-31 07:51:17 -05:00
|
|
|
}
|
|
|
|
|
2019-12-30 13:16:07 -06:00
|
|
|
handleProgressNotification(params: ProgressParams) {
|
2019-12-25 12:08:44 -06:00
|
|
|
const { token, value } = params;
|
2019-12-25 12:10:30 -06:00
|
|
|
if (token !== 'rustAnalyzer/cargoWatcher') {
|
2019-12-25 12:08:44 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (value.kind) {
|
2019-12-25 12:10:30 -06:00
|
|
|
case 'begin':
|
2019-12-25 12:08:44 -06:00
|
|
|
this.show();
|
|
|
|
break;
|
|
|
|
|
2019-12-25 12:10:30 -06:00
|
|
|
case 'report':
|
2019-12-25 12:08:44 -06:00
|
|
|
if (value.message) {
|
|
|
|
this.packageName = value.message;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-12-25 12:10:30 -06:00
|
|
|
case 'end':
|
2019-12-25 12:08:44 -06:00
|
|
|
this.hide();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-31 07:51:17 -05:00
|
|
|
private frame() {
|
2019-03-31 08:21:14 -05:00
|
|
|
return spinnerFrames[(this.i = ++this.i % spinnerFrames.length)];
|
2019-03-31 07:51:17 -05:00
|
|
|
}
|
2019-03-31 08:21:14 -05:00
|
|
|
}
|
2019-12-25 12:08:44 -06:00
|
|
|
|
|
|
|
// FIXME: Replace this once vscode-languageclient is updated to LSP 3.15
|
|
|
|
interface ProgressParams {
|
2019-12-25 12:10:30 -06:00
|
|
|
token: string;
|
|
|
|
value: WorkDoneProgress;
|
2019-12-25 12:08:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
enum WorkDoneProgressKind {
|
2019-12-25 12:10:30 -06:00
|
|
|
Begin = 'begin',
|
|
|
|
Report = 'report',
|
|
|
|
End = 'end',
|
2019-12-25 12:08:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
interface WorkDoneProgress {
|
2019-12-25 12:10:30 -06:00
|
|
|
kind: WorkDoneProgressKind;
|
|
|
|
message?: string;
|
|
|
|
cancelable?: boolean;
|
|
|
|
percentage?: string;
|
|
|
|
}
|