aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/proc_macro_api/src/msg.rs25
-rw-r--r--crates/rust-analyzer/tests/rust-analyzer/main.rs4
2 files changed, 22 insertions, 7 deletions
diff --git a/crates/proc_macro_api/src/msg.rs b/crates/proc_macro_api/src/msg.rs
index 970f165ed..21e56cc83 100644
--- a/crates/proc_macro_api/src/msg.rs
+++ b/crates/proc_macro_api/src/msg.rs
@@ -77,13 +77,24 @@ impl Message for Request {}
77impl Message for Response {} 77impl Message for Response {}
78 78
79fn read_json(inp: &mut impl BufRead) -> io::Result<Option<String>> { 79fn read_json(inp: &mut impl BufRead) -> io::Result<Option<String>> {
80 let mut buf = String::new(); 80 loop {
81 inp.read_line(&mut buf)?; 81 let mut buf = String::new();
82 buf.pop(); // Remove trailing '\n' 82 inp.read_line(&mut buf)?;
83 Ok(match buf.len() { 83 buf.pop(); // Remove trailing '\n'
84 0 => None, 84
85 _ => Some(buf), 85 if buf.is_empty() {
86 }) 86 return Ok(None);
87 }
88
89 // Some ill behaved macro try to use stdout for debugging
90 // We ignore it here
91 if !buf.starts_with("{") {
92 log::error!("proc-macro tried to print : {}", buf);
93 continue;
94 }
95
96 return Ok(Some(buf));
97 }
87} 98}
88 99
89fn write_json(out: &mut impl Write, msg: &str) -> io::Result<()> { 100fn write_json(out: &mut impl Write, msg: &str) -> io::Result<()> {
diff --git a/crates/rust-analyzer/tests/rust-analyzer/main.rs b/crates/rust-analyzer/tests/rust-analyzer/main.rs
index 19516de7b..4442cbff6 100644
--- a/crates/rust-analyzer/tests/rust-analyzer/main.rs
+++ b/crates/rust-analyzer/tests/rust-analyzer/main.rs
@@ -712,6 +712,10 @@ pub fn foo(_input: TokenStream) -> TokenStream {
712 // We hard code the output here for preventing to use any deps 712 // We hard code the output here for preventing to use any deps
713 let mut res = TokenStream::new(); 713 let mut res = TokenStream::new();
714 714
715 // ill behaved proc-macro will use the stdout
716 // we should ignore it
717 println!("I am bad guy");
718
715 // impl Bar for Foo { fn bar() {} } 719 // impl Bar for Foo { fn bar() {} }
716 let mut tokens = vec![t!("impl"), t!("Bar"), t!("for"), t!("Foo")]; 720 let mut tokens = vec![t!("impl"), t!("Bar"), t!("for"), t!("Foo")];
717 let mut fn_stream = TokenStream::new(); 721 let mut fn_stream = TokenStream::new();