aboutsummaryrefslogtreecommitdiff
path: root/crates/gen_lsp_server/src
diff options
context:
space:
mode:
authorRoberto Vidal <[email protected]>2019-04-16 23:32:33 +0100
committerRoberto Vidal <[email protected]>2019-04-16 23:38:56 +0100
commit8d569d49d2508cd7b50dd3d00d5509d4128bf645 (patch)
treefa681e23a67dcaf25a52be11272a2ecf6d9b54bf /crates/gen_lsp_server/src
parent13d92b3f11246dc2d9a26b7d06ad8ebbcb96c47d (diff)
Breaks read loop on 'exit'
Diffstat (limited to 'crates/gen_lsp_server/src')
-rw-r--r--crates/gen_lsp_server/src/lib.rs2
-rw-r--r--crates/gen_lsp_server/src/stdio.rs18
2 files changed, 16 insertions, 4 deletions
diff --git a/crates/gen_lsp_server/src/lib.rs b/crates/gen_lsp_server/src/lib.rs
index 86b72f663..edbdda6c8 100644
--- a/crates/gen_lsp_server/src/lib.rs
+++ b/crates/gen_lsp_server/src/lib.rs
@@ -22,7 +22,7 @@
22//! sender, 22//! sender,
23//! main_loop, 23//! main_loop,
24//! )?; 24//! )?;
25//! io_threads.exit()?; 25//! io_threads.join()?;
26//! Ok(()) 26//! Ok(())
27//! } 27//! }
28//! 28//!
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"),