From b69bf4896240afd484b744282a8d5c2739059aae Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Thu, 1 Jan 2026 13:39:04 +0530 Subject: [PATCH] add termination flag to procmacroserverprocess --- crates/proc-macro-api/src/process.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/proc-macro-api/src/process.rs b/crates/proc-macro-api/src/process.rs index a206e9fc5d..efb8e0e84a 100644 --- a/crates/proc-macro-api/src/process.rs +++ b/crates/proc-macro-api/src/process.rs @@ -29,6 +29,7 @@ pub(crate) struct ProcMacroServerProcess { protocol: Protocol, /// Populated when the server exits. exited: OnceLock>, + single_use: bool, } impl std::fmt::Debug for ProcMacroServerProcess { @@ -146,6 +147,10 @@ impl ProcMacroWorker for ProcMacroServerProcess { fn get_exited(&self) -> &OnceLock> { &self.exited } + + fn is_reusable(&self) -> bool { + !self.single_use + } } impl ProcMacroServerProcess { @@ -226,6 +231,7 @@ impl ProcMacroServerProcess { } }, exited: OnceLock::new(), + single_use, }) }; let mut srv = create_srv()?; @@ -335,7 +341,7 @@ impl ProcMacroServerProcess { current_dir: String, callback: Option>, ) -> Result, ServerError> { - match self.protocol { + let result = match self.protocol { Protocol::LegacyJson { .. } => legacy_protocol::expand( proc_macro, subtree, @@ -357,6 +363,18 @@ impl ProcMacroServerProcess { current_dir, callback.expect("callback required for bidirectional protocol"), ), + }; + + if self.is_reusable() { + self.terminate(); + } + + result + } + + fn terminate(&self) { + if let Ok(mut state) = self.state.lock() { + let _ = state.process.child.kill(); } } }