diff --git a/src/actions/mod.rs b/src/actions/mod.rs index 6e464e4efce..fc253ea6d94 100644 --- a/src/actions/mod.rs +++ b/src/actions/mod.rs @@ -29,7 +29,6 @@ use std::collections::HashMap; use std::path::{Path, PathBuf}; use std::sync::{Arc, Mutex}; use std::thread; -use std::marker::PhantomData; // TODO: Support non-`file` URI schemes in VFS. We're currently ignoring them because @@ -196,10 +195,7 @@ impl InitActionContext { } }; - out.notify(Notification:: { - params: NoParams {}, - _action: PhantomData, - }); + out.notify(Notification::::new(NoParams {})); self.build_queue .request_build(project_path, priority, move |result| pbh.handle(result)); } diff --git a/src/actions/post_build.rs b/src/actions/post_build.rs index cd22394f117..3269113c296 100644 --- a/src/actions/post_build.rs +++ b/src/actions/post_build.rs @@ -12,7 +12,6 @@ use std::collections::HashMap; use std::path::{Path, PathBuf}; use std::sync::{Arc, Mutex}; use std::thread; -use std::marker::PhantomData; use build::BuildResult; use lsp_data::{ls_util, PublishDiagnosticsParams}; @@ -42,10 +41,7 @@ pub struct PostBuildHandler { impl PostBuildHandler { pub fn handle(self, result: BuildResult) { - self.out.notify(Notification:: { - params: NoParams {}, - _action: PhantomData, - }); + self.out.notify(Notification::::new(NoParams {})); match result { BuildResult::Success(messages, new_analysis) => { @@ -63,25 +59,16 @@ impl PostBuildHandler { self.reload_analysis_from_memory(new_analysis); } - self.out.notify(Notification:: { - params: NoParams {}, - _action: PhantomData, - }); + self.out.notify(Notification::::new(NoParams{})); }); } BuildResult::Squashed => { trace!("build - Squashed"); - self.out.notify(Notification:: { - params: NoParams {}, - _action: PhantomData, - }); + self.out.notify(Notification::::new(NoParams{})); } BuildResult::Err => { trace!("build - Error"); - self.out.notify(Notification:: { - params: NoParams {}, - _action: PhantomData, - }); + self.out.notify(Notification::::new(NoParams{})); } } } @@ -258,9 +245,6 @@ fn emit_notifications(build_results: &BuildResults, show_warnings: bo .collect(), }; - out.notify(Notification:: { - params, - _action: PhantomData - }); + out.notify(Notification::::new(params)); } } diff --git a/src/lsp_data.rs b/src/lsp_data.rs index 3d31f7fe661..f571754d0f6 100644 --- a/src/lsp_data.rs +++ b/src/lsp_data.rs @@ -23,7 +23,6 @@ use racer; use vfs::FileContents; pub use ls_types::*; -use jsonrpc_core::version; /// Errors that can occur when parsing a file URI. #[derive(Debug)] @@ -263,27 +262,6 @@ impl Default for InitializationOptions { } } -/// An event-like (no response needed) notification message. -#[derive(Debug, Serialize)] -pub struct NotificationMessage { - jsonrpc: version::Version, - /// The well-known language server protocol notification method string. - pub method: &'static str, - /// Extra notification parameters. - pub params: Option, -} - -impl NotificationMessage { - /// Construct a new notification message. - pub fn new(method: &'static str, params: Option) -> Self { - NotificationMessage { - jsonrpc: version::Version::V2, - method, - params, - } - } -} - /// A JSON language server protocol request that will have a matching response. #[derive(Debug, Serialize)] pub struct RequestMessage diff --git a/src/server/mod.rs b/src/server/mod.rs index dbfd8d00def..30ecfcd3d38 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -153,6 +153,16 @@ pub struct Notification { pub _action: PhantomData, } +impl Notification { + /// Creates a `Notification` structure with given `params`. + pub fn new(params: A::Params) -> Notification { + Notification { + params, + _action: PhantomData + } + } +} + impl<'a, A: BlockingRequestAction<'a>> Request { fn blocking_dispatch( self, @@ -678,10 +688,7 @@ mod test { assert_eq!( notification, - Ok(Notification:: { - params: NoParams {}, - _action: PhantomData, - }) + Ok(Notification::::new(NoParams {})) ); } }