Do not use the sysroot proc-macro server when a server path is given explicitly

This commit is contained in:
Lukas Wirth 2022-10-01 19:50:34 +02:00
parent 39eaf7864c
commit 26cf250ccc
2 changed files with 44 additions and 33 deletions

View file

@ -7,7 +7,7 @@
//! configure the server itself, feature flags are passed into analysis, and //! configure the server itself, feature flags are passed into analysis, and
//! tweak things like automatic insertion of `()` in completions. //! tweak things like automatic insertion of `()` in completions.
use std::{ffi::OsString, fmt, iter, path::PathBuf}; use std::{fmt, iter, path::PathBuf};
use flycheck::FlycheckConfig; use flycheck::FlycheckConfig;
use ide::{ use ide::{
@ -975,15 +975,17 @@ impl Config {
self.data.lru_capacity self.data.lru_capacity
} }
pub fn proc_macro_srv(&self) -> Option<(AbsPathBuf, Vec<OsString>)> { pub fn proc_macro_srv(&self) -> Option<(AbsPathBuf, /* is path explicitly set */ bool)> {
if !self.data.procMacro_enable { if !self.data.procMacro_enable {
return None; return None;
} }
let path = match &self.data.procMacro_server { Some(match &self.data.procMacro_server {
Some(it) => self.root_path.join(it), Some(it) => (
None => AbsPathBuf::assert(std::env::current_exe().ok()?), AbsPathBuf::try_from(it.clone()).unwrap_or_else(|path| self.root_path.join(path)),
}; true,
Some((path, vec!["proc-macro".into()])) ),
None => (AbsPathBuf::assert(std::env::current_exe().ok()?), false),
})
} }
pub fn dummy_replacements(&self) -> &FxHashMap<Box<str>, Box<[Box<str>]>> { pub fn dummy_replacements(&self) -> &FxHashMap<Box<str>, Box<[Box<str>]>> {

View file

@ -306,41 +306,50 @@ impl GlobalState {
format!("rust-analyzer-proc-macro-srv{}", std::env::consts::EXE_SUFFIX); format!("rust-analyzer-proc-macro-srv{}", std::env::consts::EXE_SUFFIX);
if self.proc_macro_clients.is_empty() { if self.proc_macro_clients.is_empty() {
if let Some((path, args)) = self.config.proc_macro_srv() { if let Some((path, path_manually_set)) = self.config.proc_macro_srv() {
tracing::info!("Spawning proc-macro servers"); tracing::info!("Spawning proc-macro servers");
self.proc_macro_clients = self self.proc_macro_clients = self
.workspaces .workspaces
.iter() .iter()
.map(|ws| { .map(|ws| {
let mut args = args.clone(); let (path, args) = if path_manually_set {
let mut path = path.clone(); tracing::debug!(
"Pro-macro server path explicitly set: {}",
if let ProjectWorkspace::Cargo { sysroot, .. } path.display()
| ProjectWorkspace::Json { sysroot, .. } = ws );
{ (path.clone(), vec![])
tracing::debug!("Found a cargo workspace..."); } else {
if let Some(sysroot) = sysroot.as_ref() { let mut sysroot_server = None;
tracing::debug!("Found a cargo workspace with a sysroot..."); if let ProjectWorkspace::Cargo { sysroot, .. }
let server_path = | ProjectWorkspace::Json { sysroot, .. } = ws
sysroot.root().join("libexec").join(&standalone_server_name); {
if std::fs::metadata(&server_path).is_ok() { if let Some(sysroot) = sysroot.as_ref() {
tracing::debug!( let server_path = sysroot
"And the server exists at {}", .root()
server_path.display() .join("libexec")
); .join(&standalone_server_name);
path = server_path; if std::fs::metadata(&server_path).is_ok() {
args = vec![]; tracing::debug!(
} else { "Sysroot proc-macro server exists at {}",
tracing::debug!( server_path.display()
"And the server does not exist at {}", );
server_path.display() sysroot_server = Some(server_path);
); } else {
tracing::debug!(
"Sysroot proc-macro server does not exist at {}",
server_path.display()
);
}
} }
} }
} sysroot_server.map_or_else(
|| (path.clone(), vec!["proc-macro".to_owned()]),
|path| (path, vec![]),
)
};
tracing::info!(?args, "Using proc-macro server at {}", path.display(),); tracing::info!(?args, "Using proc-macro server at {}", path.display(),);
ProcMacroServer::spawn(path.clone(), args.clone()).map_err(|err| { ProcMacroServer::spawn(path.clone(), args).map_err(|err| {
let error = format!( let error = format!(
"Failed to run proc-macro server from path {}, error: {:?}", "Failed to run proc-macro server from path {}, error: {:?}",
path.display(), path.display(),