From fb21a215be0968d1102aba842c0fdedcd401cb15 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 7 Dec 2020 17:06:14 +0100 Subject: Retain types of proc macros and allow attr. macros --- crates/base_db/src/input.rs | 13 +++++++++---- crates/base_db/src/lib.rs | 2 +- crates/proc_macro_api/Cargo.toml | 1 + crates/proc_macro_api/src/lib.rs | 33 +++++++++++++++++---------------- crates/proc_macro_api/src/rpc.rs | 2 +- 5 files changed, 29 insertions(+), 22 deletions(-) (limited to 'crates') diff --git a/crates/base_db/src/input.rs b/crates/base_db/src/input.rs index 98ba372ad..cda5e57dc 100644 --- a/crates/base_db/src/input.rs +++ b/crates/base_db/src/input.rs @@ -143,9 +143,17 @@ impl CrateDisplayName { #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub struct ProcMacroId(pub u32); +#[derive(Copy, Clone, Eq, PartialEq, Debug)] +pub enum ProcMacroKind { + CustomDerive, + FuncLike, + Attr, +} + #[derive(Debug, Clone)] pub struct ProcMacro { pub name: SmolStr, + pub kind: ProcMacroKind, pub expander: Arc, } @@ -198,11 +206,8 @@ impl CrateGraph { display_name: Option, cfg_options: CfgOptions, env: Env, - proc_macro: Vec<(SmolStr, Arc)>, + proc_macro: Vec, ) -> CrateId { - let proc_macro = - proc_macro.into_iter().map(|(name, it)| ProcMacro { name, expander: it }).collect(); - let data = CrateData { root_file_id: file_id, edition, diff --git a/crates/base_db/src/lib.rs b/crates/base_db/src/lib.rs index ce75a5337..5571af495 100644 --- a/crates/base_db/src/lib.rs +++ b/crates/base_db/src/lib.rs @@ -14,7 +14,7 @@ pub use crate::{ change::Change, input::{ CrateData, CrateDisplayName, CrateGraph, CrateId, CrateName, Dependency, Edition, Env, - ProcMacroId, SourceRoot, SourceRootId, + ProcMacro, ProcMacroId, ProcMacroKind, SourceRoot, SourceRootId, }, }; pub use salsa; diff --git a/crates/proc_macro_api/Cargo.toml b/crates/proc_macro_api/Cargo.toml index 3863e5189..1af2bbca7 100644 --- a/crates/proc_macro_api/Cargo.toml +++ b/crates/proc_macro_api/Cargo.toml @@ -17,3 +17,4 @@ crossbeam-channel = "0.5.0" jod-thread = "0.1.1" tt = { path = "../tt", version = "0.0.0" } +base_db = { path = "../base_db", version = "0.0.0" } diff --git a/crates/proc_macro_api/src/lib.rs b/crates/proc_macro_api/src/lib.rs index 40fdbfd5a..bf1f90879 100644 --- a/crates/proc_macro_api/src/lib.rs +++ b/crates/proc_macro_api/src/lib.rs @@ -16,6 +16,7 @@ use std::{ sync::Arc, }; +use base_db::ProcMacro; use tt::{SmolStr, Subtree}; use crate::process::{ProcMacroProcessSrv, ProcMacroProcessThread}; @@ -82,7 +83,7 @@ impl ProcMacroClient { ProcMacroClient { kind: ProcMacroClientKind::Dummy } } - pub fn by_dylib_path(&self, dylib_path: &Path) -> Vec<(SmolStr, Arc)> { + pub fn by_dylib_path(&self, dylib_path: &Path) -> Vec { match &self.kind { ProcMacroClientKind::Dummy => vec![], ProcMacroClientKind::Process { process, .. } => { @@ -96,21 +97,21 @@ impl ProcMacroClient { macros .into_iter() - .filter_map(|(name, kind)| { - match kind { - ProcMacroKind::CustomDerive | ProcMacroKind::FuncLike => { - let name = SmolStr::new(&name); - let expander: Arc = - Arc::new(ProcMacroProcessExpander { - process: process.clone(), - name: name.clone(), - dylib_path: dylib_path.into(), - }); - Some((name, expander)) - } - // FIXME: Attribute macro are currently unsupported. - ProcMacroKind::Attr => None, - } + .map(|(name, kind)| { + let name = SmolStr::new(&name); + let kind = match kind { + ProcMacroKind::CustomDerive => base_db::ProcMacroKind::CustomDerive, + ProcMacroKind::FuncLike => base_db::ProcMacroKind::FuncLike, + ProcMacroKind::Attr => base_db::ProcMacroKind::Attr, + }; + let expander: Arc = + Arc::new(ProcMacroProcessExpander { + process: process.clone(), + name: name.clone(), + dylib_path: dylib_path.into(), + }); + + ProcMacro { name, kind, expander } }) .collect() } diff --git a/crates/proc_macro_api/src/rpc.rs b/crates/proc_macro_api/src/rpc.rs index 203109ca4..b85f92eea 100644 --- a/crates/proc_macro_api/src/rpc.rs +++ b/crates/proc_macro_api/src/rpc.rs @@ -19,7 +19,7 @@ pub struct ListMacrosTask { pub lib: PathBuf, } -#[derive(Clone, Eq, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Copy, Clone, Eq, PartialEq, Debug, Serialize, Deserialize)] pub enum ProcMacroKind { CustomDerive, FuncLike, -- cgit v1.2.3