diff options
Diffstat (limited to 'editors/code/src/ctx.ts')
-rw-r--r-- | editors/code/src/ctx.ts | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index 41df11991..6e767babf 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts | |||
@@ -1,9 +1,11 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | import * as lc from 'vscode-languageclient'; | 2 | import * as lc from 'vscode-languageclient'; |
3 | import * as ra from './lsp_ext'; | ||
3 | 4 | ||
4 | import { Config } from './config'; | 5 | import { Config } from './config'; |
5 | import { createClient } from './client'; | 6 | import { createClient } from './client'; |
6 | import { isRustEditor, RustEditor } from './util'; | 7 | import { isRustEditor, RustEditor } from './util'; |
8 | import { Status } from './lsp_ext'; | ||
7 | 9 | ||
8 | export class Ctx { | 10 | export class Ctx { |
9 | private constructor( | 11 | private constructor( |
@@ -11,6 +13,7 @@ export class Ctx { | |||
11 | private readonly extCtx: vscode.ExtensionContext, | 13 | private readonly extCtx: vscode.ExtensionContext, |
12 | readonly client: lc.LanguageClient, | 14 | readonly client: lc.LanguageClient, |
13 | readonly serverPath: string, | 15 | readonly serverPath: string, |
16 | readonly statusBar: vscode.StatusBarItem, | ||
14 | ) { | 17 | ) { |
15 | 18 | ||
16 | } | 19 | } |
@@ -22,9 +25,18 @@ export class Ctx { | |||
22 | cwd: string, | 25 | cwd: string, |
23 | ): Promise<Ctx> { | 26 | ): Promise<Ctx> { |
24 | const client = createClient(serverPath, cwd); | 27 | const client = createClient(serverPath, cwd); |
25 | const res = new Ctx(config, extCtx, client, serverPath); | 28 | |
29 | const statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left); | ||
30 | extCtx.subscriptions.push(statusBar); | ||
31 | statusBar.text = "rust-analyzer"; | ||
32 | statusBar.tooltip = "ready"; | ||
33 | statusBar.show(); | ||
34 | |||
35 | const res = new Ctx(config, extCtx, client, serverPath, statusBar); | ||
36 | |||
26 | res.pushCleanup(client.start()); | 37 | res.pushCleanup(client.start()); |
27 | await client.onReady(); | 38 | await client.onReady(); |
39 | client.onNotification(ra.status, (status) => res.setStatus(status)); | ||
28 | return res; | 40 | return res; |
29 | } | 41 | } |
30 | 42 | ||
@@ -54,6 +66,35 @@ export class Ctx { | |||
54 | return this.extCtx.subscriptions; | 66 | return this.extCtx.subscriptions; |
55 | } | 67 | } |
56 | 68 | ||
69 | setStatus(status: Status) { | ||
70 | switch (status) { | ||
71 | case "loading": | ||
72 | this.statusBar.text = "$(sync~spin) rust-analyzer"; | ||
73 | this.statusBar.tooltip = "Loading the project"; | ||
74 | this.statusBar.command = undefined; | ||
75 | this.statusBar.color = undefined; | ||
76 | break; | ||
77 | case "ready": | ||
78 | this.statusBar.text = "rust-analyzer"; | ||
79 | this.statusBar.tooltip = "Ready"; | ||
80 | this.statusBar.command = undefined; | ||
81 | this.statusBar.color = undefined; | ||
82 | break; | ||
83 | case "invalid": | ||
84 | this.statusBar.text = "$(error) rust-analyzer"; | ||
85 | this.statusBar.tooltip = "Failed to load the project"; | ||
86 | this.statusBar.command = undefined; | ||
87 | this.statusBar.color = new vscode.ThemeColor("notificationsErrorIcon.foreground"); | ||
88 | break; | ||
89 | case "needsReload": | ||
90 | this.statusBar.text = "$(warning) rust-analyzer"; | ||
91 | this.statusBar.tooltip = "Click to reload"; | ||
92 | this.statusBar.command = "rust-analyzer.reloadWorkspace"; | ||
93 | this.statusBar.color = new vscode.ThemeColor("notificationsWarningIcon.foreground"); | ||
94 | break; | ||
95 | } | ||
96 | } | ||
97 | |||
57 | pushCleanup(d: Disposable) { | 98 | pushCleanup(d: Disposable) { |
58 | this.extCtx.subscriptions.push(d); | 99 | this.extCtx.subscriptions.push(d); |
59 | } | 100 | } |