about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAmos Wenger <amoswenger@gmail.com>2022-07-25 16:22:39 +0200
committerAmos Wenger <amoswenger@gmail.com>2022-07-25 16:22:39 +0200
commit74a2fad5e6b6193842fe52b50ee174736efb266d (patch)
treec5ee04588520e3f28490d4df04f21fe3927827f5
parentdadb83282d7dc7bfb408d93d4953019a328e8e2b (diff)
downloadrust-74a2fad5e6b6193842fe52b50ee174736efb266d.tar.gz
rust-74a2fad5e6b6193842fe52b50ee174736efb266d.zip
Gate and rename binary, use it if it's in the sysroot
-rw-r--r--crates/proc-macro-api/src/process.rs1
-rw-r--r--crates/proc-macro-srv-cli/Cargo.toml2
-rw-r--r--crates/proc-macro-srv-cli/src/main.rs12
-rw-r--r--crates/rust-analyzer/src/reload.rs8
4 files changed, 22 insertions, 1 deletions
diff --git a/crates/proc-macro-api/src/process.rs b/crates/proc-macro-api/src/process.rs
index ff4c59447d8..c4018d3b39e 100644
--- a/crates/proc-macro-api/src/process.rs
+++ b/crates/proc-macro-api/src/process.rs
@@ -86,6 +86,7 @@ fn mk_child(
 ) -> io::Result<Child> {
     Command::new(path.as_os_str())
         .args(args)
+        .env("RUST_ANALYZER_INTERNALS_DO_NOT_USE", "this is unstable")
         .stdin(Stdio::piped())
         .stdout(Stdio::piped())
         .stderr(Stdio::inherit())
diff --git a/crates/proc-macro-srv-cli/Cargo.toml b/crates/proc-macro-srv-cli/Cargo.toml
index badb594f062..9d0da5dee9c 100644
--- a/crates/proc-macro-srv-cli/Cargo.toml
+++ b/crates/proc-macro-srv-cli/Cargo.toml
@@ -13,5 +13,5 @@ proc-macro-srv = { version = "0.0.0", path = "../proc-macro-srv" }
 sysroot-abi = ["proc-macro-srv/sysroot-abi"]
 
 [[bin]]
-name = "proc-macro-srv"
+name = "rust-analyzer-proc-macro-srv"
 path = "src/main.rs"
diff --git a/crates/proc-macro-srv-cli/src/main.rs b/crates/proc-macro-srv-cli/src/main.rs
index 8398f2ba6cb..ac9fa9f5a4c 100644
--- a/crates/proc-macro-srv-cli/src/main.rs
+++ b/crates/proc-macro-srv-cli/src/main.rs
@@ -3,5 +3,17 @@
 use proc_macro_srv::cli;
 
 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);
+        }
+    }
+
     cli::run()
 }
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs
index 4256c2a764a..9ae361b034e 100644
--- a/crates/rust-analyzer/src/reload.rs
+++ b/crates/rust-analyzer/src/reload.rs
@@ -309,7 +309,9 @@ impl GlobalState {
                     .workspaces
                     .iter()
                     .map(|ws| {
+                        let mut args = args.clone();
                         let mut path = path.clone();
+
                         if let ProjectWorkspace::Cargo { sysroot, .. } = ws {
                             tracing::info!("Found a cargo workspace...");
                             if let Some(sysroot) = sysroot.as_ref() {
@@ -324,6 +326,7 @@ impl GlobalState {
                                         server_path.display()
                                     );
                                     path = server_path;
+                                    args = vec![];
                                 } else {
                                     tracing::info!(
                                         "And the server does not exist at {}",
@@ -333,6 +336,11 @@ impl GlobalState {
                             }
                         }
 
+                        tracing::info!(
+                            "Using proc-macro server at {} with args {:?}",
+                            path.display(),
+                            args
+                        );
                         ProcMacroServer::spawn(path.clone(), args.clone()).map_err(|err| {
                             let error = format!(
                                 "Failed to run proc_macro_srv from path {}, error: {:?}",