From f75feb67244c279e75a4e8c9996a72eed729d321 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 17 Apr 2019 11:47:29 +0300 Subject: cleanup cancellation Now that we explicitelly exit the reading loop on exit notification, we can assume that the sender is always alive --- crates/gen_lsp_server/src/stdio.rs | 4 +--- crates/ra_lsp_server/tests/heavy_tests/support.rs | 15 +++++---------- 2 files changed, 6 insertions(+), 13 deletions(-) (limited to 'crates') diff --git a/crates/gen_lsp_server/src/stdio.rs b/crates/gen_lsp_server/src/stdio.rs index 5edfbc39c..2d6418400 100644 --- a/crates/gen_lsp_server/src/stdio.rs +++ b/crates/gen_lsp_server/src/stdio.rs @@ -27,9 +27,7 @@ pub fn stdio_transport() -> (Receiver, Sender, Threads) _ => false, }; - if let Err(_) = reader_sender.send(msg) { - break; - } + reader_sender.send(msg).unwrap(); if is_exit { break; diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs index b07882700..d68182174 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/support.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs @@ -77,7 +77,7 @@ pub struct Server { req_id: Cell, messages: RefCell>, dir: TempDir, - worker: Option>, + worker: Worker, } impl Server { @@ -99,12 +99,7 @@ impl Server { .unwrap() }, ); - let res = Server { - req_id: Cell::new(1), - dir, - messages: Default::default(), - worker: Some(worker), - }; + let res = Server { req_id: Cell::new(1), dir, messages: Default::default(), worker }; for (path, text) in files { res.send_notification(RawNotification::new::( @@ -157,7 +152,7 @@ impl Server { } fn send_request_(&self, r: RawRequest) -> Value { let id = r.id; - self.worker.as_ref().unwrap().sender().send(RawMessage::Request(r)).unwrap(); + self.worker.sender().send(RawMessage::Request(r)).unwrap(); while let Some(msg) = self.recv() { match msg { RawMessage::Request(req) => panic!("unexpected request: {:?}", req), @@ -197,13 +192,13 @@ impl Server { } } fn recv(&self) -> Option { - recv_timeout(&self.worker.as_ref().unwrap().receiver()).map(|msg| { + recv_timeout(&self.worker.receiver()).map(|msg| { self.messages.borrow_mut().push(msg.clone()); msg }) } fn send_notification(&self, not: RawNotification) { - self.worker.as_ref().unwrap().sender().send(RawMessage::Notification(not)).unwrap(); + self.worker.sender().send(RawMessage::Notification(not)).unwrap(); } pub fn path(&self) -> &Path { -- cgit v1.2.3