From 5761b50ed899ca9c9ba9cab672d30b68725b3c18 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 22 Dec 2023 10:35:10 +0100 Subject: [PATCH] More general server config message for proc-macro-api --- crates/proc-macro-api/src/msg.rs | 10 ++++++++-- crates/proc-macro-api/src/process.rs | 6 ++++-- crates/proc-macro-srv-cli/src/main.rs | 6 +++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/crates/proc-macro-api/src/msg.rs b/crates/proc-macro-api/src/msg.rs index c8faa88e09b..557ddba5c78 100644 --- a/crates/proc-macro-api/src/msg.rs +++ b/crates/proc-macro-api/src/msg.rs @@ -33,7 +33,7 @@ pub enum Request { /// Since [`VERSION_CHECK_VERSION`] ApiVersionCheck {}, /// Since [`RUST_ANALYZER_SPAN_SUPPORT`] - SetSpanMode(SpanMode), + SetConfig(ServerConfig), } #[derive(Copy, Clone, Default, Debug, Serialize, Deserialize)] @@ -52,11 +52,17 @@ pub enum Response { /// Since [`NO_VERSION_CHECK_VERSION`] ApiVersionCheck(u32), /// Since [`RUST_ANALYZER_SPAN_SUPPORT`] - SetSpanMode(SpanMode), + SetConfig(ServerConfig), /// Since [`RUST_ANALYZER_SPAN_SUPPORT`] ExpandMacroExtended(Result), } +#[derive(Debug, Serialize, Deserialize, Default)] +#[serde(default)] +pub struct ServerConfig { + pub span_mode: SpanMode, +} + #[derive(Debug, Serialize, Deserialize)] pub struct ExpandMacroExtended { pub tree: FlatTree, diff --git a/crates/proc-macro-api/src/process.rs b/crates/proc-macro-api/src/process.rs index ed55ca5bd53..3494164c067 100644 --- a/crates/proc-macro-api/src/process.rs +++ b/crates/proc-macro-api/src/process.rs @@ -79,11 +79,13 @@ impl ProcMacroProcessSrv { } fn enable_rust_analyzer_spans(&mut self) -> Result { - let request = Request::SetSpanMode(crate::msg::SpanMode::RustAnalyzer); + let request = Request::SetConfig(crate::msg::ServerConfig { + span_mode: crate::msg::SpanMode::RustAnalyzer, + }); let response = self.send_task(request)?; match response { - Response::SetSpanMode(span_mode) => Ok(span_mode), + Response::SetConfig(crate::msg::ServerConfig { span_mode }) => Ok(span_mode), _ => Err(ServerError { message: "unexpected response".to_string(), io: None }), } } diff --git a/crates/proc-macro-srv-cli/src/main.rs b/crates/proc-macro-srv-cli/src/main.rs index 52882d83457..000a526e9f9 100644 --- a/crates/proc-macro-srv-cli/src/main.rs +++ b/crates/proc-macro-srv-cli/src/main.rs @@ -51,9 +51,9 @@ fn run() -> io::Result<()> { msg::Request::ApiVersionCheck {} => { msg::Response::ApiVersionCheck(proc_macro_api::msg::CURRENT_API_VERSION) } - msg::Request::SetSpanMode(span_mode) => { - srv.set_span_mode(span_mode); - msg::Response::SetSpanMode(span_mode) + msg::Request::SetConfig(config) => { + srv.set_span_mode(config.span_mode); + msg::Response::SetConfig(config) } }; write_response(res)?