From a8c9c882921c052be4e8ef65557c2946d013e425 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Mon, 15 Mar 2021 23:38:22 +0800 Subject: Add test for proc-macro meta info retrieval --- crates/proc_macro_api/src/lib.rs | 3 ++- crates/proc_macro_api/src/version.rs | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'crates/proc_macro_api') diff --git a/crates/proc_macro_api/src/lib.rs b/crates/proc_macro_api/src/lib.rs index 941d0fe9e..2dd2a8541 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 { - 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 b903658fb..dcf8fae8f 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 { +/// Read rustc dylib information +pub fn read_dylib_info(dylib_path: &Path) -> io::Result { macro_rules! err { ($e:literal) => { io::Error::new(io::ErrorKind::InvalidData, $e) -- cgit v1.2.3