From 07444976998122ca81dec7cca1f761c5b8b84f79 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 24 Apr 2020 00:06:01 +0800 Subject: [PATCH 1/4] Panic proc macro srv if read request failed --- crates/ra_proc_macro_srv/src/cli.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/ra_proc_macro_srv/src/cli.rs b/crates/ra_proc_macro_srv/src/cli.rs index 5f1f3ba3c7d8..7bfa4312ad98 100644 --- a/crates/ra_proc_macro_srv/src/cli.rs +++ b/crates/ra_proc_macro_srv/src/cli.rs @@ -8,8 +8,9 @@ pub fn run() { loop { let req = match read_request() { Err(err) => { - eprintln!("Read message error on ra_proc_macro_srv: {}", err); - continue; + // Panic here, as the stdin pipe may be closed. + // Otherwise, client will be restart the service anyway. + panic!("Read message error on ra_proc_macro_srv: {}", err); } Ok(None) => continue, Ok(Some(req)) => req, From 25e8f5ded9037bd9a172861c995b467b63390808 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 24 Apr 2020 00:16:17 +0800 Subject: [PATCH 2/4] Fix typo --- crates/ra_proc_macro_srv/src/cli.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ra_proc_macro_srv/src/cli.rs b/crates/ra_proc_macro_srv/src/cli.rs index 7bfa4312ad98..c7f41e4485f3 100644 --- a/crates/ra_proc_macro_srv/src/cli.rs +++ b/crates/ra_proc_macro_srv/src/cli.rs @@ -9,7 +9,7 @@ pub fn run() { let req = match read_request() { Err(err) => { // Panic here, as the stdin pipe may be closed. - // Otherwise, client will be restart the service anyway. + // Otherwise, client will be restarted the service anyway. panic!("Read message error on ra_proc_macro_srv: {}", err); } Ok(None) => continue, From 1627b55028a5e9a4fccad6124bef602d1b55b28b Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 24 Apr 2020 01:38:58 +0800 Subject: [PATCH 3/4] Bubble up error --- crates/ra_proc_macro_srv/src/cli.rs | 15 ++++++--------- crates/rust-analyzer/src/bin/main.rs | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/crates/ra_proc_macro_srv/src/cli.rs b/crates/ra_proc_macro_srv/src/cli.rs index c7f41e4485f3..ded1bcdbcb11 100644 --- a/crates/ra_proc_macro_srv/src/cli.rs +++ b/crates/ra_proc_macro_srv/src/cli.rs @@ -4,16 +4,13 @@ use crate::{expand_task, list_macros}; use ra_proc_macro::msg::{self, Message}; use std::io; -pub fn run() { +pub fn run() -> io::Result<()> { loop { - let req = match read_request() { - Err(err) => { - // Panic here, as the stdin pipe may be closed. - // Otherwise, client will be restarted the service anyway. - panic!("Read message error on ra_proc_macro_srv: {}", err); - } - Ok(None) => continue, - Ok(Some(req)) => req, + // bubble up the error for read request, + // as the stdin pipe may be closed. + let req = match read_request()? { + None => continue, + Some(req) => req, }; let res = match req { diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs index e8d5dad6577c..22a84b50c099 100644 --- a/crates/rust-analyzer/src/bin/main.rs +++ b/crates/rust-analyzer/src/bin/main.rs @@ -66,7 +66,7 @@ fn setup_logging() -> Result<()> { } fn run_proc_macro_srv() -> Result<()> { - ra_proc_macro_srv::cli::run(); + ra_proc_macro_srv::cli::run()?; Ok(()) } From a83d1743a5a753b69c08760e4182878fce3fca08 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 24 Apr 2020 09:27:37 +0800 Subject: [PATCH 4/4] Refactor a bit --- crates/ra_proc_macro_srv/src/cli.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/crates/ra_proc_macro_srv/src/cli.rs b/crates/ra_proc_macro_srv/src/cli.rs index ded1bcdbcb11..7282e5b9b7a9 100644 --- a/crates/ra_proc_macro_srv/src/cli.rs +++ b/crates/ra_proc_macro_srv/src/cli.rs @@ -5,14 +5,7 @@ use ra_proc_macro::msg::{self, Message}; use std::io; pub fn run() -> io::Result<()> { - loop { - // bubble up the error for read request, - // as the stdin pipe may be closed. - let req = match read_request()? { - None => continue, - Some(req) => req, - }; - + while let Some(req) = read_request()? { let res = match req { msg::Request::ListMacro(task) => Ok(msg::Response::ListMacro(list_macros(&task))), msg::Request::ExpansionMacro(task) => { @@ -31,6 +24,8 @@ pub fn run() -> io::Result<()> { eprintln!("Write message error: {}", err); } } + + Ok(()) } fn read_request() -> io::Result> {