mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-21 19:04:24 +00:00
Pass crate environment to proc macros
This commit is contained in:
parent
798968e1e3
commit
70877428a8
6 changed files with 42 additions and 9 deletions
|
@ -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<Subtree, tt::ExpansionError> {
|
||||
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))?;
|
||||
|
|
|
@ -51,6 +51,9 @@ pub struct ExpansionTask {
|
|||
pub attributes: Option<Subtree>,
|
||||
|
||||
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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue