From 3b97978c49829bdb63c198ee6bcf32c450f5bc0e Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 28 Apr 2023 08:30:41 +0200 Subject: [PATCH] fix: Fix proc-macro-srv path config not working --- crates/rust-analyzer/src/config.rs | 47 ++++++++++++++++++++++++++---- crates/rust-analyzer/src/reload.rs | 5 ++++ 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 89ca8e63567..c24bdab78a9 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -1102,12 +1102,8 @@ impl Config { } pub fn proc_macro_srv(&self) -> Option { - self.data - .procMacro_server - .clone() - .map(AbsPathBuf::try_from)? - .ok() - .map(|path| self.root_path.join(path)) + let path = self.data.procMacro_server.clone()?; + Some(AbsPathBuf::try_from(path).unwrap_or_else(|path| self.root_path.join(&path))) } pub fn dummy_replacements(&self) -> &FxHashMap, Box<[Box]>> { @@ -2424,4 +2420,43 @@ mod tests { fn remove_ws(text: &str) -> String { text.replace(char::is_whitespace, "") } + + #[test] + fn proc_macro_srv_null() { + let mut config = + Config::new(AbsPathBuf::try_from(project_root()).unwrap(), Default::default(), vec![]); + config + .update(serde_json::json!({ + "procMacro_server": null, + })) + .unwrap(); + assert_eq!(config.proc_macro_srv(), None); + } + + #[test] + fn proc_macro_srv_abs() { + let mut config = + Config::new(AbsPathBuf::try_from(project_root()).unwrap(), Default::default(), vec![]); + config + .update(serde_json::json!({ + "procMacro": {"server": project_root().display().to_string()} + })) + .unwrap(); + assert_eq!(config.proc_macro_srv(), Some(AbsPathBuf::try_from(project_root()).unwrap())); + } + + #[test] + fn proc_macro_srv_rel() { + let mut config = + Config::new(AbsPathBuf::try_from(project_root()).unwrap(), Default::default(), vec![]); + config + .update(serde_json::json!({ + "procMacro": {"server": "./server"} + })) + .unwrap(); + assert_eq!( + config.proc_macro_srv(), + Some(AbsPathBuf::try_from(project_root().join("./server")).unwrap()) + ); + } } diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index 4d840e11df7..87ec040d7b8 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs @@ -426,6 +426,11 @@ impl GlobalState { tracing::info!("Using proc-macro server at {}", path.display(),); ProcMacroServer::spawn(path.clone()).map_err(|err| { + tracing::error!( + "Failed to run proc-macro server from path {}, error: {:?}", + path.display(), + err + ); anyhow::anyhow!( "Failed to run proc-macro server from path {}, error: {:?}", path.display(),