Skip to content
This repository was archived by the owner on Nov 18, 2022. It is now read-only.

Commit e0c90b0

Browse files
bors[bot]matklad
andauthored
Merge #5188
5188: Implement StatusBar r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 6e9ac77 + f0dc8ed commit e0c90b0

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

rust-analyzer/editors/code/src/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class ExperimentalFeatures implements lc.StaticFeature {
161161
caps.codeActionGroup = true;
162162
caps.resolveCodeAction = true;
163163
caps.hoverActions = true;
164+
caps.statusNotification = true;
164165
capabilities.experimental = caps;
165166
}
166167
initialize(_capabilities: lc.ServerCapabilities<any>, _documentSelector: lc.DocumentSelector | undefined): void {

rust-analyzer/editors/code/src/ctx.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import * as vscode from 'vscode';
22
import * as lc from 'vscode-languageclient';
3+
import * as ra from './lsp_ext';
34

45
import { Config } from './config';
56
import { createClient } from './client';
67
import { isRustEditor, RustEditor } from './util';
8+
import { Status } from './lsp_ext';
79

810
export class Ctx {
911
private constructor(
1012
readonly config: Config,
1113
private readonly extCtx: vscode.ExtensionContext,
1214
readonly client: lc.LanguageClient,
1315
readonly serverPath: string,
16+
readonly statusBar: vscode.StatusBarItem,
1417
) {
1518

1619
}
@@ -22,9 +25,18 @@ export class Ctx {
2225
cwd: string,
2326
): Promise<Ctx> {
2427
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+
2637
res.pushCleanup(client.start());
2738
await client.onReady();
39+
client.onNotification(ra.status, (status) => res.setStatus(status));
2840
return res;
2941
}
3042

@@ -54,6 +66,35 @@ export class Ctx {
5466
return this.extCtx.subscriptions;
5567
}
5668

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+
5798
pushCleanup(d: Disposable) {
5899
this.extCtx.subscriptions.push(d);
59100
}

rust-analyzer/editors/code/src/lsp_ext.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import * as lc from "vscode-languageclient";
66

77
export const analyzerStatus = new lc.RequestType<null, string, void>("rust-analyzer/analyzerStatus");
88

9+
export type Status = "loading" | "ready" | "invalid" | "needsReload";
10+
export const status = new lc.NotificationType<Status>("rust-analyzer/status");
11+
912
export const reloadWorkspace = new lc.RequestType<null, null, void>("rust-analyzer/reloadWorkspace");
1013

1114
export interface SyntaxTreeParams {

0 commit comments

Comments
 (0)