From 3ef76760761d17cef4ea4e8462d9ee2ca8395467 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 2 Jul 2020 12:37:04 +0200 Subject: Implement StatusBar --- crates/rust-analyzer/src/config.rs | 2 ++ crates/rust-analyzer/src/global_state.rs | 1 + crates/rust-analyzer/src/lsp_ext.rs | 18 +++++++++++++++++- crates/rust-analyzer/src/main_loop.rs | 18 +++++++++++++++--- 4 files changed, 35 insertions(+), 4 deletions(-) (limited to 'crates') diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 6c311648a..21acfe644 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -130,6 +130,7 @@ pub struct ClientCapsConfig { pub code_action_group: bool, pub resolve_code_action: bool, pub hover_actions: bool, + pub status_notification: bool, } impl Config { @@ -365,6 +366,7 @@ impl Config { self.client_caps.code_action_group = get_bool("codeActionGroup"); self.client_caps.resolve_code_action = get_bool("resolveCodeAction"); self.client_caps.hover_actions = get_bool("hoverActions"); + self.client_caps.status_notification = get_bool("statusNotification"); } } } diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index b7b4edf66..5e9cae3f8 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs @@ -31,6 +31,7 @@ use crate::{ pub(crate) enum Status { Loading, Ready, + Invalid, } impl Default for Status { diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs index 82207bbb8..d225ad5ff 100644 --- a/crates/rust-analyzer/src/lsp_ext.rs +++ b/crates/rust-analyzer/src/lsp_ext.rs @@ -3,7 +3,7 @@ use std::{collections::HashMap, path::PathBuf}; use lsp_types::request::Request; -use lsp_types::{Position, Range, TextDocumentIdentifier}; +use lsp_types::{notification::Notification, Position, Range, TextDocumentIdentifier}; use serde::{Deserialize, Serialize}; pub enum AnalyzerStatus {} @@ -208,6 +208,22 @@ pub struct SsrParams { pub parse_only: bool, } +pub enum StatusNotification {} + +#[serde(rename_all = "camelCase")] +#[derive(Serialize, Deserialize)] +pub enum Status { + Loading, + Ready, + NeedsReload, + Invalid, +} + +impl Notification for StatusNotification { + type Params = Status; + const METHOD: &'static str = "rust-analyzer/status"; +} + pub enum CodeActionRequest {} impl Request for CodeActionRequest { diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index e03038b25..a5a8c17a0 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -169,16 +169,16 @@ impl GlobalState { } vfs::loader::Message::Progress { n_total, n_done } => { if n_total == 0 { - self.status = Status::Ready; + self.transition(Status::Invalid); } else { let state = if n_done == 0 { - self.status = Status::Loading; + self.transition(Status::Loading); Progress::Begin } else if n_done < n_total { Progress::Report } else { assert_eq!(n_done, n_total); - self.status = Status::Ready; + self.transition(Status::Ready); Progress::End }; self.report_progress( @@ -274,6 +274,18 @@ impl GlobalState { Ok(()) } + fn transition(&mut self, new_status: Status) { + self.status = Status::Ready; + if self.config.client_caps.status_notification { + let lsp_status = match new_status { + Status::Loading => lsp_ext::Status::Loading, + Status::Ready => lsp_ext::Status::Ready, + Status::Invalid => lsp_ext::Status::Invalid, + }; + self.send_notification::(lsp_status); + } + } + fn on_request(&mut self, request_received: Instant, req: Request) -> Result<()> { self.register_request(&req, request_received); -- cgit v1.2.3