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

Commit 09630fd

Browse files
committed
Use Notification::new
1 parent 3ee4da3 commit 09630fd

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)
@@ -64,25 +60,16 @@ impl<O: Output> PostBuildHandler<O> {
6460
self.reload_analysis_from_memory(new_analysis);
6561
}
6662

67-
self.out.notify(Notification::<DiagnosticsEnd> {
68-
params: NoParams {},
69-
_action: PhantomData,
70-
});
63+
self.out.notify(Notification::<DiagnosticsEnd>::new(NoParams{}));
7164
});
7265
}
7366
BuildResult::Squashed => {
7467
trace!("build - Squashed");
75-
self.out.notify(Notification::<DiagnosticsEnd> {
76-
params: NoParams {},
77-
_action: PhantomData,
78-
});
68+
self.out.notify(Notification::<DiagnosticsEnd>::new(NoParams{}));
7969
}
8070
BuildResult::Err => {
8171
trace!("build - Error");
82-
self.out.notify(Notification::<DiagnosticsEnd> {
83-
params: NoParams {},
84-
_action: PhantomData,
85-
});
72+
self.out.notify(Notification::<DiagnosticsEnd>::new(NoParams{}));
8673
}
8774
}
8875
}
@@ -259,9 +246,6 @@ fn emit_notifications<O: Output>(build_results: &BuildResults, show_warnings: bo
259246
.collect(),
260247
};
261248

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

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)]
@@ -249,27 +248,6 @@ impl Default for InitializationOptions {
249248
}
250249
}
251250

252-
/// An event-like (no response needed) notification message.
253-
#[derive(Debug, Serialize)]
254-
pub struct NotificationMessage {
255-
jsonrpc: version::Version,
256-
/// The well-known language server protocol notification method string.
257-
pub method: &'static str,
258-
/// Extra notification parameters.
259-
pub params: Option<PublishDiagnosticsParams>,
260-
}
261-
262-
impl NotificationMessage {
263-
/// Construct a new notification message.
264-
pub fn new(method: &'static str, params: Option<PublishDiagnosticsParams>) -> Self {
265-
NotificationMessage {
266-
jsonrpc: version::Version::V2,
267-
method,
268-
params,
269-
}
270-
}
271-
}
272-
273251
/// A JSON language server protocol request that will have a matching response.
274252
#[derive(Debug, Serialize)]
275253
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)