aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-05-31 18:30:14 +0100
committerAleksey Kladov <[email protected]>2019-05-31 18:30:14 +0100
commit15efd58274855b755c99e5c088102920b70f3d80 (patch)
tree20f34929cb92cee869b36c0f808b9e07494562b8
parent2d773a46c91cd38862f2324de2bdf8a4fbbf1683 (diff)
cleanup
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs83
1 files changed, 48 insertions, 35 deletions
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs
index 9fc392749..ab22052d9 100644
--- a/crates/ra_lsp_server/src/main_loop.rs
+++ b/crates/ra_lsp_server/src/main_loop.rs
@@ -470,42 +470,16 @@ impl<'a> PoolDispatcher<'a> {
470 self.world.cancel_requests(); 470 self.world.cancel_requests();
471 } 471 }
472 472
473 let world = self.world.snapshot(); 473 self.pool.execute({
474 let sender = self.sender.clone(); 474 let world = self.world.snapshot();
475 self.pool.execute(move || { 475 let sender = self.sender.clone();
476 let response = match f(world, params) { 476 move || {
477 Ok(resp) => RawResponse::ok::<R>(id, &resp), 477 let result = f(world, params);
478 Err(e) => match e.downcast::<LspError>() { 478 let task = result_to_task::<R>(id, result);
479 Ok(lsp_error) => RawResponse::err(id, lsp_error.code, lsp_error.message), 479 sender.send(task).unwrap();
480 Err(e) => { 480 }
481 if is_canceled(&e) {
482 // FIXME: When https://github.com/Microsoft/vscode-languageserver-node/issues/457
483 // gets fixed, we can return the proper response.
484 // This works around the issue where "content modified" error would continuously
485 // show an message pop-up in VsCode
486 // RawResponse::err(
487 // id,
488 // ErrorCode::ContentModified as i32,
489 // "content modified".to_string(),
490 // )
491 RawResponse {
492 id,
493 result: Some(serde_json::to_value(&()).unwrap()),
494 error: None,
495 }
496 } else {
497 RawResponse::err(
498 id,
499 ErrorCode::InternalError as i32,
500 format!("{}\n{}", e, e.backtrace()),
501 )
502 }
503 }
504 },
505 };
506 let task = Task::Respond(response);
507 sender.send(task).unwrap();
508 }); 481 });
482
509 Ok(self) 483 Ok(self)
510 } 484 }
511 485
@@ -518,6 +492,45 @@ impl<'a> PoolDispatcher<'a> {
518 } 492 }
519} 493}
520 494
495fn result_to_task<R>(id: u64, result: Result<R::Result>) -> Task
496where
497 R: req::Request + 'static,
498 R::Params: DeserializeOwned + Send + 'static,
499 R::Result: Serialize + 'static,
500{
501 let response = match result {
502 Ok(resp) => RawResponse::ok::<R>(id, &resp),
503 Err(e) => match e.downcast::<LspError>() {
504 Ok(lsp_error) => RawResponse::err(id, lsp_error.code, lsp_error.message),
505 Err(e) => {
506 if is_canceled(&e) {
507 // FIXME: When https://github.com/Microsoft/vscode-languageserver-node/issues/457
508 // gets fixed, we can return the proper response.
509 // This works around the issue where "content modified" error would continuously
510 // show an message pop-up in VsCode
511 // RawResponse::err(
512 // id,
513 // ErrorCode::ContentModified as i32,
514 // "content modified".to_string(),
515 // )
516 RawResponse {
517 id,
518 result: Some(serde_json::to_value(&()).unwrap()),
519 error: None,
520 }
521 } else {
522 RawResponse::err(
523 id,
524 ErrorCode::InternalError as i32,
525 format!("{}\n{}", e, e.backtrace()),
526 )
527 }
528 }
529 },
530 };
531 Task::Respond(response)
532}
533
521fn update_file_notifications_on_threadpool( 534fn update_file_notifications_on_threadpool(
522 pool: &ThreadPool, 535 pool: &ThreadPool,
523 world: ServerWorld, 536 world: ServerWorld,