aboutsummaryrefslogtreecommitdiff
path: root/crates/proc_macro_api/src/msg.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/proc_macro_api/src/msg.rs')
-rw-r--r--crates/proc_macro_api/src/msg.rs25
1 files changed, 18 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<()> {