From 798968e1e3a7d9eafa0c27c857571cdc347c34a7 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 11 Dec 2020 14:24:02 +0100 Subject: Move TokenExpander to base_db and rename it It's only used to break the dependency to proc_macro_api --- crates/proc_macro_api/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 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 0d061fd53..a61afbbd6 100644 --- a/crates/proc_macro_api/src/lib.rs +++ b/crates/proc_macro_api/src/lib.rs @@ -39,7 +39,7 @@ impl PartialEq for ProcMacroProcessExpander { } } -impl tt::TokenExpander for ProcMacroProcessExpander { +impl base_db::ProcMacroExpander for ProcMacroProcessExpander { fn expand( &self, subtree: &Subtree, @@ -90,7 +90,7 @@ impl ProcMacroClient { ProcMacroKind::FuncLike => base_db::ProcMacroKind::FuncLike, ProcMacroKind::Attr => base_db::ProcMacroKind::Attr, }; - let expander: Arc = Arc::new(ProcMacroProcessExpander { + let expander = Arc::new(ProcMacroProcessExpander { process: self.process.clone(), name: name.clone(), dylib_path: dylib_path.into(), -- cgit v1.2.3 From 70877428a8d9f17834dee72f03ef80ce5c206e68 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 11 Dec 2020 14:57:50 +0100 Subject: Pass crate environment to proc macros --- crates/proc_macro_api/src/lib.rs | 4 +++- crates/proc_macro_api/src/rpc.rs | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) (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 a61afbbd6..2ea456fb0 100644 --- a/crates/proc_macro_api/src/lib.rs +++ b/crates/proc_macro_api/src/lib.rs @@ -16,7 +16,7 @@ use std::{ sync::Arc, }; -use base_db::ProcMacro; +use base_db::{Env, ProcMacro}; use tt::{SmolStr, Subtree}; use crate::process::{ProcMacroProcessSrv, ProcMacroProcessThread}; @@ -44,12 +44,14 @@ impl base_db::ProcMacroExpander for ProcMacroProcessExpander { &self, subtree: &Subtree, attr: Option<&Subtree>, + env: &Env, ) -> Result { let task = ExpansionTask { macro_body: subtree.clone(), macro_name: self.name.to_string(), attributes: attr.cloned(), lib: self.dylib_path.to_path_buf(), + env: env.iter().map(|(k, v)| (k.to_string(), v.to_string())).collect(), }; let result: ExpansionResult = self.process.send_task(msg::Request::ExpansionMacro(task))?; diff --git a/crates/proc_macro_api/src/rpc.rs b/crates/proc_macro_api/src/rpc.rs index b85f92eea..cf830b59f 100644 --- a/crates/proc_macro_api/src/rpc.rs +++ b/crates/proc_macro_api/src/rpc.rs @@ -51,6 +51,9 @@ pub struct ExpansionTask { pub attributes: Option, pub lib: PathBuf, + + /// Environment variables to set during macro expansion. + pub env: Vec<(String, String)>, } #[derive(Clone, Eq, PartialEq, Debug, Default, Serialize, Deserialize)] @@ -251,6 +254,7 @@ mod tests { macro_name: Default::default(), attributes: None, lib: Default::default(), + env: Default::default(), }; let json = serde_json::to_string(&task).unwrap(); -- cgit v1.2.3