2019-03-31 07:51:17 -05:00
|
|
|
import * as vscode from 'vscode';
|
|
|
|
|
2020-02-02 15:23:01 -06:00
|
|
|
import { WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressReport, WorkDoneProgressEnd, Disposable } from 'vscode-languageclient';
|
2020-01-15 04:47:56 -06:00
|
|
|
|
2019-12-31 10:22:43 -06:00
|
|
|
import { Ctx } from './ctx';
|
|
|
|
|
2019-03-31 07:51:17 -05:00
|
|
|
const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
|
|
|
2019-12-31 10:22:43 -06:00
|
|
|
export function activateStatusDisplay(ctx: Ctx) {
|
2020-04-02 05:47:58 -05:00
|
|
|
const statusDisplay = new StatusDisplay(ctx.config.checkOnSave.command);
|
2019-12-31 10:22:43 -06:00
|
|
|
ctx.pushCleanup(statusDisplay);
|
2020-02-17 06:40:20 -06:00
|
|
|
const client = ctx.client;
|
|
|
|
if (client != null) {
|
|
|
|
ctx.pushCleanup(client.onProgress(
|
|
|
|
WorkDoneProgress.type,
|
|
|
|
'rustAnalyzer/cargoWatcher',
|
|
|
|
params => statusDisplay.handleProgressNotification(params)
|
2020-02-17 14:09:44 -06:00
|
|
|
));
|
2020-02-17 06:40:20 -06:00
|
|
|
}
|
2019-12-31 10:22:43 -06:00
|
|
|
}
|
|
|
|
|
2020-02-05 14:39:47 -06:00
|
|
|
class StatusDisplay implements Disposable {
|
2019-12-30 13:16:07 -06:00
|
|
|
packageName?: string;
|
2019-04-02 12:46:47 -05:00
|
|
|
|
2020-01-31 12:55:10 -06:00
|
|
|
private i: number = 0;
|
2019-03-31 07:51:17 -05:00
|
|
|
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(() => {
|
2020-01-31 12:55:10 -06:00
|
|
|
this.tick();
|
|
|
|
this.refreshLabel();
|
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
|
|
|
}
|
|
|
|
|
2020-01-31 12:55:10 -06:00
|
|
|
refreshLabel() {
|
|
|
|
if (this.packageName) {
|
2020-02-13 14:48:20 -06:00
|
|
|
this.statusBarItem.text = `${spinnerFrames[this.i]} cargo ${this.command} [${this.packageName}]`;
|
2020-01-31 12:55:10 -06:00
|
|
|
} else {
|
2020-02-13 14:48:20 -06:00
|
|
|
this.statusBarItem.text = `${spinnerFrames[this.i]} cargo ${this.command}`;
|
2020-01-31 12:55:10 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-15 04:47:56 -06:00
|
|
|
handleProgressNotification(params: WorkDoneProgressBegin | WorkDoneProgressReport | WorkDoneProgressEnd) {
|
|
|
|
switch (params.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':
|
2020-01-15 04:47:56 -06:00
|
|
|
if (params.message) {
|
|
|
|
this.packageName = params.message;
|
2020-01-31 12:55:10 -06:00
|
|
|
this.refreshLabel();
|
2019-12-25 12:08:44 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-12-25 12:10:30 -06:00
|
|
|
case 'end':
|
2019-12-25 12:08:44 -06:00
|
|
|
this.hide();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-31 12:55:10 -06:00
|
|
|
private tick() {
|
|
|
|
this.i = (this.i + 1) % spinnerFrames.length;
|
2019-03-31 07:51:17 -05:00
|
|
|
}
|
2019-03-31 08:21:14 -05:00
|
|
|
}
|