diff options
author | Edwin Cheng <[email protected]> | 2020-04-04 09:10:45 +0100 |
---|---|---|
committer | Edwin Cheng <[email protected]> | 2020-04-09 18:18:47 +0100 |
commit | e5698faf4c3d1964d2a644f7b0856d5b3577df73 (patch) | |
tree | 5ca3dde68c552ee03f1b4f922247cc5b7c4cf380 | |
parent | f7f121d60d0f6b8f280e09397b14a8afd0a369c1 (diff) |
Implement expand_task and list_macros
-rw-r--r-- | crates/ra_proc_macro_srv/src/lib.rs | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/crates/ra_proc_macro_srv/src/lib.rs b/crates/ra_proc_macro_srv/src/lib.rs index f5a526dbf..8fba73ac9 100644 --- a/crates/ra_proc_macro_srv/src/lib.rs +++ b/crates/ra_proc_macro_srv/src/lib.rs | |||
@@ -22,10 +22,33 @@ mod dylib; | |||
22 | use proc_macro::bridge::client::TokenStream; | 22 | use proc_macro::bridge::client::TokenStream; |
23 | use ra_proc_macro::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask}; | 23 | use ra_proc_macro::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask}; |
24 | 24 | ||
25 | pub fn expand_task(_task: &ExpansionTask) -> Result<ExpansionResult, String> { | 25 | pub fn expand_task(task: &ExpansionTask) -> Result<ExpansionResult, String> { |
26 | unimplemented!() | 26 | let expander = dylib::Expander::new(&task.lib) |
27 | .expect(&format!("Cannot expand with provided libraries: ${:?}", &task.lib)); | ||
28 | |||
29 | match expander.expand(&task.macro_name, &task.macro_body, task.attributes.as_ref()) { | ||
30 | Ok(expansion) => Ok(ExpansionResult { expansion }), | ||
31 | Err(msg) => { | ||
32 | let reason = format!( | ||
33 | "Cannot perform expansion for {}: error {:?}!", | ||
34 | &task.macro_name, | ||
35 | msg.as_str() | ||
36 | ); | ||
37 | Err(reason) | ||
38 | } | ||
39 | } | ||
27 | } | 40 | } |
28 | 41 | ||
29 | pub fn list_macros(_task: &ListMacrosTask) -> Result<ListMacrosResult, String> { | 42 | pub fn list_macros(task: &ListMacrosTask) -> Result<ListMacrosResult, String> { |
30 | unimplemented!() | 43 | let expander = dylib::Expander::new(&task.lib) |
44 | .expect(&format!("Cannot expand with provided libraries: ${:?}", &task.lib)); | ||
45 | |||
46 | match expander.list_macros() { | ||
47 | Ok(macros) => Ok(ListMacrosResult { macros }), | ||
48 | Err(msg) => { | ||
49 | let reason = | ||
50 | format!("Cannot perform expansion for {:?}: error {:?}!", &task.lib, msg.as_str()); | ||
51 | Err(reason) | ||
52 | } | ||
53 | } | ||
31 | } | 54 | } |