]> git.lizzy.rs Git - rust.git/commitdiff
status is not a command
authorAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 30 Dec 2019 19:16:07 +0000 (20:16 +0100)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 30 Dec 2019 19:16:07 +0000 (20:16 +0100)
editors/code/src/commands/watch_status.ts [deleted file]
editors/code/src/main.ts
editors/code/src/status_display.ts [new file with mode: 0644]

diff --git a/editors/code/src/commands/watch_status.ts b/editors/code/src/commands/watch_status.ts
deleted file mode 100644 (file)
index 10787b5..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-import * as vscode from 'vscode';
-
-const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
-
-export class StatusDisplay implements vscode.Disposable {
-    public 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();
-    }
-
-    public 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();
-    }
-
-    public hide() {
-        if (this.timer) {
-            clearInterval(this.timer);
-            this.timer = undefined;
-        }
-
-        this.statusBarItem.hide();
-    }
-
-    public dispose() {
-        if (this.timer) {
-            clearInterval(this.timer);
-            this.timer = undefined;
-        }
-
-        this.statusBarItem.dispose();
-    }
-
-    public 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;
-}
index cf0ddfa16198c81412947db84b84879d361d81f8..d6c210579a2cca7d666716243bf5a8ec65c60acf 100644 (file)
@@ -3,7 +3,7 @@ import * as lc from 'vscode-languageclient';
 
 import * as commands from './commands';
 import { HintsUpdater } from './inlay_hints';
-import { StatusDisplay } from './commands/watch_status';
+import { StatusDisplay } from './status_display';
 import * as events from './events';
 import * as notifications from './notifications';
 import { Server } from './server';
@@ -28,10 +28,6 @@ export async function activate(context: vscode.ExtensionContext) {
     ctx.registerCommand('runSingle', commands.runSingle);
     ctx.registerCommand('showReferences', commands.showReferences);
 
-    function disposeOnDeactivation(disposable: vscode.Disposable) {
-        context.subscriptions.push(disposable);
-    }
-
     if (Server.config.enableEnhancedTyping) {
         ctx.overrideCommand('type', commands.onEnter);
     }
@@ -39,7 +35,11 @@ export async function activate(context: vscode.ExtensionContext) {
     const watchStatus = new StatusDisplay(
         Server.config.cargoWatchOptions.command,
     );
-    disposeOnDeactivation(watchStatus);
+    ctx.pushCleanup(watchStatus);
+
+    function disposeOnDeactivation(disposable: vscode.Disposable) {
+        context.subscriptions.push(disposable);
+    }
 
     // Notifications are events triggered by the language server
     const allNotifications: [string, lc.GenericNotificationHandler][] = [
diff --git a/editors/code/src/status_display.ts b/editors/code/src/status_display.ts
new file mode 100644 (file)
index 0000000..48cf065
--- /dev/null
@@ -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;
+}