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

Commit 3f41009

Browse files
committed
Use Notification::new
1 parent f9ed5a9 commit 3f41009

File tree

4 files changed

+17
-52
lines changed

4 files changed

+17
-52
lines changed

src/actions/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use std::collections::HashMap;
2929
use std::path::{Path, PathBuf};
3030
use std::sync::{Arc, Mutex};
3131
use std::thread;
32-
use std::marker::PhantomData;
3332

3433

3534
// TODO: Support non-`file` URI schemes in VFS. We're currently ignoring them because
@@ -196,10 +195,7 @@ impl InitActionContext {
196195
}
197196
};
198197

199-
out.notify(Notification::<BeginBuild> {
200-
params: NoParams {},
201-
_action: PhantomData,
202-
});
198+
out.notify(Notification::<BeginBuild>::new(NoParams {}));
203199
self.build_queue
204200
.request_build(project_path, priority, move |result| pbh.handle(result));
205201
}

src/actions/post_build.rs

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use std::collections::HashMap;
1212
use std::path::{Path, PathBuf};
1313
use std::sync::{Arc, Mutex};
1414
use std::thread;
15-
use std::marker::PhantomData;
1615

1716
use build::BuildResult;
1817
use lsp_data::{ls_util, PublishDiagnosticsParams};
@@ -42,10 +41,7 @@ pub struct PostBuildHandler<O: Output> {
4241

4342
impl<O: Output> PostBuildHandler<O> {
4443
pub fn handle(self, result: BuildResult) {
45-
self.out.notify(Notification::<DiagnosticsBegin> {
46-
params: NoParams {},
47-
_action: PhantomData,
48-
});
44+
self.out.notify(Notification::<DiagnosticsBegin>::new(NoParams {}));
4945

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

66-
self.out.notify(Notification::<DiagnosticsEnd> {
67-
params: NoParams {},
68-
_action: PhantomData,
69-
});
62+
self.out.notify(Notification::<DiagnosticsEnd>::new(NoParams{}));
7063
});
7164
}
7265
BuildResult::Squashed => {
7366
trace!("build - Squashed");
74-
self.out.notify(Notification::<DiagnosticsEnd> {
75-
params: NoParams {},
76-
_action: PhantomData,
77-
});
67+
self.out.notify(Notification::<DiagnosticsEnd>::new(NoParams{}));
7868
}
7969
BuildResult::Err => {
8070
trace!("build - Error");
81-
self.out.notify(Notification::<DiagnosticsEnd> {
82-
params: NoParams {},
83-
_action: PhantomData,
84-
});
71+
self.out.notify(Notification::<DiagnosticsEnd>::new(NoParams{}));
8572
}
8673
}
8774
}
@@ -258,9 +245,6 @@ fn emit_notifications<O: Output>(build_results: &BuildResults, show_warnings: bo
258245
.collect(),
259246
};
260247

261-
out.notify(Notification::<PublishDiagnostics> {
262-
params,
263-
_action: PhantomData
264-
});
248+
out.notify(Notification::<PublishDiagnostics>::new(params));
265249
}
266250
}

src/lsp_data.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use racer;
2323
use vfs::FileContents;
2424

2525
pub use ls_types::*;
26-
use jsonrpc_core::version;
2726

2827
/// Errors that can occur when parsing a file URI.
2928
#[derive(Debug)]
@@ -263,27 +262,6 @@ impl Default for InitializationOptions {
263262
}
264263
}
265264

266-
/// An event-like (no response needed) notification message.
267-
#[derive(Debug, Serialize)]
268-
pub struct NotificationMessage {
269-
jsonrpc: version::Version,
270-
/// The well-known language server protocol notification method string.
271-
pub method: &'static str,
272-
/// Extra notification parameters.
273-
pub params: Option<PublishDiagnosticsParams>,
274-
}
275-
276-
impl NotificationMessage {
277-
/// Construct a new notification message.
278-
pub fn new(method: &'static str, params: Option<PublishDiagnosticsParams>) -> Self {
279-
NotificationMessage {
280-
jsonrpc: version::Version::V2,
281-
method,
282-
params,
283-
}
284-
}
285-
}
286-
287265
/// A JSON language server protocol request that will have a matching response.
288266
#[derive(Debug, Serialize)]
289267
pub struct RequestMessage<T>

src/server/mod.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ pub struct Notification<A: Action> {
153153
pub _action: PhantomData<A>,
154154
}
155155

156+
impl<A: Action> Notification<A> {
157+
/// Creates a `Notification` structure with given `params`.
158+
pub fn new(params: A::Params) -> Notification<A> {
159+
Notification {
160+
params,
161+
_action: PhantomData
162+
}
163+
}
164+
}
165+
156166
impl<'a, A: BlockingRequestAction<'a>> Request<A> {
157167
fn blocking_dispatch<O: Output>(
158168
self,
@@ -678,10 +688,7 @@ mod test {
678688

679689
assert_eq!(
680690
notification,
681-
Ok(Notification::<notifications::Initialized> {
682-
params: NoParams {},
683-
_action: PhantomData,
684-
})
691+
Ok(Notification::<notifications::Initialized>::new(NoParams {}))
685692
);
686693
}
687694
}

0 commit comments

Comments
 (0)