From e5698faf4c3d1964d2a644f7b0856d5b3577df73 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sat, 4 Apr 2020 16:10:45 +0800 Subject: Implement expand_task and list_macros --- crates/ra_proc_macro_srv/src/lib.rs | 31 +++++++++++++++++++++++++++---- 1 file 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; use proc_macro::bridge::client::TokenStream; use ra_proc_macro::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask}; -pub fn expand_task(_task: &ExpansionTask) -> Result { - unimplemented!() +pub fn expand_task(task: &ExpansionTask) -> Result { + let expander = dylib::Expander::new(&task.lib) + .expect(&format!("Cannot expand with provided libraries: ${:?}", &task.lib)); + + match expander.expand(&task.macro_name, &task.macro_body, task.attributes.as_ref()) { + Ok(expansion) => Ok(ExpansionResult { expansion }), + Err(msg) => { + let reason = format!( + "Cannot perform expansion for {}: error {:?}!", + &task.macro_name, + msg.as_str() + ); + Err(reason) + } + } } -pub fn list_macros(_task: &ListMacrosTask) -> Result { - unimplemented!() +pub fn list_macros(task: &ListMacrosTask) -> Result { + let expander = dylib::Expander::new(&task.lib) + .expect(&format!("Cannot expand with provided libraries: ${:?}", &task.lib)); + + match expander.list_macros() { + Ok(macros) => Ok(ListMacrosResult { macros }), + Err(msg) => { + let reason = + format!("Cannot perform expansion for {:?}: error {:?}!", &task.lib, msg.as_str()); + Err(reason) + } + } } -- cgit v1.2.3