aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-09-02 13:18:43 +0100
committerAleksey Kladov <[email protected]>2018-09-02 13:18:43 +0100
commit1329dd4e287c137ec0a90abeec0272275b2b2c8d (patch)
treed924f7bcc28b9c46d1643d54c5a2f109d19b2977
parent80be61ed78e8410e013cb94879435d54a4907c30 (diff)
Avoid clones
-rw-r--r--crates/gen_lsp_server/src/lib.rs4
-rw-r--r--crates/gen_lsp_server/src/msg.rs10
-rw-r--r--crates/server/src/main_loop/mod.rs10
-rw-r--r--crates/server/tests/heavy_tests/support.rs4
4 files changed, 14 insertions, 14 deletions
diff --git a/crates/gen_lsp_server/src/lib.rs b/crates/gen_lsp_server/src/lib.rs
index 0dc24ffc1..b25017045 100644
--- a/crates/gen_lsp_server/src/lib.rs
+++ b/crates/gen_lsp_server/src/lib.rs
@@ -51,7 +51,7 @@ pub fn run_server(
51pub fn handle_shutdown(req: RawRequest, sender: &Sender<RawMessage>) -> Option<RawRequest> { 51pub fn handle_shutdown(req: RawRequest, sender: &Sender<RawMessage>) -> Option<RawRequest> {
52 match req.cast::<Shutdown>() { 52 match req.cast::<Shutdown>() {
53 Ok((id, ())) => { 53 Ok((id, ())) => {
54 let resp = RawResponse::ok::<Shutdown>(id, ()); 54 let resp = RawResponse::ok::<Shutdown>(id, &());
55 sender.send(RawMessage::Response(resp)); 55 sender.send(RawMessage::Response(resp));
56 None 56 None
57 } 57 }
@@ -72,7 +72,7 @@ fn initialize(
72 msg => 72 msg =>
73 bail!("expected initialize request, got {:?}", msg), 73 bail!("expected initialize request, got {:?}", msg),
74 }; 74 };
75 let resp = RawResponse::ok::<Initialize>(id, InitializeResult { capabilities: caps }); 75 let resp = RawResponse::ok::<Initialize>(id, &InitializeResult { capabilities: caps });
76 sender.send(RawMessage::Response(resp)); 76 sender.send(RawMessage::Response(resp));
77 match receiver.recv() { 77 match receiver.recv() {
78 Some(RawMessage::Notification(n)) => { 78 Some(RawMessage::Notification(n)) => {
diff --git a/crates/gen_lsp_server/src/msg.rs b/crates/gen_lsp_server/src/msg.rs
index 42241194d..7fcac6f6d 100644
--- a/crates/gen_lsp_server/src/msg.rs
+++ b/crates/gen_lsp_server/src/msg.rs
@@ -88,7 +88,7 @@ impl RawMessage {
88} 88}
89 89
90impl RawRequest { 90impl RawRequest {
91 pub fn new<R>(id: u64, params: R::Params) -> RawRequest 91 pub fn new<R>(id: u64, params: &R::Params) -> RawRequest
92 where 92 where
93 R: Request, 93 R: Request,
94 R::Params: Serialize, 94 R::Params: Serialize,
@@ -96,7 +96,7 @@ impl RawRequest {
96 RawRequest { 96 RawRequest {
97 id: id, 97 id: id,
98 method: R::METHOD.to_string(), 98 method: R::METHOD.to_string(),
99 params: to_value(&params).unwrap(), 99 params: to_value(params).unwrap(),
100 } 100 }
101 } 101 }
102 pub fn cast<R>(self) -> ::std::result::Result<(u64, R::Params), RawRequest> 102 pub fn cast<R>(self) -> ::std::result::Result<(u64, R::Params), RawRequest>
@@ -114,7 +114,7 @@ impl RawRequest {
114} 114}
115 115
116impl RawResponse { 116impl RawResponse {
117 pub fn ok<R>(id: u64, result: R::Result) -> RawResponse 117 pub fn ok<R>(id: u64, result: &R::Result) -> RawResponse
118 where R: Request, 118 where R: Request,
119 R::Result: Serialize, 119 R::Result: Serialize,
120 { 120 {
@@ -135,14 +135,14 @@ impl RawResponse {
135} 135}
136 136
137impl RawNotification { 137impl RawNotification {
138 pub fn new<N>(params: N::Params) -> RawNotification 138 pub fn new<N>(params: &N::Params) -> RawNotification
139 where 139 where
140 N: Notification, 140 N: Notification,
141 N::Params: Serialize, 141 N::Params: Serialize,
142 { 142 {
143 RawNotification { 143 RawNotification {
144 method: N::METHOD.to_string(), 144 method: N::METHOD.to_string(),
145 params: to_value(&params).unwrap(), 145 params: to_value(params).unwrap(),
146 } 146 }
147 } 147 }
148 pub fn cast<N>(self) -> ::std::result::Result<N::Params, RawNotification> 148 pub fn cast<N>(self) -> ::std::result::Result<N::Params, RawNotification>
diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs
index 52fc00c9c..bb1d638e0 100644
--- a/crates/server/src/main_loop/mod.rs
+++ b/crates/server/src/main_loop/mod.rs
@@ -130,7 +130,7 @@ fn main_loop_inner(
130 Event::Ws(ws) => { 130 Event::Ws(ws) => {
131 match ws { 131 match ws {
132 Ok(ws) => { 132 Ok(ws) => {
133 let not = RawNotification::new::<req::DidReloadWorkspace>(vec![ws.clone()]); 133 let not = RawNotification::new::<req::DidReloadWorkspace>(&vec![ws.clone()]);
134 msg_sender.send(RawMessage::Notification(not)); 134 msg_sender.send(RawMessage::Notification(not));
135 state.set_workspaces(vec![ws]); 135 state.set_workspaces(vec![ws]);
136 state_changed = true; 136 state_changed = true;
@@ -288,7 +288,7 @@ fn on_notification(
288 let file_id = state.remove_mem_file(path.as_path())?; 288 let file_id = state.remove_mem_file(path.as_path())?;
289 subs.remove_sub(file_id); 289 subs.remove_sub(file_id);
290 let params = req::PublishDiagnosticsParams { uri, diagnostics: Vec::new() }; 290 let params = req::PublishDiagnosticsParams { uri, diagnostics: Vec::new() };
291 let not = RawNotification::new::<req::PublishDiagnostics>(params); 291 let not = RawNotification::new::<req::PublishDiagnostics>(&params);
292 msg_sender.send(RawMessage::Notification(not)); 292 msg_sender.send(RawMessage::Notification(not));
293 return Ok(()) 293 return Ok(())
294 } 294 }
@@ -326,7 +326,7 @@ impl<'a> PoolDispatcher<'a> {
326 let sender = self.sender.clone(); 326 let sender = self.sender.clone();
327 self.pool.execute(move || { 327 self.pool.execute(move || {
328 let resp = match f(world, params, token) { 328 let resp = match f(world, params, token) {
329 Ok(resp) => RawResponse::ok::<R>(id, resp), 329 Ok(resp) => RawResponse::ok::<R>(id, &resp),
330 Err(e) => RawResponse::err(id, ErrorCode::InternalError as i32, e.to_string()), 330 Err(e) => RawResponse::err(id, ErrorCode::InternalError as i32, e.to_string()),
331 }; 331 };
332 let task = Task::Respond(resp); 332 let task = Task::Respond(resp);
@@ -363,7 +363,7 @@ fn update_file_notifications_on_threadpool(
363 error!("failed to compute diagnostics: {:?}", e) 363 error!("failed to compute diagnostics: {:?}", e)
364 } 364 }
365 Ok(params) => { 365 Ok(params) => {
366 let not = RawNotification::new::<req::PublishDiagnostics>(params); 366 let not = RawNotification::new::<req::PublishDiagnostics>(&params);
367 sender.send(Task::Notify(not)); 367 sender.send(Task::Notify(not));
368 } 368 }
369 } 369 }
@@ -372,7 +372,7 @@ fn update_file_notifications_on_threadpool(
372 error!("failed to compute decorations: {:?}", e) 372 error!("failed to compute decorations: {:?}", e)
373 } 373 }
374 Ok(params) => { 374 Ok(params) => {
375 let not = RawNotification::new::<req::PublishDecorations>(params); 375 let not = RawNotification::new::<req::PublishDecorations>(&params);
376 sender.send(Task::Notify(not)) 376 sender.send(Task::Notify(not))
377 } 377 }
378 } 378 }
diff --git a/crates/server/tests/heavy_tests/support.rs b/crates/server/tests/heavy_tests/support.rs
index 006926216..76cbd56ea 100644
--- a/crates/server/tests/heavy_tests/support.rs
+++ b/crates/server/tests/heavy_tests/support.rs
@@ -83,7 +83,7 @@ impl Server {
83 }; 83 };
84 for (path, text) in files { 84 for (path, text) in files {
85 res.send_notification(RawNotification::new::<DidOpenTextDocument>( 85 res.send_notification(RawNotification::new::<DidOpenTextDocument>(
86 DidOpenTextDocumentParams { 86 &DidOpenTextDocumentParams {
87 text_document: TextDocumentItem { 87 text_document: TextDocumentItem {
88 uri: Url::from_file_path(path).unwrap(), 88 uri: Url::from_file_path(path).unwrap(),
89 language_id: "rust".to_string(), 89 language_id: "rust".to_string(),
@@ -149,7 +149,7 @@ impl Server {
149 R: Request, 149 R: Request,
150 R::Params: Serialize, 150 R::Params: Serialize,
151 { 151 {
152 let r = RawRequest::new::<R>(id, params); 152 let r = RawRequest::new::<R>(id, &params);
153 self.sender.as_ref() 153 self.sender.as_ref()
154 .unwrap() 154 .unwrap()
155 .send(RawMessage::Request(r)); 155 .send(RawMessage::Request(r));