From c4a5672bc89c9897b7cb520ee5388dc97dc0ea06 Mon Sep 17 00:00:00 2001 From: Tad Hardesty Date: Tue, 17 Apr 2018 18:56:31 -0700 Subject: [PATCH] Add an extra notification to make environment loading less noisy --- Cargo.lock | 1 + src/langserver/Cargo.toml | 1 + src/langserver/extras.rs | 14 ++++++++++++++ src/langserver/main.rs | 35 +++++++++++++++++++++++++++++++---- 4 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 src/langserver/extras.rs diff --git a/Cargo.lock b/Cargo.lock index 5061a67b..7a8630f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -148,6 +148,7 @@ dependencies = [ "languageserver-types 0.36.0 (registry+https://github.com/rust-lang/crates.io-index)", "petgraph 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/src/langserver/Cargo.toml b/src/langserver/Cargo.toml index 23da0f3c..4fa37b77 100644 --- a/src/langserver/Cargo.toml +++ b/src/langserver/Cargo.toml @@ -11,6 +11,7 @@ path = "main.rs" url = "1.6.0" serde = "1.0.27" serde_json = "1.0.10" +serde_derive = "1.0.27" jsonrpc-core = "8.0.1" languageserver-types = "0.36" dreammaker = { path = "../dreammaker" } diff --git a/src/langserver/extras.rs b/src/langserver/extras.rs new file mode 100644 index 00000000..2c0cd904 --- /dev/null +++ b/src/langserver/extras.rs @@ -0,0 +1,14 @@ +//! Extensions to the language server protocol. + +use langserver::notification::*; + +pub enum WindowStatus {} +impl Notification for WindowStatus { + const METHOD: &'static str = "$window/status"; + type Params = WindowStatusParams; +} +#[derive(Debug, Default, Serialize)] +pub struct WindowStatusParams { + pub environment: Option, + pub tasks: Vec, +} diff --git a/src/langserver/main.rs b/src/langserver/main.rs index 63b5f4b9..94c9ed81 100644 --- a/src/langserver/main.rs +++ b/src/langserver/main.rs @@ -9,6 +9,7 @@ extern crate url; extern crate serde; extern crate serde_json; +#[macro_use] extern crate serde_derive; extern crate petgraph; extern crate languageserver_types as langserver; extern crate jsonrpc_core as jsonrpc; @@ -18,6 +19,7 @@ extern crate dreammaker as dm; mod io; mod document; mod symbol_search; +mod extras; use std::path::PathBuf; use std::collections::HashMap; @@ -114,6 +116,15 @@ impl<'a, R: io::RequestRead, W: io::ResponseWrite> Engine<'a, R, W> { ) } + fn show_status(&mut self, message: S) where + S: Into + { + self.issue_notification::(extras::WindowStatusParams { + environment: None, + tasks: vec![message.into()], + }); + } + fn file_url(&self, file: dm::FileId) -> Result { path_to_url(self.root.join(self.context.file_path(file))) } @@ -139,14 +150,30 @@ impl<'a, R: io::RequestRead, W: io::ResponseWrite> Engine<'a, R, W> { fn parse_environment(&mut self, environment: PathBuf) -> Result<(), jsonrpc::Error> { // handle the parsing - let file_name = environment.file_name().unwrap_or("..".as_ref()).to_string_lossy(); eprintln!("environment: {}", environment.display()); + if let Some(stem) = environment.file_stem() { + self.issue_notification::(extras::WindowStatusParams { + environment: Some(stem.to_string_lossy().into_owned()), + tasks: vec!["loading".to_owned()], + }) + } else { + self.show_status("loading"); + } let ctx = self.context; let mut pp = match dm::preprocessor::Preprocessor::new(ctx, environment.clone()) { Ok(pp) => pp, Err(err) => { - self.show_message(MessageType::Error, format!("Error loading {}", file_name)); + use std::error::Error; + self.issue_notification::( + langserver::PublishDiagnosticsParams { + uri: path_to_url(environment)?, + diagnostics: vec![langserver::Diagnostic { + message: err.description().to_owned(), + .. Default::default() + }], + } + ); eprintln!("{:?}", err); return Ok(()); } @@ -155,7 +182,7 @@ impl<'a, R: io::RequestRead, W: io::ResponseWrite> Engine<'a, R, W> { self.objtree = dm::parser::parse(ctx, dm::indents::IndentProcessor::new(ctx, &mut pp)); pp.finalize(); self.preprocessor = Some(pp); - self.show_message(MessageType::Info, format!("Loaded {}", file_name)); + self.issue_notification::(Default::default()); // initial diagnostics pump let mut map: HashMap<_, Vec<_>> = HashMap::new(); @@ -447,7 +474,7 @@ handle_notification! { if let Some(environment) = environment { self.parse_environment(environment)?; } else { - self.show_message(MessageType::Error, "No DME found, language service not available."); + self.show_status("no .dme file"); } }