diff options
author | Kevin DeLorey <[email protected]> | 2020-02-09 16:25:47 +0000 |
---|---|---|
committer | Kevin DeLorey <[email protected]> | 2020-02-09 16:37:43 +0000 |
commit | a957c473fdb79880c39b73dc9e0c923093cf16ac (patch) | |
tree | f998b548f530ce604651e0e6af314ed2ec74b3b5 /editors/code/src/status_display.ts | |
parent | 22caf982b99c54058e2e9200aeea0e61cada284a (diff) | |
parent | 1b9b13b4b4a75b5531c3f046ce6bf72d681f2732 (diff) |
Merge branch 'master' into kdelorey/complete-trait-impl
Diffstat (limited to 'editors/code/src/status_display.ts')
-rw-r--r-- | editors/code/src/status_display.ts | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/editors/code/src/status_display.ts b/editors/code/src/status_display.ts index c75fddf9d..51dbf388b 100644 --- a/editors/code/src/status_display.ts +++ b/editors/code/src/status_display.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | 2 | ||
3 | import { WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressReport, WorkDoneProgressEnd } from 'vscode-languageclient'; | 3 | import { WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressReport, WorkDoneProgressEnd, Disposable } from 'vscode-languageclient'; |
4 | 4 | ||
5 | import { Ctx } from './ctx'; | 5 | import { Ctx } from './ctx'; |
6 | 6 | ||
@@ -9,15 +9,17 @@ const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', ' | |||
9 | export function activateStatusDisplay(ctx: Ctx) { | 9 | export function activateStatusDisplay(ctx: Ctx) { |
10 | const statusDisplay = new StatusDisplay(ctx.config.cargoWatchOptions.command); | 10 | const statusDisplay = new StatusDisplay(ctx.config.cargoWatchOptions.command); |
11 | ctx.pushCleanup(statusDisplay); | 11 | ctx.pushCleanup(statusDisplay); |
12 | ctx.onDidRestart(client => { | 12 | ctx.onDidRestart(client => ctx.pushCleanup(client.onProgress( |
13 | client.onProgress(WorkDoneProgress.type, 'rustAnalyzer/cargoWatcher', params => statusDisplay.handleProgressNotification(params)); | 13 | WorkDoneProgress.type, |
14 | }); | 14 | 'rustAnalyzer/cargoWatcher', |
15 | params => statusDisplay.handleProgressNotification(params) | ||
16 | ))); | ||
15 | } | 17 | } |
16 | 18 | ||
17 | class StatusDisplay implements vscode.Disposable { | 19 | class StatusDisplay implements Disposable { |
18 | packageName?: string; | 20 | packageName?: string; |
19 | 21 | ||
20 | private i = 0; | 22 | private i: number = 0; |
21 | private statusBarItem: vscode.StatusBarItem; | 23 | private statusBarItem: vscode.StatusBarItem; |
22 | private command: string; | 24 | private command: string; |
23 | private timer?: NodeJS.Timeout; | 25 | private timer?: NodeJS.Timeout; |
@@ -37,11 +39,8 @@ class StatusDisplay implements vscode.Disposable { | |||
37 | this.timer = | 39 | this.timer = |
38 | this.timer || | 40 | this.timer || |
39 | setInterval(() => { | 41 | setInterval(() => { |
40 | if (this.packageName) { | 42 | this.tick(); |
41 | this.statusBarItem!.text = `${this.frame()} cargo ${this.command} [${this.packageName}]`; | 43 | this.refreshLabel(); |
42 | } else { | ||
43 | this.statusBarItem!.text = `${this.frame()} cargo ${this.command}`; | ||
44 | } | ||
45 | }, 300); | 44 | }, 300); |
46 | 45 | ||
47 | this.statusBarItem.show(); | 46 | this.statusBarItem.show(); |
@@ -65,6 +64,14 @@ class StatusDisplay implements vscode.Disposable { | |||
65 | this.statusBarItem.dispose(); | 64 | this.statusBarItem.dispose(); |
66 | } | 65 | } |
67 | 66 | ||
67 | refreshLabel() { | ||
68 | if (this.packageName) { | ||
69 | this.statusBarItem!.text = `${spinnerFrames[this.i]} cargo ${this.command} [${this.packageName}]`; | ||
70 | } else { | ||
71 | this.statusBarItem!.text = `${spinnerFrames[this.i]} cargo ${this.command}`; | ||
72 | } | ||
73 | } | ||
74 | |||
68 | handleProgressNotification(params: WorkDoneProgressBegin | WorkDoneProgressReport | WorkDoneProgressEnd) { | 75 | handleProgressNotification(params: WorkDoneProgressBegin | WorkDoneProgressReport | WorkDoneProgressEnd) { |
69 | switch (params.kind) { | 76 | switch (params.kind) { |
70 | case 'begin': | 77 | case 'begin': |
@@ -74,6 +81,7 @@ class StatusDisplay implements vscode.Disposable { | |||
74 | case 'report': | 81 | case 'report': |
75 | if (params.message) { | 82 | if (params.message) { |
76 | this.packageName = params.message; | 83 | this.packageName = params.message; |
84 | this.refreshLabel(); | ||
77 | } | 85 | } |
78 | break; | 86 | break; |
79 | 87 | ||
@@ -83,7 +91,7 @@ class StatusDisplay implements vscode.Disposable { | |||
83 | } | 91 | } |
84 | } | 92 | } |
85 | 93 | ||
86 | private frame() { | 94 | private tick() { |
87 | return spinnerFrames[(this.i = ++this.i % spinnerFrames.length)]; | 95 | this.i = (this.i + 1) % spinnerFrames.length; |
88 | } | 96 | } |
89 | } | 97 | } |