Unnamed repository; edit this file 'description' to name the repository.
remove request_id, rename postcardNew to BidirectionalPostcardPrototype and remove JsonNew
| -rw-r--r-- | crates/proc-macro-api/src/bidirectional_protocol.rs | 20 | ||||
| -rw-r--r-- | crates/proc-macro-api/src/bidirectional_protocol/msg.rs | 9 | ||||
| -rw-r--r-- | crates/proc-macro-api/src/process.rs | 32 | ||||
| -rw-r--r-- | crates/proc-macro-srv-cli/src/main.rs | 6 | ||||
| -rw-r--r-- | crates/proc-macro-srv-cli/src/main_loop.rs | 22 |
5 files changed, 20 insertions, 69 deletions
diff --git a/crates/proc-macro-api/src/bidirectional_protocol.rs b/crates/proc-macro-api/src/bidirectional_protocol.rs index 728f0f707d..c7caccb96f 100644 --- a/crates/proc-macro-api/src/bidirectional_protocol.rs +++ b/crates/proc-macro-api/src/bidirectional_protocol.rs @@ -12,7 +12,7 @@ use span::{FileId, Span}; use crate::{ Codec, ProcMacro, ProcMacroKind, ServerError, bidirectional_protocol::msg::{ - Envelope, ExpandMacro, ExpandMacroData, ExpnGlobals, Kind, Payload, Request, RequestId, + Envelope, ExpandMacro, ExpandMacroData, ExpnGlobals, Kind, Payload, Request, Response, SubRequest, SubResponse, }, legacy_protocol::{ @@ -37,11 +37,10 @@ pub fn run_conversation<C: Codec>( writer: &mut dyn Write, reader: &mut dyn BufRead, buf: &mut C::Buf, - id: RequestId, initial: Payload, callbacks: &mut dyn ClientCallbacks, ) -> Result<Payload, ServerError> { - let msg = Envelope { id, kind: Kind::Request, payload: initial }; + let msg = Envelope { kind: Kind::Request, payload: initial }; let encoded = C::encode(&msg).map_err(wrap_encode)?; C::write(writer, &encoded).map_err(wrap_io("failed to write initial request"))?; @@ -56,18 +55,11 @@ pub fn run_conversation<C: Codec>( let msg: Envelope = C::decode(b).map_err(wrap_decode)?; - if msg.id != id { - return Err(ServerError { - message: format!("unexpected message id {}, expected {}", msg.id, id), - io: None, - }); - } - match (msg.kind, msg.payload) { (Kind::SubRequest, Payload::SubRequest(sr)) => { let resp = callbacks.handle_sub_request(sr)?; let reply = - Envelope { id, kind: Kind::SubResponse, payload: Payload::SubResponse(resp) }; + Envelope { kind: Kind::SubResponse, payload: Payload::SubResponse(resp) }; let encoded = C::encode(&reply).map_err(wrap_encode)?; C::write(writer, &encoded).map_err(wrap_io("failed to write sub-response"))?; } @@ -268,11 +260,9 @@ fn run_request( return Err(server_error.clone()); } - let id = srv.request_id(); - if srv.use_postcard() { - srv.run_bidirectional::<PostcardProtocol>(id, msg, callbacks) + srv.run_bidirectional::<PostcardProtocol>(msg, callbacks) } else { - srv.run_bidirectional::<JsonProtocol>(id, msg, callbacks) + srv.run_bidirectional::<JsonProtocol>(msg, callbacks) } } diff --git a/crates/proc-macro-api/src/bidirectional_protocol/msg.rs b/crates/proc-macro-api/src/bidirectional_protocol/msg.rs index 796573385c..4f81ef4ae6 100644 --- a/crates/proc-macro-api/src/bidirectional_protocol/msg.rs +++ b/crates/proc-macro-api/src/bidirectional_protocol/msg.rs @@ -8,21 +8,12 @@ use crate::{ legacy_protocol::msg::{FlatTree, Message, PanicMessage, ServerConfig}, }; -pub type RequestId = u32; - #[derive(Debug, Serialize, Deserialize)] pub struct Envelope { - pub id: RequestId, pub kind: Kind, pub payload: Payload, } -impl From<(RequestId, Kind, Payload)> for Envelope { - fn from(value: (RequestId, Kind, Payload)) -> Self { - Envelope { id: value.0, kind: value.1, payload: value.2 } - } -} - #[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)] pub enum Kind { Request, diff --git a/crates/proc-macro-api/src/process.rs b/crates/proc-macro-api/src/process.rs index bb4599c532..1c1709e5fa 100644 --- a/crates/proc-macro-api/src/process.rs +++ b/crates/proc-macro-api/src/process.rs @@ -6,7 +6,6 @@ use std::{ process::{Child, ChildStdin, ChildStdout, Command, Stdio}, sync::{ Arc, Mutex, OnceLock, - atomic::{AtomicU32, Ordering}, }, }; @@ -20,7 +19,7 @@ use crate::{ Codec, ProcMacro, ProcMacroKind, ServerError, bidirectional_protocol::{ self, ClientCallbacks, - msg::{Payload, RequestId}, + msg::Payload, }, legacy_protocol::{self, SpanMode}, version, @@ -36,15 +35,13 @@ pub(crate) struct ProcMacroServerProcess { protocol: Protocol, /// Populated when the server exits. exited: OnceLock<AssertUnwindSafe<ServerError>>, - next_request_id: AtomicU32, } #[derive(Debug, Clone)] pub(crate) enum Protocol { LegacyJson { mode: SpanMode }, LegacyPostcard { mode: SpanMode }, - NewPostcard { mode: SpanMode }, - NewJson { mode: SpanMode }, + BidirectionalPostcardPrototype { mode: SpanMode }, } /// Maintains the state of the proc-macro server process. @@ -74,8 +71,7 @@ impl ProcMacroServerProcess { && has_working_format_flag { &[ - (Some("postcard-new"), Protocol::NewPostcard { mode: SpanMode::Id }), - (Some("json-new"), Protocol::NewJson { mode: SpanMode::Id }), + (Some("postcard-new"), Protocol::BidirectionalPostcardPrototype { mode: SpanMode::Id }), (Some("postcard-legacy"), Protocol::LegacyPostcard { mode: SpanMode::Id }), (Some("json-legacy"), Protocol::LegacyJson { mode: SpanMode::Id }), ] @@ -94,7 +90,6 @@ impl ProcMacroServerProcess { version: 0, protocol: protocol.clone(), exited: OnceLock::new(), - next_request_id: AtomicU32::new(1), }) }; let mut srv = create_srv()?; @@ -122,8 +117,7 @@ impl ProcMacroServerProcess { match &mut srv.protocol { Protocol::LegacyJson { mode } | Protocol::LegacyPostcard { mode } - | Protocol::NewJson { mode } - | Protocol::NewPostcard { mode } => *mode = new_mode, + | Protocol::BidirectionalPostcardPrototype { mode } => *mode = new_mode, } } tracing::info!("Proc-macro server protocol: {:?}", srv.protocol); @@ -159,8 +153,7 @@ impl ProcMacroServerProcess { match self.protocol { Protocol::LegacyJson { mode } => mode == SpanMode::RustAnalyzer, Protocol::LegacyPostcard { mode } => mode == SpanMode::RustAnalyzer, - Protocol::NewJson { mode } => mode == SpanMode::RustAnalyzer, - Protocol::NewPostcard { mode } => mode == SpanMode::RustAnalyzer, + Protocol::BidirectionalPostcardPrototype { mode } => mode == SpanMode::RustAnalyzer, } } @@ -170,7 +163,7 @@ impl ProcMacroServerProcess { Protocol::LegacyJson { .. } | Protocol::LegacyPostcard { .. } => { legacy_protocol::version_check(self) } - Protocol::NewJson { .. } | Protocol::NewPostcard { .. } => { + Protocol::BidirectionalPostcardPrototype { .. } => { bidirectional_protocol::version_check(self) } } @@ -182,7 +175,7 @@ impl ProcMacroServerProcess { Protocol::LegacyJson { .. } | Protocol::LegacyPostcard { .. } => { legacy_protocol::enable_rust_analyzer_spans(self) } - Protocol::NewJson { .. } | Protocol::NewPostcard { .. } => { + Protocol::BidirectionalPostcardPrototype { .. } => { bidirectional_protocol::enable_rust_analyzer_spans(self) } } @@ -197,7 +190,7 @@ impl ProcMacroServerProcess { Protocol::LegacyJson { .. } | Protocol::LegacyPostcard { .. } => { legacy_protocol::find_proc_macros(self, dylib_path) } - Protocol::NewJson { .. } | Protocol::NewPostcard { .. } => { + Protocol::BidirectionalPostcardPrototype { .. } => { bidirectional_protocol::find_proc_macros(self, dylib_path) } } @@ -229,7 +222,7 @@ impl ProcMacroServerProcess { current_dir, ) } - Protocol::NewJson { .. } | Protocol::NewPostcard { .. } => { + Protocol::BidirectionalPostcardPrototype { .. } => { bidirectional_protocol::expand( proc_macro, db, @@ -307,20 +300,15 @@ impl ProcMacroServerProcess { pub(crate) fn run_bidirectional<C: Codec>( &self, - id: RequestId, initial: Payload, callbacks: &mut dyn ClientCallbacks, ) -> Result<Payload, ServerError> { self.with_locked_io::<C, _>(|writer, reader, buf| { bidirectional_protocol::run_conversation::<C>( - writer, reader, buf, id, initial, callbacks, + writer, reader, buf, initial, callbacks, ) }) } - - pub(crate) fn request_id(&self) -> RequestId { - self.next_request_id.fetch_add(1, Ordering::Relaxed) - } } /// Manages the execution of the proc-macro server process. diff --git a/crates/proc-macro-srv-cli/src/main.rs b/crates/proc-macro-srv-cli/src/main.rs index c9134b402d..53302dd579 100644 --- a/crates/proc-macro-srv-cli/src/main.rs +++ b/crates/proc-macro-srv-cli/src/main.rs @@ -31,7 +31,7 @@ fn main() -> std::io::Result<()> { clap::Arg::new("format") .long("format") .action(clap::ArgAction::Set) - .default_value("json-new") + .default_value("postcard-new") .value_parser(clap::builder::EnumValueParser::<ProtocolFormat>::new()), clap::Arg::new("version") .long("version") @@ -52,7 +52,6 @@ fn main() -> std::io::Result<()> { enum ProtocolFormat { JsonLegacy, PostcardLegacy, - JsonNew, PostcardNew, } @@ -61,7 +60,6 @@ impl ValueEnum for ProtocolFormat { &[ ProtocolFormat::JsonLegacy, ProtocolFormat::PostcardLegacy, - ProtocolFormat::JsonNew, ProtocolFormat::PostcardNew, ] } @@ -72,7 +70,6 @@ impl ValueEnum for ProtocolFormat { ProtocolFormat::PostcardLegacy => { Some(clap::builder::PossibleValue::new("postcard-legacy")) } - ProtocolFormat::JsonNew => Some(clap::builder::PossibleValue::new("json-new")), ProtocolFormat::PostcardNew => Some(clap::builder::PossibleValue::new("postcard-new")), } } @@ -81,7 +78,6 @@ impl ValueEnum for ProtocolFormat { "json-legacy" => Ok(ProtocolFormat::JsonLegacy), "postcard-legacy" => Ok(ProtocolFormat::PostcardLegacy), "postcard-new" => Ok(ProtocolFormat::PostcardNew), - "json-new" => Ok(ProtocolFormat::JsonNew), _ => Err(format!("unknown protocol format: {input}")), } } diff --git a/crates/proc-macro-srv-cli/src/main_loop.rs b/crates/proc-macro-srv-cli/src/main_loop.rs index dc828a87de..ee9b208811 100644 --- a/crates/proc-macro-srv-cli/src/main_loop.rs +++ b/crates/proc-macro-srv-cli/src/main_loop.rs @@ -10,7 +10,6 @@ use proc_macro_api::{ version::CURRENT_API_VERSION, }; -use bidirectional::RequestId; use legacy::Message; use proc_macro_srv::{EnvSnapshot, SpanId}; @@ -39,7 +38,6 @@ pub(crate) fn run(format: ProtocolFormat) -> io::Result<()> { match format { ProtocolFormat::JsonLegacy => run_::<JsonProtocol>(), ProtocolFormat::PostcardLegacy => run_::<PostcardProtocol>(), - ProtocolFormat::JsonNew => run_new::<JsonProtocol>(), ProtocolFormat::PostcardNew => run_new::<PostcardProtocol>(), } } @@ -83,7 +81,6 @@ fn run_new<C: Codec>() -> io::Result<()> { send_response::<_, C>( &mut stdout, - req.id, bidirectional::Response::ListMacros(res), )?; } @@ -91,7 +88,6 @@ fn run_new<C: Codec>() -> io::Result<()> { bidirectional::Request::ApiVersionCheck {} => { send_response::<_, C>( &mut stdout, - req.id, bidirectional::Response::ApiVersionCheck(CURRENT_API_VERSION), )?; } @@ -100,7 +96,6 @@ fn run_new<C: Codec>() -> io::Result<()> { span_mode = config.span_mode; send_response::<_, C>( &mut stdout, - req.id, bidirectional::Response::SetConfig(config), )?; } @@ -110,7 +105,6 @@ fn run_new<C: Codec>() -> io::Result<()> { &mut stdin, &mut stdout, &mut buf, - req.id, span_mode, *task, )?; @@ -129,14 +123,13 @@ fn handle_expand<W: std::io::Write, R: std::io::BufRead, C: Codec>( stdin: &mut R, stdout: &mut W, buf: &mut C::Buf, - req_id: RequestId, span_mode: legacy::SpanMode, task: bidirectional::ExpandMacro, ) -> io::Result<()> { match span_mode { - legacy::SpanMode::Id => handle_expand_id::<_, C>(srv, stdout, req_id, task), + legacy::SpanMode::Id => handle_expand_id::<_, C>(srv, stdout, task), legacy::SpanMode::RustAnalyzer => { - handle_expand_ra::<_, _, C>(srv, stdin, stdout, buf, req_id, task) + handle_expand_ra::<_, _, C>(srv, stdin, stdout, buf, task) } } } @@ -144,7 +137,6 @@ fn handle_expand<W: std::io::Write, R: std::io::BufRead, C: Codec>( fn handle_expand_id<W: std::io::Write, C: Codec>( srv: &proc_macro_srv::ProcMacroSrv<'_>, stdout: &mut W, - req_id: RequestId, task: bidirectional::ExpandMacro, ) -> io::Result<()> { let bidirectional::ExpandMacro { lib, env, current_dir, data } = task; @@ -182,7 +174,7 @@ fn handle_expand_id<W: std::io::Write, C: Codec>( }) .map_err(|e| legacy::PanicMessage(e.into_string().unwrap_or_default())); - send_response::<_, C>(stdout, req_id, bidirectional::Response::ExpandMacro(res)) + send_response::<_, C>(stdout, bidirectional::Response::ExpandMacro(res)) } fn handle_expand_ra<W: std::io::Write, R: std::io::BufRead, C: Codec>( @@ -190,7 +182,6 @@ fn handle_expand_ra<W: std::io::Write, R: std::io::BufRead, C: Codec>( stdin: &mut R, stdout: &mut W, buf: &mut C::Buf, - req_id: RequestId, task: bidirectional::ExpandMacro, ) -> io::Result<()> { let bidirectional::ExpandMacro { @@ -276,7 +267,6 @@ fn handle_expand_ra<W: std::io::Write, R: std::io::BufRead, C: Codec>( if let Ok(res) = result_rx.try_recv() { send_response::<_, C>( stdout, - req_id, bidirectional::Response::ExpandMacroExtended(res), ) .unwrap(); @@ -290,7 +280,7 @@ fn handle_expand_ra<W: std::io::Write, R: std::io::BufRead, C: Codec>( } }; - send_subrequest::<_, C>(stdout, req_id, from_srv_req(subreq)).unwrap(); + send_subrequest::<_, C>(stdout, from_srv_req(subreq)).unwrap(); let resp_opt = bidirectional::Envelope::read::<_, C>(stdin, buf).unwrap(); let resp = match resp_opt { @@ -474,11 +464,9 @@ fn from_client_res(value: bidirectional::SubResponse) -> proc_macro_srv::SubResp fn send_response<W: std::io::Write, C: Codec>( stdout: &mut W, - id: u32, resp: bidirectional::Response, ) -> io::Result<()> { let resp = bidirectional::Envelope { - id, kind: bidirectional::Kind::Response, payload: bidirectional::Payload::Response(resp), }; @@ -487,11 +475,9 @@ fn send_response<W: std::io::Write, C: Codec>( fn send_subrequest<W: std::io::Write, C: Codec>( stdout: &mut W, - id: u32, resp: bidirectional::SubRequest, ) -> io::Result<()> { let resp = bidirectional::Envelope { - id, kind: bidirectional::Kind::SubRequest, payload: bidirectional::Payload::SubRequest(resp), }; |