Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Use Notification::new
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanewok committed Nov 29, 2017
1 parent f9ed5a9 commit 3f41009
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 52 deletions.
6 changes: 1 addition & 5 deletions src/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -196,10 +195,7 @@ impl InitActionContext {
}
};

out.notify(Notification::<BeginBuild> {
params: NoParams {},
_action: PhantomData,
});
out.notify(Notification::<BeginBuild>::new(NoParams {}));
self.build_queue
.request_build(project_path, priority, move |result| pbh.handle(result));
}
Expand Down
26 changes: 5 additions & 21 deletions src/actions/post_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -42,10 +41,7 @@ pub struct PostBuildHandler<O: Output> {

impl<O: Output> PostBuildHandler<O> {
pub fn handle(self, result: BuildResult) {
self.out.notify(Notification::<DiagnosticsBegin> {
params: NoParams {},
_action: PhantomData,
});
self.out.notify(Notification::<DiagnosticsBegin>::new(NoParams {}));

match result {
BuildResult::Success(messages, new_analysis) => {
Expand All @@ -63,25 +59,16 @@ impl<O: Output> PostBuildHandler<O> {
self.reload_analysis_from_memory(new_analysis);
}

self.out.notify(Notification::<DiagnosticsEnd> {
params: NoParams {},
_action: PhantomData,
});
self.out.notify(Notification::<DiagnosticsEnd>::new(NoParams{}));
});
}
BuildResult::Squashed => {
trace!("build - Squashed");
self.out.notify(Notification::<DiagnosticsEnd> {
params: NoParams {},
_action: PhantomData,
});
self.out.notify(Notification::<DiagnosticsEnd>::new(NoParams{}));
}
BuildResult::Err => {
trace!("build - Error");
self.out.notify(Notification::<DiagnosticsEnd> {
params: NoParams {},
_action: PhantomData,
});
self.out.notify(Notification::<DiagnosticsEnd>::new(NoParams{}));
}
}
}
Expand Down Expand Up @@ -258,9 +245,6 @@ fn emit_notifications<O: Output>(build_results: &BuildResults, show_warnings: bo
.collect(),
};

out.notify(Notification::<PublishDiagnostics> {
params,
_action: PhantomData
});
out.notify(Notification::<PublishDiagnostics>::new(params));
}
}
22 changes: 0 additions & 22 deletions src/lsp_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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<PublishDiagnosticsParams>,
}

impl NotificationMessage {
/// Construct a new notification message.
pub fn new(method: &'static str, params: Option<PublishDiagnosticsParams>) -> 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<T>
Expand Down
15 changes: 11 additions & 4 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ pub struct Notification<A: Action> {
pub _action: PhantomData<A>,
}

impl<A: Action> Notification<A> {
/// Creates a `Notification` structure with given `params`.
pub fn new(params: A::Params) -> Notification<A> {
Notification {
params,
_action: PhantomData
}
}
}

impl<'a, A: BlockingRequestAction<'a>> Request<A> {
fn blocking_dispatch<O: Output>(
self,
Expand Down Expand Up @@ -678,10 +688,7 @@ mod test {

assert_eq!(
notification,
Ok(Notification::<notifications::Initialized> {
params: NoParams {},
_action: PhantomData,
})
Ok(Notification::<notifications::Initialized>::new(NoParams {}))
);
}
}

0 comments on commit 3f41009

Please sign in to comment.