Skip to content

Commit 58286cc

Browse files
committed
Actual dummy server for the server cli
1 parent f3b3eef commit 58286cc

File tree

2 files changed

+29
-3
lines changed
  • src/tools/rust-analyzer/crates

2 files changed

+29
-3
lines changed

src/tools/rust-analyzer/crates/proc-macro-srv-cli/src/main.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ extern crate rustc_driver as _;
88

99
use std::io;
1010

11+
use proc_macro_api::msg::ServerConfig;
12+
1113
fn main() -> std::io::Result<()> {
1214
let v = std::env::var("RUST_ANALYZER_INTERNALS_DO_NOT_USE");
1315
match v.as_deref() {
@@ -26,8 +28,32 @@ fn main() -> std::io::Result<()> {
2628

2729
#[cfg(not(any(feature = "sysroot-abi", rust_analyzer)))]
2830
fn run() -> io::Result<()> {
29-
eprintln!("proc-macro-srv-cli requires the `sysroot-abi` feature to be enabled");
30-
std::process::exit(70);
31+
let err = "proc-macro-srv-cli needs to be compiled with the `sysroot-abi` feature to function";
32+
eprintln!("{err}");
33+
use proc_macro_api::msg::{self, Message};
34+
35+
let read_request = |buf: &mut String| msg::Request::read(&mut io::stdin().lock(), buf);
36+
37+
let write_response = |msg: msg::Response| msg.write(&mut io::stdout().lock());
38+
39+
let mut buf = String::new();
40+
41+
while let Some(req) = read_request(&mut buf)? {
42+
let res = match req {
43+
msg::Request::ListMacros { .. } => msg::Response::ListMacros(Err(err.to_owned())),
44+
msg::Request::ExpandMacro(_) => {
45+
msg::Response::ExpandMacro(Err(msg::PanicMessage(err.to_owned())))
46+
}
47+
msg::Request::ApiVersionCheck {} => {
48+
msg::Response::ApiVersionCheck(proc_macro_api::msg::CURRENT_API_VERSION)
49+
}
50+
msg::Request::SetConfig(_) => {
51+
msg::Response::SetConfig(ServerConfig { span_mode: msg::SpanMode::Id })
52+
}
53+
};
54+
write_response(res)?
55+
}
56+
Ok(())
3157
}
3258

3359
#[cfg(any(feature = "sysroot-abi", rust_analyzer))]

src/tools/rust-analyzer/crates/proc-macro-srv/proc-macro-test/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//! 1.58) and future ABIs (stage1, nightly)
99
1010
use std::{
11-
env, fs,
11+
env,
1212
path::{Path, PathBuf},
1313
process::Command,
1414
};

0 commit comments

Comments
 (0)