about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-04-28 19:18:14 +0000
committerbors <bors@rust-lang.org>2023-04-28 19:18:14 +0000
commit3ad835faa97030011e66eb83092f7fb1e3201e2b (patch)
treed284adf0d6b107083b276cc28f336c8c6ee8bc19
parent62c81d62932c458e23975191ecc124916be0b35e (diff)
parent3b97978c49829bdb63c198ee6bcf32c450f5bc0e (diff)
downloadrust-3ad835faa97030011e66eb83092f7fb1e3201e2b.tar.gz
rust-3ad835faa97030011e66eb83092f7fb1e3201e2b.zip
Auto merge of #14671 - Veykril:proc-macro-srv-conf, r=Veykril
fix: Fix proc-macro-srv path config not working
-rw-r--r--crates/rust-analyzer/src/config.rs47
-rw-r--r--crates/rust-analyzer/src/reload.rs5
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<AbsPathBuf> {
-        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<str>, Box<[Box<str>]>> {
@@ -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(),