Skip to content

Commit bf5cad8

Browse files
committed
Auto merge of rust-lang#13326 - Veykril:proc-macro-srv-config, r=Veykril
Do not use the sysroot proc-macro server when a server path is given explicitly
2 parents f88293f + 26cf250 commit bf5cad8

File tree

2 files changed

+44
-33
lines changed

2 files changed

+44
-33
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//! configure the server itself, feature flags are passed into analysis, and
88
//! tweak things like automatic insertion of `()` in completions.
99
10-
use std::{ffi::OsString, fmt, iter, path::PathBuf};
10+
use std::{fmt, iter, path::PathBuf};
1111

1212
use flycheck::FlycheckConfig;
1313
use ide::{
@@ -977,15 +977,17 @@ impl Config {
977977
self.data.lru_capacity
978978
}
979979

980-
pub fn proc_macro_srv(&self) -> Option<(AbsPathBuf, Vec<OsString>)> {
980+
pub fn proc_macro_srv(&self) -> Option<(AbsPathBuf, /* is path explicitly set */ bool)> {
981981
if !self.data.procMacro_enable {
982982
return None;
983983
}
984-
let path = match &self.data.procMacro_server {
985-
Some(it) => self.root_path.join(it),
986-
None => AbsPathBuf::assert(std::env::current_exe().ok()?),
987-
};
988-
Some((path, vec!["proc-macro".into()]))
984+
Some(match &self.data.procMacro_server {
985+
Some(it) => (
986+
AbsPathBuf::try_from(it.clone()).unwrap_or_else(|path| self.root_path.join(path)),
987+
true,
988+
),
989+
None => (AbsPathBuf::assert(std::env::current_exe().ok()?), false),
990+
})
989991
}
990992

991993
pub fn dummy_replacements(&self) -> &FxHashMap<Box<str>, Box<[Box<str>]>> {

crates/rust-analyzer/src/reload.rs

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -306,41 +306,50 @@ impl GlobalState {
306306
format!("rust-analyzer-proc-macro-srv{}", std::env::consts::EXE_SUFFIX);
307307

308308
if self.proc_macro_clients.is_empty() {
309-
if let Some((path, args)) = self.config.proc_macro_srv() {
309+
if let Some((path, path_manually_set)) = self.config.proc_macro_srv() {
310310
tracing::info!("Spawning proc-macro servers");
311311
self.proc_macro_clients = self
312312
.workspaces
313313
.iter()
314314
.map(|ws| {
315-
let mut args = args.clone();
316-
let mut path = path.clone();
317-
318-
if let ProjectWorkspace::Cargo { sysroot, .. }
319-
| ProjectWorkspace::Json { sysroot, .. } = ws
320-
{
321-
tracing::debug!("Found a cargo workspace...");
322-
if let Some(sysroot) = sysroot.as_ref() {
323-
tracing::debug!("Found a cargo workspace with a sysroot...");
324-
let server_path =
325-
sysroot.root().join("libexec").join(&standalone_server_name);
326-
if std::fs::metadata(&server_path).is_ok() {
327-
tracing::debug!(
328-
"And the server exists at {}",
329-
server_path.display()
330-
);
331-
path = server_path;
332-
args = vec![];
333-
} else {
334-
tracing::debug!(
335-
"And the server does not exist at {}",
336-
server_path.display()
337-
);
315+
let (path, args) = if path_manually_set {
316+
tracing::debug!(
317+
"Pro-macro server path explicitly set: {}",
318+
path.display()
319+
);
320+
(path.clone(), vec![])
321+
} else {
322+
let mut sysroot_server = None;
323+
if let ProjectWorkspace::Cargo { sysroot, .. }
324+
| ProjectWorkspace::Json { sysroot, .. } = ws
325+
{
326+
if let Some(sysroot) = sysroot.as_ref() {
327+
let server_path = sysroot
328+
.root()
329+
.join("libexec")
330+
.join(&standalone_server_name);
331+
if std::fs::metadata(&server_path).is_ok() {
332+
tracing::debug!(
333+
"Sysroot proc-macro server exists at {}",
334+
server_path.display()
335+
);
336+
sysroot_server = Some(server_path);
337+
} else {
338+
tracing::debug!(
339+
"Sysroot proc-macro server does not exist at {}",
340+
server_path.display()
341+
);
342+
}
338343
}
339344
}
340-
}
345+
sysroot_server.map_or_else(
346+
|| (path.clone(), vec!["proc-macro".to_owned()]),
347+
|path| (path, vec![]),
348+
)
349+
};
341350

342351
tracing::info!(?args, "Using proc-macro server at {}", path.display(),);
343-
ProcMacroServer::spawn(path.clone(), args.clone()).map_err(|err| {
352+
ProcMacroServer::spawn(path.clone(), args).map_err(|err| {
344353
let error = format!(
345354
"Failed to run proc-macro server from path {}, error: {:?}",
346355
path.display(),

0 commit comments

Comments
 (0)