From 6cc55e4c5ce994be284fc4337eed21844c0eef24 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 30 Dec 2019 20:16:07 +0100 Subject: status is not a command --- editors/code/src/status_display.ts | 105 +++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 editors/code/src/status_display.ts (limited to 'editors/code/src/status_display.ts') 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 @@ +import * as vscode from 'vscode'; + +const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']; + +export class StatusDisplay implements vscode.Disposable { + packageName?: string; + + private i = 0; + private statusBarItem: vscode.StatusBarItem; + private command: string; + private timer?: NodeJS.Timeout; + + constructor(command: string) { + this.statusBarItem = vscode.window.createStatusBarItem( + vscode.StatusBarAlignment.Left, + 10, + ); + this.command = command; + this.statusBarItem.hide(); + } + + show() { + this.packageName = undefined; + + this.timer = + this.timer || + setInterval(() => { + if (this.packageName) { + this.statusBarItem!.text = `cargo ${this.command} [${ + this.packageName + }] ${this.frame()}`; + } else { + this.statusBarItem!.text = `cargo ${ + this.command + } ${this.frame()}`; + } + }, 300); + + this.statusBarItem.show(); + } + + hide() { + if (this.timer) { + clearInterval(this.timer); + this.timer = undefined; + } + + this.statusBarItem.hide(); + } + + dispose() { + if (this.timer) { + clearInterval(this.timer); + this.timer = undefined; + } + + this.statusBarItem.dispose(); + } + + handleProgressNotification(params: ProgressParams) { + const { token, value } = params; + if (token !== 'rustAnalyzer/cargoWatcher') { + return; + } + + switch (value.kind) { + case 'begin': + this.show(); + break; + + case 'report': + if (value.message) { + this.packageName = value.message; + } + break; + + case 'end': + this.hide(); + break; + } + } + + private frame() { + return spinnerFrames[(this.i = ++this.i % spinnerFrames.length)]; + } +} + +// FIXME: Replace this once vscode-languageclient is updated to LSP 3.15 +interface ProgressParams { + token: string; + value: WorkDoneProgress; +} + +enum WorkDoneProgressKind { + Begin = 'begin', + Report = 'report', + End = 'end', +} + +interface WorkDoneProgress { + kind: WorkDoneProgressKind; + message?: string; + cancelable?: boolean; + percentage?: string; +} -- cgit v1.2.3