Skip to content

Commit 54f467b

Browse files
committed
Do not require a special env var to be set for the proc-macro-srv
1 parent 648a009 commit 54f467b

File tree

1 file changed

+15
-41
lines changed
  • src/tools/rust-analyzer/crates/proc-macro-srv-cli/src

1 file changed

+15
-41
lines changed

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

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,62 +6,36 @@
66
#[cfg(feature = "in-rust-tree")]
77
extern crate rustc_driver as _;
88

9-
use proc_macro_api::json::{read_json, write_json};
10-
119
use std::io;
1210

1311
fn main() -> std::io::Result<()> {
1412
let v = std::env::var("RUST_ANALYZER_INTERNALS_DO_NOT_USE");
15-
match v.as_deref() {
16-
Ok("this is unstable") => {
17-
// very well, if you must
18-
}
19-
_ => {
20-
eprintln!("If you're rust-analyzer, you can use this tool by exporting RUST_ANALYZER_INTERNALS_DO_NOT_USE='this is unstable'.");
21-
eprintln!("If not, you probably shouldn't use this tool. But do what you want: I'm an error message, not a cop.");
22-
std::process::exit(122);
23-
}
13+
if v.is_err() {
14+
eprintln!("This is an IDE implementation detail, you can use this tool by exporting RUST_ANALYZER_INTERNALS_DO_NOT_USE.");
15+
eprintln!(
16+
"Note that this tool's API is highly unstable and may break without prior notice"
17+
);
18+
std::process::exit(122);
2419
}
2520

2621
run()
2722
}
2823

2924
#[cfg(not(any(feature = "sysroot-abi", rust_analyzer)))]
3025
fn run() -> io::Result<()> {
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 =
36-
|buf: &mut String| msg::Request::read(read_json, &mut io::stdin().lock(), buf);
37-
38-
let write_response = |msg: msg::Response| msg.write(write_json, &mut io::stdout().lock());
39-
40-
let mut buf = String::new();
41-
42-
while let Some(req) = read_request(&mut buf)? {
43-
let res = match req {
44-
msg::Request::ListMacros { .. } => msg::Response::ListMacros(Err(err.to_owned())),
45-
msg::Request::ExpandMacro(_) => {
46-
msg::Response::ExpandMacro(Err(msg::PanicMessage(err.to_owned())))
47-
}
48-
msg::Request::ApiVersionCheck {} => {
49-
msg::Response::ApiVersionCheck(proc_macro_api::msg::CURRENT_API_VERSION)
50-
}
51-
msg::Request::SetConfig(_) => {
52-
msg::Response::SetConfig(proc_macro_api::msg::ServerConfig {
53-
span_mode: msg::SpanMode::Id,
54-
})
55-
}
56-
};
57-
write_response(res)?
58-
}
59-
Ok(())
26+
Err(io::Error::new(
27+
io::ErrorKind::Unsupported,
28+
"proc-macro-srv-cli needs to be compiled with the `sysroot-abi` feature to function"
29+
.to_owned(),
30+
))
6031
}
6132

6233
#[cfg(any(feature = "sysroot-abi", rust_analyzer))]
6334
fn run() -> io::Result<()> {
64-
use proc_macro_api::msg::{self, Message};
35+
use proc_macro_api::{
36+
json::{read_json, write_json},
37+
msg::{self, Message},
38+
};
6539
use proc_macro_srv::EnvSnapshot;
6640

6741
let read_request =

0 commit comments

Comments
 (0)