aboutsummaryrefslogtreecommitdiff
path: root/crates/proc_macro_api
diff options
context:
space:
mode:
Diffstat (limited to 'crates/proc_macro_api')
-rw-r--r--crates/proc_macro_api/src/lib.rs3
-rw-r--r--crates/proc_macro_api/src/version.rs17
2 files changed, 11 insertions, 9 deletions
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};
23use crate::process::{ProcMacroProcessSrv, ProcMacroProcessThread}; 23use crate::process::{ProcMacroProcessSrv, ProcMacroProcessThread};
24 24
25pub use rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind}; 25pub use rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind};
26pub use version::{read_dylib_info, RustCInfo};
26 27
27#[derive(Debug, Clone)] 28#[derive(Debug, Clone)]
28struct ProcMacroProcessExpander { 29struct ProcMacroProcessExpander {
@@ -76,7 +77,7 @@ impl ProcMacroClient {
76 } 77 }
77 78
78 pub fn by_dylib_path(&self, dylib_path: &Path) -> Vec<ProcMacro> { 79 pub fn by_dylib_path(&self, dylib_path: &Path) -> Vec<ProcMacro> {
79 match version::read_info(dylib_path) { 80 match version::read_dylib_info(dylib_path) {
80 Ok(info) => { 81 Ok(info) => {
81 if info.version.0 < 1 || info.version.1 < 47 { 82 if info.version.0 < 1 || info.version.1 < 47 {
82 eprintln!("proc-macro {} built by {:#?} is not supported by Rust Analyzer, please update your rust version.", dylib_path.to_string_lossy(), info); 83 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 11a7fb59a..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};
11use snap::read::FrameDecoder as SnapDecoder; 11use snap::read::FrameDecoder as SnapDecoder;
12 12
13#[derive(Debug)] 13#[derive(Debug)]
14pub(crate) struct RustCInfo { 14pub struct RustCInfo {
15 pub(crate) version: (usize, usize, usize), 15 pub version: (usize, usize, usize),
16 pub(crate) channel: String, 16 pub channel: String,
17 pub(crate) commit: String, 17 pub commit: String,
18 pub(crate) date: String, 18 pub date: String,
19} 19}
20 20
21pub(crate) fn read_info(dylib_path: &Path) -> io::Result<RustCInfo> { 21/// Read rustc dylib information
22pub fn read_dylib_info(dylib_path: &Path) -> io::Result<RustCInfo> {
22 macro_rules! err { 23 macro_rules! err {
23 ($e:literal) => { 24 ($e:literal) => {
24 io::Error::new(io::ErrorKind::InvalidData, $e) 25 io::Error::new(io::ErrorKind::InvalidData, $e)
@@ -33,7 +34,7 @@ pub(crate) fn read_info(dylib_path: &Path) -> io::Result<RustCInfo> {
33 } 34 }
34 35
35 let version_part = items.next().ok_or(err!("no version string"))?; 36 let version_part = items.next().ok_or(err!("no version string"))?;
36 let mut version_parts = version_part.split("-"); 37 let mut version_parts = version_part.split('-');
37 let version = version_parts.next().ok_or(err!("no version"))?; 38 let version = version_parts.next().ok_or(err!("no version"))?;
38 let channel = version_parts.next().unwrap_or_default().to_string(); 39 let channel = version_parts.next().unwrap_or_default().to_string();
39 40
@@ -51,7 +52,7 @@ pub(crate) fn read_info(dylib_path: &Path) -> io::Result<RustCInfo> {
51 let date = date[0..date.len() - 2].to_string(); 52 let date = date[0..date.len() - 2].to_string();
52 53
53 let version_numbers = version 54 let version_numbers = version
54 .split(".") 55 .split('.')
55 .map(|it| it.parse::<usize>()) 56 .map(|it| it.parse::<usize>())
56 .collect::<Result<Vec<_>, _>>() 57 .collect::<Result<Vec<_>, _>>()
57 .map_err(|_| err!("version number error"))?; 58 .map_err(|_| err!("version number error"))?;