mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-19 11:12:43 +00:00
Breaks read loop on 'exit'
This commit is contained in:
parent
13d92b3f11
commit
8d569d49d2
@ -22,7 +22,7 @@
|
||||
//! sender,
|
||||
//! main_loop,
|
||||
//! )?;
|
||||
//! io_threads.exit()?;
|
||||
//! io_threads.join()?;
|
||||
//! Ok(())
|
||||
//! }
|
||||
//!
|
||||
|
@ -5,6 +5,7 @@ use std::{
|
||||
|
||||
use crossbeam_channel::{bounded, Receiver, Sender};
|
||||
use failure::bail;
|
||||
use lsp_types::notification::Exit;
|
||||
|
||||
use crate::{RawMessage, Result};
|
||||
|
||||
@ -21,9 +22,18 @@ pub fn stdio_transport() -> (Receiver<RawMessage>, Sender<RawMessage>, Threads)
|
||||
let stdin = stdin();
|
||||
let mut stdin = stdin.lock();
|
||||
while let Some(msg) = RawMessage::read(&mut stdin)? {
|
||||
let is_exit = match &msg {
|
||||
RawMessage::Notification(n) => n.is::<Exit>(),
|
||||
_ => false,
|
||||
};
|
||||
|
||||
if let Err(_) = reader_sender.send(msg) {
|
||||
break;
|
||||
}
|
||||
|
||||
if is_exit {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
});
|
||||
@ -37,9 +47,11 @@ pub struct Threads {
|
||||
}
|
||||
|
||||
impl Threads {
|
||||
pub fn exit(self) -> Result<()> {
|
||||
// We can't rely on stdin being closed
|
||||
drop(self.reader);
|
||||
pub fn join(self) -> Result<()> {
|
||||
match self.reader.join() {
|
||||
Ok(r) => r?,
|
||||
Err(_) => bail!("reader panicked"),
|
||||
}
|
||||
match self.writer.join() {
|
||||
Ok(r) => r,
|
||||
Err(_) => bail!("writer panicked"),
|
||||
|
@ -54,7 +54,7 @@ fn main_inner() -> Result<()> {
|
||||
ra_lsp_server::main_loop(workspace_roots, opts, r, s)
|
||||
})?;
|
||||
log::info!("shutting down IO...");
|
||||
threads.exit()?;
|
||||
threads.join()?;
|
||||
log::info!("... IO is down");
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user