diff --git a/crates/proc-macro-api/src/msg.rs b/crates/proc-macro-api/src/msg.rs index dd882d82fb64..f266050012fd 100644 --- a/crates/proc-macro-api/src/msg.rs +++ b/crates/proc-macro-api/src/msg.rs @@ -17,8 +17,9 @@ pub const NO_VERSION_CHECK_VERSION: u32 = 0; pub const VERSION_CHECK_VERSION: u32 = 1; pub const ENCODE_CLOSE_SPAN_VERSION: u32 = 2; pub const HAS_GLOBAL_SPANS: u32 = 3; +pub const EXPAND_MACRO_RESPONSE_PREFIX: u32 = 4; -pub const CURRENT_API_VERSION: u32 = HAS_GLOBAL_SPANS; +pub const CURRENT_API_VERSION: u32 = EXPAND_MACRO_RESPONSE_PREFIX; #[derive(Debug, Serialize, Deserialize)] pub enum Request { @@ -96,13 +97,21 @@ pub trait Message: Serialize + DeserializeOwned { }) } fn write(self, out: &mut impl Write) -> io::Result<()> { - let text = serde_json::to_string(&self)?; - write_json(out, &text) + write_message_as_json_to(out, self) } } impl Message for Request {} -impl Message for Response {} + +impl Message for Response { + fn write(self, out: &mut impl Write) -> io::Result<()> { + match (&self, std::env::var("RA_EXPAND_MACRO_RESPONSE_PREFIX")) { + (Response::ExpandMacro(..), Ok(prefix)) => out.write_all(prefix.as_bytes())?, + _ => {} + } + write_message_as_json_to(out, self) + } +} fn read_json<'a>(inp: &mut impl BufRead, buf: &'a mut String) -> io::Result> { loop { @@ -126,6 +135,11 @@ fn read_json<'a>(inp: &mut impl BufRead, buf: &'a mut String) -> io::Result io::Result<()> { + let text = serde_json::to_string(&m)?; + write_json(out, &text) +} + fn write_json(out: &mut impl Write, msg: &str) -> io::Result<()> { tracing::debug!("> {}", msg); out.write_all(msg.as_bytes())?;