about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2024-12-13 08:43:33 +0000
committerGitHub <noreply@github.com>2024-12-13 08:43:33 +0000
commit7718173520287b09b5967cacfa3a9a6e3fc88c7c (patch)
tree37449df803f5fdc5b395eb8f4472fdc862162c02 /src/tools
parentc57aec8d5890ba5a67300c62b3bec9eacbd0b023 (diff)
parent54f467b68d95af1d501a068105ee3c552440c2a6 (diff)
downloadrust-7718173520287b09b5967cacfa3a9a6e3fc88c7c.tar.gz
rust-7718173520287b09b5967cacfa3a9a6e3fc88c7c.zip
Merge pull request #18672 from Veykril/push-lurnqpqtzvzq
internal: Do not require a special env var to be set for the proc-macro-srv
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/rust-analyzer/crates/proc-macro-srv-cli/src/main.rs56
1 files changed, 15 insertions, 41 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 7095dac348d..137efd5e7a0 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
@@ -6,21 +6,16 @@
 #[cfg(feature = "in-rust-tree")]
 extern crate rustc_driver as _;
 
-use proc_macro_api::json::{read_json, write_json};
-
 use std::io;
 
 fn main() -> std::io::Result<()> {
     let v = std::env::var("RUST_ANALYZER_INTERNALS_DO_NOT_USE");
-    match v.as_deref() {
-        Ok("this is unstable") => {
-            // very well, if you must
-        }
-        _ => {
-            eprintln!("If you're rust-analyzer, you can use this tool by exporting RUST_ANALYZER_INTERNALS_DO_NOT_USE='this is unstable'.");
-            eprintln!("If not, you probably shouldn't use this tool. But do what you want: I'm an error message, not a cop.");
-            std::process::exit(122);
-        }
+    if v.is_err() {
+        eprintln!("This is an IDE implementation detail, you can use this tool by exporting RUST_ANALYZER_INTERNALS_DO_NOT_USE.");
+        eprintln!(
+            "Note that this tool's API is highly unstable and may break without prior notice"
+        );
+        std::process::exit(122);
     }
 
     run()
@@ -28,40 +23,19 @@ fn main() -> std::io::Result<()> {
 
 #[cfg(not(any(feature = "sysroot-abi", rust_analyzer)))]
 fn run() -> io::Result<()> {
-    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(read_json, &mut io::stdin().lock(), buf);
-
-    let write_response = |msg: msg::Response| msg.write(write_json, &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(proc_macro_api::msg::ServerConfig {
-                    span_mode: msg::SpanMode::Id,
-                })
-            }
-        };
-        write_response(res)?
-    }
-    Ok(())
+    Err(io::Error::new(
+        io::ErrorKind::Unsupported,
+        "proc-macro-srv-cli needs to be compiled with the `sysroot-abi` feature to function"
+            .to_owned(),
+    ))
 }
 
 #[cfg(any(feature = "sysroot-abi", rust_analyzer))]
 fn run() -> io::Result<()> {
-    use proc_macro_api::msg::{self, Message};
+    use proc_macro_api::{
+        json::{read_json, write_json},
+        msg::{self, Message},
+    };
     use proc_macro_srv::EnvSnapshot;
 
     let read_request =