From 36d922c87d0c933803441bde825ace5658af78b2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 10 Aug 2018 23:30:11 +0300 Subject: diagnostics --- crates/server/src/main.rs | 53 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 7 deletions(-) (limited to 'crates/server/src/main.rs') diff --git a/crates/server/src/main.rs b/crates/server/src/main.rs index 2d8695d23..6018350e3 100644 --- a/crates/server/src/main.rs +++ b/crates/server/src/main.rs @@ -11,6 +11,7 @@ extern crate crossbeam_channel; extern crate threadpool; #[macro_use] extern crate log; +extern crate url; extern crate flexi_logger; extern crate libeditor; extern crate libanalysis; @@ -31,7 +32,7 @@ use languageserver_types::{TextDocumentItem, VersionedTextDocumentIdentifier, Te use ::{ io::{Io, RawMsg}, - handlers::{handle_syntax_tree, handle_extend_selection}, + handlers::{handle_syntax_tree, handle_extend_selection, publish_diagnostics}, }; pub type Result = ::std::result::Result; @@ -209,6 +210,21 @@ fn main_loop( dispatch::handle_notification::(&mut not, |params| { let path = params.text_document.file_path()?; world.change_overlay(path, Some(params.text_document.text)); + let world = world.snapshot(); + let sender = sender.clone(); + let uri = params.text_document.uri; + pool.execute(move || { + match publish_diagnostics(world, uri) { + Err(e) => { + error!("failed to compute diagnostics: {:?}", e) + } + Ok(params) => { + sender.send(Box::new(|io: &mut Io| { + dispatch::send_notification::(io, params) + })) + } + } + }); Ok(()) })?; dispatch::handle_notification::(&mut not, |mut params| { @@ -217,11 +233,30 @@ fn main_loop( .ok_or_else(|| format_err!("empty changes"))? .text; world.change_overlay(path, Some(text)); + let world = world.snapshot(); + let sender = sender.clone(); + let uri = params.text_document.uri; + pool.execute(move || { + match publish_diagnostics(world, uri) { + Err(e) => { + error!("failed to compute diagnostics: {:?}", e) + } + Ok(params) => { + sender.send(Box::new(|io: &mut Io| { + dispatch::send_notification::(io, params) + })) + } + } + }); Ok(()) })?; dispatch::handle_notification::(&mut not, |params| { let path = params.text_document.file_path()?; world.change_overlay(path, None); + dispatch::send_notification::(io, req::PublishDiagnosticsParams { + uri: params.text_document.uri, + diagnostics: Vec::new(), + })?; Ok(()) })?; @@ -252,21 +287,25 @@ trait FilePath { impl FilePath for TextDocumentItem { fn file_path(&self) -> Result { - self.uri.to_file_path() - .map_err(|()| format_err!("invalid uri: {}", self.uri)) + self.uri.file_path() } } impl FilePath for VersionedTextDocumentIdentifier { fn file_path(&self) -> Result { - self.uri.to_file_path() - .map_err(|()| format_err!("invalid uri: {}", self.uri)) + self.uri.file_path() } } impl FilePath for TextDocumentIdentifier { fn file_path(&self) -> Result { - self.uri.to_file_path() - .map_err(|()| format_err!("invalid uri: {}", self.uri)) + self.uri.file_path() + } +} + +impl FilePath for ::url::Url { + fn file_path(&self) -> Result { + self.to_file_path() + .map_err(|()| format_err!("invalid uri: {}", self)) } } -- cgit v1.2.3