-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit-id:ab75be72
- Loading branch information
Showing
3 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
scarb/src/ops/proc_macro_server/methods/expand_attribute.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use crate::{ | ||
compiler::plugin::proc_macro::{ExpansionKind, ProcMacroHost}, | ||
ops::proc_macro_server::json_rpc::Handler, | ||
}; | ||
use anyhow::Result; | ||
use proc_macro_server_api::methods::{expand::ExpandAttribute, ProcMacroResult}; | ||
use std::sync::Arc; | ||
|
||
impl Handler for ExpandAttribute { | ||
fn handle(proc_macros: Arc<ProcMacroHost>, params: Self::Params) -> Result<Self::Response> { | ||
let instance = proc_macros | ||
.macros() | ||
.into_iter() | ||
.find(|e| { | ||
e.get_expansions() | ||
.iter() | ||
.filter(|expansion| expansion.kind == ExpansionKind::Attr) | ||
.any(|expansion| expansion.name == params.attr) | ||
}) | ||
.unwrap(); | ||
|
||
let result = instance.generate_code(params.attr.into(), params.args, params.item); | ||
|
||
Ok(ProcMacroResult { | ||
token_stream: result.token_stream, | ||
diagnostics: result.diagnostics, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod defined_macros; | ||
pub mod expand_attribute; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters