From 8fe20b19d4702fc6d6933c31abddc8539d2581f0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 6 Apr 2021 14:16:35 +0300 Subject: More robust status notifications --- editors/code/src/client.ts | 2 +- editors/code/src/ctx.ts | 47 +++++++++++++++++---------------------------- editors/code/src/lsp_ext.ts | 9 +++++---- 3 files changed, 24 insertions(+), 34 deletions(-) (limited to 'editors/code') diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index 0771ca3b6..116f41df6 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts @@ -159,7 +159,7 @@ class ExperimentalFeatures implements lc.StaticFeature { caps.snippetTextEdit = true; caps.codeActionGroup = true; caps.hoverActions = true; - caps.statusNotification = true; + caps.serverStatusNotification = 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 c07583cfa..c05e757f8 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts @@ -5,7 +5,7 @@ import * as ra from './lsp_ext'; import { Config } from './config'; import { createClient } from './client'; import { isRustEditor, RustEditor } from './util'; -import { Status } from './lsp_ext'; +import { ServerStatusParams } from './lsp_ext'; export class Ctx { private constructor( @@ -36,7 +36,7 @@ export class Ctx { res.pushCleanup(client.start()); await client.onReady(); - client.onNotification(ra.status, (params) => res.setStatus(params.status)); + client.onNotification(ra.serverStatus, (params) => res.setServerStatus(params)); return res; } @@ -66,39 +66,28 @@ 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; + setServerStatus(status: ServerStatusParams) { + this.statusBar.tooltip = status.message ?? "Ready"; + let icon = ""; + switch (status.health) { + case "ok": this.statusBar.color = undefined; break; - case "readyPartial": - this.statusBar.text = "rust-analyzer"; - this.statusBar.tooltip = "Ready (Partial)"; - 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"; + case "warning": + this.statusBar.tooltip += "\nClick to reload." this.statusBar.command = "rust-analyzer.reloadWorkspace"; this.statusBar.color = new vscode.ThemeColor("notificationsWarningIcon.foreground"); + icon = "$(warning) "; + break; + case "error": + this.statusBar.tooltip += "\nClick to reload." + this.statusBar.command = "rust-analyzer.reloadWorkspace"; + this.statusBar.color = new vscode.ThemeColor("notificationsErrorIcon.foreground"); + icon = "$(error) "; break; } + if (!status.quiescent) icon = "$(sync~spin) "; + this.statusBar.text = `${icon} rust-analyzer`; } pushCleanup(d: Disposable) { diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts index 00e128b8c..2e1744f1b 100644 --- a/editors/code/src/lsp_ext.ts +++ b/editors/code/src/lsp_ext.ts @@ -10,11 +10,12 @@ export interface AnalyzerStatusParams { export const analyzerStatus = new lc.RequestType("rust-analyzer/analyzerStatus"); export const memoryUsage = new lc.RequestType0("rust-analyzer/memoryUsage"); -export type Status = "loading" | "ready" | "readyPartial" | "invalid" | "needsReload"; -export interface StatusParams { - status: Status; +export interface ServerStatusParams { + health: "ok" | "warning" | "error" + quiescent: boolean + message?: string } -export const status = new lc.NotificationType("rust-analyzer/status"); +export const serverStatus = new lc.NotificationType("experimental/serverStatus"); export const reloadWorkspace = new lc.RequestType0("rust-analyzer/reloadWorkspace"); -- cgit v1.2.3