Repository: rust-analyzer/rust-analyzer
Pull request #8033 (2021-03-15 15:39:18)

Add test for proc-macro meta info retrieval
bors r+


Patch:
diff --git a/crates/proc_macro_api/src/lib.rs b/crates/proc_macro_api/src/lib.rs
index 941d0fe9e2..2dd2a85411 100644
--- a/crates/proc_macro_api/src/lib.rs
+++ b/crates/proc_macro_api/src/lib.rs
@@ -23,6 +23,7 @@ use tt::{SmolStr, Subtree};
 use crate::process::{ProcMacroProcessSrv, ProcMacroProcessThread};
 
 pub use rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind};
+pub use version::{read_dylib_info, RustCInfo};
 
 #[derive(Debug, Clone)]
 struct ProcMacroProcessExpander {
@@ -76,7 +77,7 @@ impl ProcMacroClient {
     }
 
     pub fn by_dylib_path(&self, dylib_path: &Path) -> Vec<ProcMacro> {
-        match version::read_info(dylib_path) {
+        match version::read_dylib_info(dylib_path) {
             Ok(info) => {
                 if info.version.0 < 1 || info.version.1 < 47 {
                     eprintln!("proc-macro {} built by {:#?} is not supported by Rust Analyzer, please update your rust version.", dylib_path.to_string_lossy(), info);
diff --git a/crates/proc_macro_api/src/version.rs b/crates/proc_macro_api/src/version.rs
index b903658fb9..dcf8fae8f5 100644
--- a/crates/proc_macro_api/src/version.rs
+++ b/crates/proc_macro_api/src/version.rs
@@ -11,14 +11,15 @@ use object::read::{File as BinaryFile, Object, ObjectSection};
 use snap::read::FrameDecoder as SnapDecoder;
 
 #[derive(Debug)]
-pub(crate) struct RustCInfo {
-    pub(crate) version: (usize, usize, usize),
-    pub(crate) channel: String,
-    pub(crate) commit: String,
-    pub(crate) date: String,
+pub struct RustCInfo {
+    pub version: (usize, usize, usize),
+    pub channel: String,
+    pub commit: String,
+    pub date: String,
 }
 
-pub(crate) fn read_info(dylib_path: &Path) -> io::Result<RustCInfo> {
+/// Read rustc dylib information
+pub fn read_dylib_info(dylib_path: &Path) -> io::Result<RustCInfo> {
     macro_rules! err {
         ($e:literal) => {
             io::Error::new(io::ErrorKind::InvalidData, $e)
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 8f541976ec..8af7871ac4 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -172,7 +172,7 @@ config_data! {
         notifications_cargoTomlNotFound: bool      = "true",
 
         /// Enable support for procedural macros, implies `#rust-analyzer.cargo.runBuildScripts#`.
-        procMacro_enable: bool                     = "true",
+        procMacro_enable: bool                     = "false",
         /// Internal config, path to proc-macro server executable (typically,
         /// this is rust-analyzer itself, but we override this in tests).
         procMacro_server: Option<PathBuf>          = "null",
diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc
index c2521289c0..042ba2d54c 100644
--- a/docs/user/generated_config.adoc
+++ b/docs/user/generated_config.adoc
@@ -276,7 +276,7 @@ Number of syntax trees rust-analyzer keeps in memory. Defaults to 128.
 --
 Whether to show `can't find Cargo.toml` error message.
 --
-[[rust-analyzer.procMacro.enable]]rust-analyzer.procMacro.enable (default: `true`)::
+[[rust-analyzer.procMacro.enable]]rust-analyzer.procMacro.enable (default: `false`)::
 +
 --
 Enable support for procedural macros, implies `#rust-analyzer.cargo.runBuildScripts#`.
diff --git a/editors/code/package.json b/editors/code/package.json
index a2ed9b2d58..923e9b35a0 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -690,7 +690,7 @@
                 },
                 "rust-analyzer.procMacro.enable": {
                     "markdownDescription": "Enable support for procedural macros, implies `#rust-analyzer.cargo.runBuildScripts#`.",
-                    "default": true,
+                    "default": false,
                     "type": "boolean"
                 },
                 "rust-analyzer.procMacro.server": {


Test patch:
diff --git a/crates/proc_macro_srv/src/tests/mod.rs b/crates/proc_macro_srv/src/tests/mod.rs
index fd54f8dfda..b4ab4c0776 100644
--- a/crates/proc_macro_srv/src/tests/mod.rs
+++ b/crates/proc_macro_srv/src/tests/mod.rs
@@ -56,3 +56,10 @@ DummyTrait [CustomDerive]"#,
         &res
     );
 }
+
+#[test]
+fn test_version_check() {
+    let path = fixtures::dylib_path("proc_macro_test", "0.0.0");
+    let info = proc_macro_api::read_dylib_info(&path).unwrap();
+    assert!(info.version.1 >= 50);
+}
diff --git a/crates/proc_macro_srv/src/tests/utils.rs b/crates/proc_macro_srv/src/tests/utils.rs
index 0484c3af44..f15381f0f4 100644
--- a/crates/proc_macro_srv/src/tests/utils.rs
+++ b/crates/proc_macro_srv/src/tests/utils.rs
@@ -6,7 +6,7 @@ use proc_macro_api::ListMacrosTask;
 use std::str::FromStr;
 use test_utils::assert_eq_text;
 
-mod fixtures {
+pub mod fixtures {
     use cargo_metadata::Message;
     use std::path::PathBuf;
     use std::process::Command;