1158: cleanup cancellation r=matklad a=matklad

Now that we explicitelly exit the reading loop on exit notification,
we can assume that the sender is always alive

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2019-04-17 08:56:36 +00:00
commit 645a7b77b6
2 changed files with 6 additions and 13 deletions

View File

@ -27,9 +27,7 @@ pub fn stdio_transport() -> (Receiver<RawMessage>, Sender<RawMessage>, Threads)
_ => false, _ => false,
}; };
if let Err(_) = reader_sender.send(msg) { reader_sender.send(msg).unwrap();
break;
}
if is_exit { if is_exit {
break; break;

View File

@ -77,7 +77,7 @@ pub struct Server {
req_id: Cell<u64>, req_id: Cell<u64>,
messages: RefCell<Vec<RawMessage>>, messages: RefCell<Vec<RawMessage>>,
dir: TempDir, dir: TempDir,
worker: Option<Worker<RawMessage, RawMessage>>, worker: Worker<RawMessage, RawMessage>,
} }
impl Server { impl Server {
@ -99,12 +99,7 @@ impl Server {
.unwrap() .unwrap()
}, },
); );
let res = Server { let res = Server { req_id: Cell::new(1), dir, messages: Default::default(), worker };
req_id: Cell::new(1),
dir,
messages: Default::default(),
worker: Some(worker),
};
for (path, text) in files { for (path, text) in files {
res.send_notification(RawNotification::new::<DidOpenTextDocument>( res.send_notification(RawNotification::new::<DidOpenTextDocument>(
@ -157,7 +152,7 @@ impl Server {
} }
fn send_request_(&self, r: RawRequest) -> Value { fn send_request_(&self, r: RawRequest) -> Value {
let id = r.id; 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() { while let Some(msg) = self.recv() {
match msg { match msg {
RawMessage::Request(req) => panic!("unexpected request: {:?}", req), RawMessage::Request(req) => panic!("unexpected request: {:?}", req),
@ -197,13 +192,13 @@ impl Server {
} }
} }
fn recv(&self) -> Option<RawMessage> { fn recv(&self) -> Option<RawMessage> {
recv_timeout(&self.worker.as_ref().unwrap().receiver()).map(|msg| { recv_timeout(&self.worker.receiver()).map(|msg| {
self.messages.borrow_mut().push(msg.clone()); self.messages.borrow_mut().push(msg.clone());
msg msg
}) })
} }
fn send_notification(&self, not: RawNotification) { 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 { pub fn path(&self) -> &Path {