From 3ef76760761d17cef4ea4e8462d9ee2ca8395467 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 2 Jul 2020 12:37:04 +0200 Subject: Implement StatusBar --- editors/code/src/client.ts | 1 + editors/code/src/ctx.ts | 43 ++++++++++++++++++++++++++++++++++++++++++- editors/code/src/lsp_ext.ts | 3 +++ 3 files changed, 46 insertions(+), 1 deletion(-) (limited to 'editors/code') diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index 65ad573d8..3e5915c28 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts @@ -161,6 +161,7 @@ class ExperimentalFeatures implements lc.StaticFeature { caps.codeActionGroup = true; caps.resolveCodeAction = true; caps.hoverActions = true; + caps.statusNotification = true; capabilities.experimental = caps; } initialize(_capabilities: lc.ServerCapabilities, _documentSelector: lc.DocumentSelector | undefined): void { 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 @@ import * as vscode from 'vscode'; import * as lc from 'vscode-languageclient'; +import * as ra from './lsp_ext'; import { Config } from './config'; import { createClient } from './client'; import { isRustEditor, RustEditor } from './util'; +import { Status } from './lsp_ext'; export class Ctx { private constructor( @@ -11,6 +13,7 @@ export class Ctx { private readonly extCtx: vscode.ExtensionContext, readonly client: lc.LanguageClient, readonly serverPath: string, + readonly statusBar: vscode.StatusBarItem, ) { } @@ -22,9 +25,18 @@ export class Ctx { cwd: string, ): Promise { const client = createClient(serverPath, cwd); - const res = new Ctx(config, extCtx, client, serverPath); + + const statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left); + extCtx.subscriptions.push(statusBar); + statusBar.text = "rust-analyzer"; + statusBar.tooltip = "ready"; + statusBar.show(); + + const res = new Ctx(config, extCtx, client, serverPath, statusBar); + res.pushCleanup(client.start()); await client.onReady(); + client.onNotification(ra.status, (status) => res.setStatus(status)); return res; } @@ -54,6 +66,35 @@ export class Ctx { return this.extCtx.subscriptions; } + setStatus(status: Status) { + switch (status) { + case "loading": + this.statusBar.text = "$(sync~spin) rust-analyzer"; + this.statusBar.tooltip = "Loading the project"; + this.statusBar.command = undefined; + this.statusBar.color = undefined; + break; + case "ready": + this.statusBar.text = "rust-analyzer"; + this.statusBar.tooltip = "Ready"; + this.statusBar.command = undefined; + this.statusBar.color = undefined; + break; + case "invalid": + this.statusBar.text = "$(error) rust-analyzer"; + this.statusBar.tooltip = "Failed to load the project"; + this.statusBar.command = undefined; + this.statusBar.color = new vscode.ThemeColor("notificationsErrorIcon.foreground"); + break; + case "needsReload": + this.statusBar.text = "$(warning) rust-analyzer"; + this.statusBar.tooltip = "Click to reload"; + this.statusBar.command = "rust-analyzer.reloadWorkspace"; + this.statusBar.color = new vscode.ThemeColor("notificationsWarningIcon.foreground"); + break; + } + } + pushCleanup(d: Disposable) { this.extCtx.subscriptions.push(d); } diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts index 981b6f40e..bf4703239 100644 --- a/editors/code/src/lsp_ext.ts +++ b/editors/code/src/lsp_ext.ts @@ -6,6 +6,9 @@ import * as lc from "vscode-languageclient"; export const analyzerStatus = new lc.RequestType("rust-analyzer/analyzerStatus"); +export type Status = "loading" | "ready" | "invalid" | "needsReload"; +export const status = new lc.NotificationType("rust-analyzer/status"); + export const reloadWorkspace = new lc.RequestType("rust-analyzer/reloadWorkspace"); export interface SyntaxTreeParams { -- cgit v1.2.3