-
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:7587de32
- Loading branch information
Showing
6 changed files
with
145 additions
and
9 deletions.
There are no files selected for viewing
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
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
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,49 @@ | ||
use std::sync::Arc; | ||
|
||
use anyhow::Result; | ||
use scarb_proc_macro_server_types::methods::defined_macros::{ | ||
DefinedMacros, DefinedMacrosResponse, | ||
}; | ||
|
||
use super::Handler; | ||
use crate::compiler::plugin::proc_macro::ProcMacroHost; | ||
|
||
impl Handler for DefinedMacros { | ||
fn handle( | ||
proc_macro_host: Arc<ProcMacroHost>, | ||
_params: Self::Params, | ||
) -> Result<Self::Response> { | ||
let mut response = proc_macro_host | ||
.macros() | ||
.iter() | ||
.map(|e| DefinedMacrosResponse { | ||
attributes: e.declared_attributes(), | ||
inline_macros: e.inline_macros(), | ||
derives: e.declared_derives(), | ||
executables: e.executable_attributes(), | ||
}) | ||
.reduce(|mut acc, defined_macros| { | ||
acc.attributes.extend(defined_macros.attributes); | ||
acc.inline_macros.extend(defined_macros.inline_macros); | ||
acc.derives.extend(defined_macros.derives); | ||
acc.executables.extend(defined_macros.executables); | ||
|
||
acc | ||
}) | ||
.unwrap_or_default(); | ||
|
||
response.attributes.sort(); | ||
response.attributes.dedup(); | ||
|
||
response.inline_macros.sort(); | ||
response.inline_macros.dedup(); | ||
|
||
response.derives.sort(); | ||
response.derives.dedup(); | ||
|
||
response.executables.sort(); | ||
response.executables.dedup(); | ||
|
||
Ok(response) | ||
} | ||
} |
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,12 @@ | ||
use std::sync::Arc; | ||
|
||
use anyhow::Result; | ||
use scarb_proc_macro_server_types::methods::Method; | ||
|
||
use crate::compiler::plugin::proc_macro::ProcMacroHost; | ||
|
||
pub mod defined_macros; | ||
|
||
pub trait Handler: Method { | ||
fn handle(proc_macro_host: Arc<ProcMacroHost>, params: Self::Params) -> Result<Self::Response>; | ||
} |
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
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,38 @@ | ||
use assert_fs::prelude::PathChild; | ||
use assert_fs::TempDir; | ||
use scarb_proc_macro_server_types::methods::defined_macros::DefinedMacros; | ||
use scarb_proc_macro_server_types::methods::defined_macros::DefinedMacrosParams; | ||
use scarb_test_support::cairo_plugin_project_builder::CairoPluginProjectBuilder; | ||
use scarb_test_support::proc_macro_server::ProcMacroClient; | ||
use scarb_test_support::proc_macro_server::SIMPLE_MACROS; | ||
use scarb_test_support::project_builder::ProjectBuilder; | ||
|
||
#[test] | ||
fn defined_macros() { | ||
let t = TempDir::new().unwrap(); | ||
let plugin_package = t.child("some"); | ||
|
||
CairoPluginProjectBuilder::default() | ||
.lib_rs(SIMPLE_MACROS) | ||
.build(&plugin_package); | ||
|
||
let project = t.child("test_package"); | ||
|
||
ProjectBuilder::start() | ||
.name("test_package") | ||
.version("1.0.0") | ||
.lib_cairo("") | ||
.dep("some", plugin_package) | ||
.build(&project); | ||
|
||
let mut proc_macro_server = ProcMacroClient::new(&project); | ||
|
||
let response = proc_macro_server | ||
.request_and_wait::<DefinedMacros>(DefinedMacrosParams {}) | ||
.unwrap(); | ||
|
||
assert_eq!(response.attributes, vec!["some".to_string()]); | ||
assert_eq!(response.derives, vec!["some_derive".to_string()]); | ||
assert_eq!(response.inline_macros, vec!["inline_some".to_string()]); | ||
assert_eq!(response.executables, vec!["some_executable".to_string()]); | ||
} |