mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Add test for proc-macro meta info retrieval
This commit is contained in:
parent
5f6d71cf0c
commit
a8c9c88292
@ -23,6 +23,7 @@ use tt::{SmolStr, Subtree};
|
|||||||
use crate::process::{ProcMacroProcessSrv, ProcMacroProcessThread};
|
use crate::process::{ProcMacroProcessSrv, ProcMacroProcessThread};
|
||||||
|
|
||||||
pub use rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind};
|
pub use rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind};
|
||||||
|
pub use version::{read_dylib_info, RustCInfo};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct ProcMacroProcessExpander {
|
struct ProcMacroProcessExpander {
|
||||||
@ -76,7 +77,7 @@ impl ProcMacroClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn by_dylib_path(&self, dylib_path: &Path) -> Vec<ProcMacro> {
|
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) => {
|
Ok(info) => {
|
||||||
if info.version.0 < 1 || info.version.1 < 47 {
|
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);
|
eprintln!("proc-macro {} built by {:#?} is not supported by Rust Analyzer, please update your rust version.", dylib_path.to_string_lossy(), info);
|
||||||
|
@ -11,14 +11,15 @@ use object::read::{File as BinaryFile, Object, ObjectSection};
|
|||||||
use snap::read::FrameDecoder as SnapDecoder;
|
use snap::read::FrameDecoder as SnapDecoder;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct RustCInfo {
|
pub struct RustCInfo {
|
||||||
pub(crate) version: (usize, usize, usize),
|
pub version: (usize, usize, usize),
|
||||||
pub(crate) channel: String,
|
pub channel: String,
|
||||||
pub(crate) commit: String,
|
pub commit: String,
|
||||||
pub(crate) date: 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 {
|
macro_rules! err {
|
||||||
($e:literal) => {
|
($e:literal) => {
|
||||||
io::Error::new(io::ErrorKind::InvalidData, $e)
|
io::Error::new(io::ErrorKind::InvalidData, $e)
|
||||||
|
@ -56,3 +56,10 @@ DummyTrait [CustomDerive]"#,
|
|||||||
&res
|
&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);
|
||||||
|
}
|
||||||
|
@ -6,7 +6,7 @@ use proc_macro_api::ListMacrosTask;
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use test_utils::assert_eq_text;
|
use test_utils::assert_eq_text;
|
||||||
|
|
||||||
mod fixtures {
|
pub mod fixtures {
|
||||||
use cargo_metadata::Message;
|
use cargo_metadata::Message;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user