From 0ba7e2eaebf335dbc31b5d6dbc9c354737c7fe54 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 23 Jan 2019 00:15:03 +0300 Subject: ad status command --- crates/ra_lsp_server/src/main_loop.rs | 1 + crates/ra_lsp_server/src/main_loop/handlers.rs | 4 ++++ crates/ra_lsp_server/src/req.rs | 8 ++++++++ crates/ra_lsp_server/src/server_world.rs | 15 +++++++++++++++ 4 files changed, 28 insertions(+) (limited to 'crates/ra_lsp_server') diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index fa07b1942..f51576521 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -285,6 +285,7 @@ fn on_request( sender, }; let req = pool_dispatcher + .on::(handlers::handle_analyzer_status)? .on::(handlers::handle_syntax_tree)? .on::(handlers::handle_extend_selection)? .on::(handlers::handle_find_matching_brace)? diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 497f819be..d84f762f4 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -23,6 +23,10 @@ use crate::{ LspError, Result, }; +pub fn handle_analyzer_status(world: ServerWorld, _: ()) -> Result { + Ok(world.status()) +} + pub fn handle_syntax_tree(world: ServerWorld, params: req::SyntaxTreeParams) -> Result { let id = params.text_document.try_conv_with(&world)?; let res = world.analysis().syntax_tree(id); diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs index 156cf9641..ec6b6d905 100644 --- a/crates/ra_lsp_server/src/req.rs +++ b/crates/ra_lsp_server/src/req.rs @@ -11,6 +11,14 @@ pub use lsp_types::{ TextDocumentPositionParams, TextEdit, WorkspaceEdit, WorkspaceSymbolParams, }; +pub enum AnalyzerStatus {} + +impl Request for AnalyzerStatus { + type Params = (); + type Result = String; + const METHOD: &'static str = "ra/analyzerStatus"; +} + pub enum SyntaxTree {} impl Request for SyntaxTree { diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs index c24ded9f9..5cb97b29b 100644 --- a/crates/ra_lsp_server/src/server_world.rs +++ b/crates/ra_lsp_server/src/server_world.rs @@ -264,4 +264,19 @@ impl ServerWorld { .map_err(|_| format_err!("can't convert path to url: {}", path.display()))?; Ok(url) } + + pub fn status(&self) -> String { + let mut res = String::new(); + if self.workspaces.is_empty() { + res.push_str("no workspaces\n") + } else { + res.push_str("workspaces:\n"); + for w in self.workspaces.iter() { + res += &format!("{} packages loaded\n", w.cargo.packages().count()); + } + } + res.push_str("\nanalysis:\n"); + res.push_str(&self.analysis.status()); + res + } } -- cgit v1.2.3