aboutsummaryrefslogtreecommitdiff
path: root/crates/gen_lsp_server/src/stdio.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/gen_lsp_server/src/stdio.rs')
-rw-r--r--crates/gen_lsp_server/src/stdio.rs18
1 files changed, 15 insertions, 3 deletions
diff --git a/crates/gen_lsp_server/src/stdio.rs b/crates/gen_lsp_server/src/stdio.rs
index c5fe5b83a..5edfbc39c 100644
--- a/crates/gen_lsp_server/src/stdio.rs
+++ b/crates/gen_lsp_server/src/stdio.rs
@@ -5,6 +5,7 @@ use std::{
5 5
6use crossbeam_channel::{bounded, Receiver, Sender}; 6use crossbeam_channel::{bounded, Receiver, Sender};
7use failure::bail; 7use failure::bail;
8use lsp_types::notification::Exit;
8 9
9use crate::{RawMessage, Result}; 10use crate::{RawMessage, Result};
10 11
@@ -21,9 +22,18 @@ pub fn stdio_transport() -> (Receiver<RawMessage>, Sender<RawMessage>, Threads)
21 let stdin = stdin(); 22 let stdin = stdin();
22 let mut stdin = stdin.lock(); 23 let mut stdin = stdin.lock();
23 while let Some(msg) = RawMessage::read(&mut stdin)? { 24 while let Some(msg) = RawMessage::read(&mut stdin)? {
25 let is_exit = match &msg {
26 RawMessage::Notification(n) => n.is::<Exit>(),
27 _ => false,
28 };
29
24 if let Err(_) = reader_sender.send(msg) { 30 if let Err(_) = reader_sender.send(msg) {
25 break; 31 break;
26 } 32 }
33
34 if is_exit {
35 break;
36 }
27 } 37 }
28 Ok(()) 38 Ok(())
29 }); 39 });
@@ -37,9 +47,11 @@ pub struct Threads {
37} 47}
38 48
39impl Threads { 49impl Threads {
40 pub fn exit(self) -> Result<()> { 50 pub fn join(self) -> Result<()> {
41 // We can't rely on stdin being closed 51 match self.reader.join() {
42 drop(self.reader); 52 Ok(r) => r?,
53 Err(_) => bail!("reader panicked"),
54 }
43 match self.writer.join() { 55 match self.writer.join() {
44 Ok(r) => r, 56 Ok(r) => r,
45 Err(_) => bail!("writer panicked"), 57 Err(_) => bail!("writer panicked"),