Skip to content

Commit 74a2fad

Browse files
Gate and rename binary, use it if it's in the sysroot
1 parent dadb832 commit 74a2fad

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

crates/proc-macro-api/src/process.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ fn mk_child(
8686
) -> io::Result<Child> {
8787
Command::new(path.as_os_str())
8888
.args(args)
89+
.env("RUST_ANALYZER_INTERNALS_DO_NOT_USE", "this is unstable")
8990
.stdin(Stdio::piped())
9091
.stdout(Stdio::piped())
9192
.stderr(Stdio::inherit())

crates/proc-macro-srv-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ proc-macro-srv = { version = "0.0.0", path = "../proc-macro-srv" }
1313
sysroot-abi = ["proc-macro-srv/sysroot-abi"]
1414

1515
[[bin]]
16-
name = "proc-macro-srv"
16+
name = "rust-analyzer-proc-macro-srv"
1717
path = "src/main.rs"

crates/proc-macro-srv-cli/src/main.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,17 @@
33
use proc_macro_srv::cli;
44

55
fn main() -> std::io::Result<()> {
6+
let v = std::env::var("RUST_ANALYZER_INTERNALS_DO_NOT_USE");
7+
match v.as_deref() {
8+
Ok("this is unstable") => {
9+
// very well, if you must
10+
}
11+
_ => {
12+
eprintln!("If you're rust-analyzer, you can use this tool by exporting RUST_ANALYZER_INTERNALS_DO_NOT_USE='this is unstable'.");
13+
eprintln!("If not, you probably shouldn't use this tool. But do what you want: I'm an error message, not a cop.");
14+
std::process::exit(122);
15+
}
16+
}
17+
618
cli::run()
719
}

crates/rust-analyzer/src/reload.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ impl GlobalState {
309309
.workspaces
310310
.iter()
311311
.map(|ws| {
312+
let mut args = args.clone();
312313
let mut path = path.clone();
314+
313315
if let ProjectWorkspace::Cargo { sysroot, .. } = ws {
314316
tracing::info!("Found a cargo workspace...");
315317
if let Some(sysroot) = sysroot.as_ref() {
@@ -324,6 +326,7 @@ impl GlobalState {
324326
server_path.display()
325327
);
326328
path = server_path;
329+
args = vec![];
327330
} else {
328331
tracing::info!(
329332
"And the server does not exist at {}",
@@ -333,6 +336,11 @@ impl GlobalState {
333336
}
334337
}
335338

339+
tracing::info!(
340+
"Using proc-macro server at {} with args {:?}",
341+
path.display(),
342+
args
343+
);
336344
ProcMacroServer::spawn(path.clone(), args.clone()).map_err(|err| {
337345
let error = format!(
338346
"Failed to run proc_macro_srv from path {}, error: {:?}",

0 commit comments

Comments
 (0)