aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server/src')
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs48
-rw-r--r--crates/ra_lsp_server/src/project_model.rs4
2 files changed, 29 insertions, 23 deletions
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs
index 97c1be778..3ebae4ecd 100644
--- a/crates/ra_lsp_server/src/main_loop.rs
+++ b/crates/ra_lsp_server/src/main_loop.rs
@@ -7,7 +7,7 @@ use std::{
7 sync::Arc, 7 sync::Arc,
8}; 8};
9 9
10use crossbeam_channel::{unbounded, select, Receiver, Sender}; 10use crossbeam_channel::{unbounded, select, Receiver, Sender, RecvError};
11use gen_lsp_server::{ 11use gen_lsp_server::{
12 handle_shutdown, ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse, 12 handle_shutdown, ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse,
13}; 13};
@@ -62,7 +62,7 @@ pub fn main_loop(
62 let (task_sender, task_receiver) = unbounded::<Task>(); 62 let (task_sender, task_receiver) = unbounded::<Task>();
63 let (ws_worker, ws_watcher) = workspace_loader(); 63 let (ws_worker, ws_watcher) = workspace_loader();
64 64
65 ws_worker.send(ws_root.clone()); 65 ws_worker.send(ws_root.clone()).unwrap();
66 // FIXME: support dynamic workspace loading. 66 // FIXME: support dynamic workspace loading.
67 let workspaces = match ws_worker.recv().unwrap() { 67 let workspaces = match ws_worker.recv().unwrap() {
68 Ok(ws) => vec![ws], 68 Ok(ws) => vec![ws],
@@ -95,7 +95,9 @@ pub fn main_loop(
95 ); 95 );
96 96
97 log::info!("waiting for tasks to finish..."); 97 log::info!("waiting for tasks to finish...");
98 task_receiver.for_each(|task| on_task(task, msg_sender, &mut pending_requests)); 98 task_receiver
99 .into_iter()
100 .for_each(|task| on_task(task, msg_sender, &mut pending_requests));
99 log::info!("...tasks have finished"); 101 log::info!("...tasks have finished");
100 log::info!("joining threadpool..."); 102 log::info!("joining threadpool...");
101 drop(pool); 103 drop(pool);
@@ -170,16 +172,16 @@ fn main_loop_inner(
170 loop { 172 loop {
171 log::trace!("selecting"); 173 log::trace!("selecting");
172 let event = select! { 174 let event = select! {
173 recv(msg_receiver, msg) => match msg { 175 recv(msg_receiver) -> msg => match msg {
174 Some(msg) => Event::Msg(msg), 176 Ok(msg) => Event::Msg(msg),
175 None => bail!("client exited without shutdown"), 177 Err(RecvError) => bail!("client exited without shutdown"),
176 }, 178 },
177 recv(task_receiver, task) => Event::Task(task.unwrap()), 179 recv(task_receiver) -> task => Event::Task(task.unwrap()),
178 recv(state.vfs.read().task_receiver(), task) => match task { 180 recv(state.vfs.read().task_receiver()) -> task => match task {
179 None => bail!("vfs died"), 181 Ok(task) => Event::Vfs(task),
180 Some(task) => Event::Vfs(task), 182 Err(RecvError) => bail!("vfs died"),
181 } 183 },
182 recv(libdata_receiver, data) => Event::Lib(data.unwrap()) 184 recv(libdata_receiver) -> data => Event::Lib(data.unwrap())
183 }; 185 };
184 log::info!("loop_turn = {:?}", event); 186 log::info!("loop_turn = {:?}", event);
185 let start = std::time::Instant::now(); 187 let start = std::time::Instant::now();
@@ -209,7 +211,7 @@ fn main_loop_inner(
209 ErrorCode::MethodNotFound as i32, 211 ErrorCode::MethodNotFound as i32,
210 "unknown request".to_string(), 212 "unknown request".to_string(),
211 ); 213 );
212 msg_sender.send(RawMessage::Response(resp)) 214 msg_sender.send(RawMessage::Response(resp)).unwrap()
213 } 215 }
214 } 216 }
215 } 217 }
@@ -229,7 +231,7 @@ fn main_loop_inner(
229 log::info!("indexing {:?} ... ", root); 231 log::info!("indexing {:?} ... ", root);
230 let data = LibraryData::prepare(root, files); 232 let data = LibraryData::prepare(root, files);
231 log::info!("indexed {:?} {:?}", start.elapsed(), root); 233 log::info!("indexed {:?} {:?}", start.elapsed(), root);
232 sender.send(data); 234 sender.send(data).unwrap();
233 }); 235 });
234 } 236 }
235 if state.roots_to_scan == 0 { 237 if state.roots_to_scan == 0 {
@@ -253,10 +255,12 @@ fn on_task(task: Task, msg_sender: &Sender<RawMessage>, pending_requests: &mut F
253 match task { 255 match task {
254 Task::Respond(response) => { 256 Task::Respond(response) => {
255 if pending_requests.remove(&response.id) { 257 if pending_requests.remove(&response.id) {
256 msg_sender.send(RawMessage::Response(response)) 258 msg_sender.send(RawMessage::Response(response)).unwrap();
257 } 259 }
258 } 260 }
259 Task::Notify(n) => msg_sender.send(RawMessage::Notification(n)), 261 Task::Notify(n) => {
262 msg_sender.send(RawMessage::Notification(n)).unwrap();
263 }
260 } 264 }
261} 265}
262 266
@@ -328,7 +332,7 @@ fn on_notification(
328 ErrorCode::RequestCancelled as i32, 332 ErrorCode::RequestCancelled as i32,
329 "canceled by client".to_string(), 333 "canceled by client".to_string(),
330 ); 334 );
331 msg_sender.send(RawMessage::Response(response)) 335 msg_sender.send(RawMessage::Response(response)).unwrap()
332 } 336 }
333 return Ok(()); 337 return Ok(());
334 } 338 }
@@ -381,7 +385,7 @@ fn on_notification(
381 diagnostics: Vec::new(), 385 diagnostics: Vec::new(),
382 }; 386 };
383 let not = RawNotification::new::<req::PublishDiagnostics>(&params); 387 let not = RawNotification::new::<req::PublishDiagnostics>(&params);
384 msg_sender.send(RawMessage::Notification(not)); 388 msg_sender.send(RawMessage::Notification(not)).unwrap();
385 return Ok(()); 389 return Ok(());
386 } 390 }
387 Err(not) => not, 391 Err(not) => not,
@@ -441,7 +445,7 @@ impl<'a> PoolDispatcher<'a> {
441 }, 445 },
442 }; 446 };
443 let task = Task::Respond(resp); 447 let task = Task::Respond(resp);
444 sender.send(task); 448 sender.send(task).unwrap();
445 }); 449 });
446 self.res = Some(id); 450 self.res = Some(id);
447 } 451 }
@@ -476,7 +480,7 @@ fn update_file_notifications_on_threadpool(
476 } 480 }
477 Ok(params) => { 481 Ok(params) => {
478 let not = RawNotification::new::<req::PublishDiagnostics>(&params); 482 let not = RawNotification::new::<req::PublishDiagnostics>(&params);
479 sender.send(Task::Notify(not)); 483 sender.send(Task::Notify(not)).unwrap();
480 } 484 }
481 } 485 }
482 if publish_decorations { 486 if publish_decorations {
@@ -488,7 +492,7 @@ fn update_file_notifications_on_threadpool(
488 } 492 }
489 Ok(params) => { 493 Ok(params) => {
490 let not = RawNotification::new::<req::PublishDecorations>(&params); 494 let not = RawNotification::new::<req::PublishDecorations>(&params);
491 sender.send(Task::Notify(not)) 495 sender.send(Task::Notify(not)).unwrap();
492 } 496 }
493 } 497 }
494 } 498 }
@@ -501,7 +505,7 @@ fn feedback(intrnal_mode: bool, msg: &str, sender: &Sender<RawMessage>) {
501 return; 505 return;
502 } 506 }
503 let not = RawNotification::new::<req::InternalFeedback>(&msg.to_string()); 507 let not = RawNotification::new::<req::InternalFeedback>(&msg.to_string());
504 sender.send(RawMessage::Notification(not)); 508 sender.send(RawMessage::Notification(not)).unwrap();
505} 509}
506 510
507fn is_canceled(e: &failure::Error) -> bool { 511fn is_canceled(e: &failure::Error) -> bool {
diff --git a/crates/ra_lsp_server/src/project_model.rs b/crates/ra_lsp_server/src/project_model.rs
index 5852a157d..ae2149463 100644
--- a/crates/ra_lsp_server/src/project_model.rs
+++ b/crates/ra_lsp_server/src/project_model.rs
@@ -204,8 +204,10 @@ pub fn workspace_loader() -> (Worker<PathBuf, Result<CargoWorkspace>>, WorkerHan
204 1, 204 1,
205 |input_receiver, output_sender| { 205 |input_receiver, output_sender| {
206 input_receiver 206 input_receiver
207 .into_iter()
207 .map(|path| CargoWorkspace::from_cargo_metadata(path.as_path())) 208 .map(|path| CargoWorkspace::from_cargo_metadata(path.as_path()))
208 .for_each(|it| output_sender.send(it)) 209 .try_for_each(|it| output_sender.send(it))
210 .unwrap()
209 }, 211 },
210 ) 212 )
211} 213}