about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2024-06-30 16:33:30 +0200
committerLukas Wirth <lukastw97@gmail.com>2024-06-30 16:34:06 +0200
commit58286ccbd1760d83c7e2e47a7dfe6604219d29d0 (patch)
treecc6d3b77c8276ad91122b56b8668b1bb8e5bdaff /src
parentf3b3eef221cc5607dfb2ecb2a698a7af9e9f9e93 (diff)
downloadrust-58286ccbd1760d83c7e2e47a7dfe6604219d29d0.tar.gz
rust-58286ccbd1760d83c7e2e47a7dfe6604219d29d0.zip
Actual dummy server for the server cli
Diffstat (limited to 'src')
-rw-r--r--src/tools/rust-analyzer/crates/proc-macro-srv-cli/src/main.rs30
-rw-r--r--src/tools/rust-analyzer/crates/proc-macro-srv/proc-macro-test/build.rs2
2 files changed, 29 insertions, 3 deletions
diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv-cli/src/main.rs b/src/tools/rust-analyzer/crates/proc-macro-srv-cli/src/main.rs
index f9689712ad6..f6f6fdc864b 100644
--- a/src/tools/rust-analyzer/crates/proc-macro-srv-cli/src/main.rs
+++ b/src/tools/rust-analyzer/crates/proc-macro-srv-cli/src/main.rs
@@ -8,6 +8,8 @@ extern crate rustc_driver as _;
 
 use std::io;
 
+use proc_macro_api::msg::ServerConfig;
+
 fn main() -> std::io::Result<()> {
     let v = std::env::var("RUST_ANALYZER_INTERNALS_DO_NOT_USE");
     match v.as_deref() {
@@ -26,8 +28,32 @@ fn main() -> std::io::Result<()> {
 
 #[cfg(not(any(feature = "sysroot-abi", rust_analyzer)))]
 fn run() -> io::Result<()> {
-    eprintln!("proc-macro-srv-cli requires the `sysroot-abi` feature to be enabled");
-    std::process::exit(70);
+    let err = "proc-macro-srv-cli needs to be compiled with the `sysroot-abi` feature to function";
+    eprintln!("{err}");
+    use proc_macro_api::msg::{self, Message};
+
+    let read_request = |buf: &mut String| msg::Request::read(&mut io::stdin().lock(), buf);
+
+    let write_response = |msg: msg::Response| msg.write(&mut io::stdout().lock());
+
+    let mut buf = String::new();
+
+    while let Some(req) = read_request(&mut buf)? {
+        let res = match req {
+            msg::Request::ListMacros { .. } => msg::Response::ListMacros(Err(err.to_owned())),
+            msg::Request::ExpandMacro(_) => {
+                msg::Response::ExpandMacro(Err(msg::PanicMessage(err.to_owned())))
+            }
+            msg::Request::ApiVersionCheck {} => {
+                msg::Response::ApiVersionCheck(proc_macro_api::msg::CURRENT_API_VERSION)
+            }
+            msg::Request::SetConfig(_) => {
+                msg::Response::SetConfig(ServerConfig { span_mode: msg::SpanMode::Id })
+            }
+        };
+        write_response(res)?
+    }
+    Ok(())
 }
 
 #[cfg(any(feature = "sysroot-abi", rust_analyzer))]
diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv/proc-macro-test/build.rs b/src/tools/rust-analyzer/crates/proc-macro-srv/proc-macro-test/build.rs
index dd4709a1f75..ff2f5d18639 100644
--- a/src/tools/rust-analyzer/crates/proc-macro-srv/proc-macro-test/build.rs
+++ b/src/tools/rust-analyzer/crates/proc-macro-srv/proc-macro-test/build.rs
@@ -8,7 +8,7 @@
 //! 1.58) and future ABIs (stage1, nightly)
 
 use std::{
-    env, fs,
+    env,
     path::{Path, PathBuf},
     process::Command,
 };