|
6 | 6 | #[cfg(feature = "in-rust-tree")] |
7 | 7 | extern crate rustc_driver as _; |
8 | 8 |
|
9 | | -use proc_macro_api::json::{read_json, write_json}; |
10 | | - |
11 | 9 | use std::io; |
12 | 10 |
|
13 | 11 | fn main() -> std::io::Result<()> { |
14 | 12 | 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); |
24 | 19 | } |
25 | 20 |
|
26 | 21 | run() |
27 | 22 | } |
28 | 23 |
|
29 | 24 | #[cfg(not(any(feature = "sysroot-abi", rust_analyzer)))] |
30 | 25 | 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 | + )) |
60 | 31 | } |
61 | 32 |
|
62 | 33 | #[cfg(any(feature = "sysroot-abi", rust_analyzer))] |
63 | 34 | 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 | + }; |
65 | 39 | use proc_macro_srv::EnvSnapshot; |
66 | 40 |
|
67 | 41 | let read_request = |
|
0 commit comments