Finally got get_doc hookup in codegen macro working

This commit is contained in:
greg 2018-09-29 01:20:31 -07:00
parent 4fccff5e27
commit 80eb703f5e
2 changed files with 9 additions and 7 deletions

View File

@ -72,13 +72,13 @@ pub fn derive_programming_language_interface(input: TokenStream) -> TokenStream
let passes = extract_attribute_list("PipelineSteps", attrs).expect("PipelineSteps are required"); let passes = extract_attribute_list("PipelineSteps", attrs).expect("PipelineSteps are required");
let pass_idents = passes.iter().map(|x| x.0.clone()); let pass_idents = passes.iter().map(|x| x.0.clone());
let doc_method: Option<String>= find_attr_by_name("DocMethod", attrs).and_then(|attr| { let doc_method: Option<proc_macro2::Ident>= find_attr_by_name("DocMethod", attrs).and_then(|attr| {
let tts = attr.tts.clone().into_iter().collect::<Vec<_>>(); let tts = attr.tts.clone().into_iter().collect::<Vec<_>>();
if tts.len() == 2 { if tts.len() == 2 {
let ref after_equals: proc_macro2::TokenTree = tts[1]; let ref after_equals: proc_macro2::TokenTree = tts[1];
match after_equals { match after_equals {
proc_macro2::TokenTree::Ident(ident) => Some(ident.to_string()), proc_macro2::TokenTree::Ident(ident) => Some(ident.clone()),
_ => None _ => None
} }
} else { } else {
@ -88,9 +88,9 @@ pub fn derive_programming_language_interface(input: TokenStream) -> TokenStream
let doc_method_body = match doc_method { let doc_method_body = match doc_method {
None => quote! { }, None => quote! { },
Some(s) => quote!{ Some(method_name) => quote! {
fn get_doc(&self, commands: &Vec<&str>) -> Option<String> { fn get_doc(&self, commands: &Vec<&str>) -> Option<String> {
#s(commands) self.#method_name(commands)
} }
} }
}; };
@ -128,8 +128,10 @@ pub fn derive_programming_language_interface(input: TokenStream) -> TokenStream
vec![ #(#pass_descriptors),* ] vec![ #(#pass_descriptors),* ]
//vec![ #(PassDescriptor { name: #pass_names.to_string(), debug_options: vec![] }),* ] //vec![ #(PassDescriptor { name: #pass_names.to_string(), debug_options: vec![] }),* ]
} }
}
#doc_method_body #doc_method_body
}
}; };
let output: TokenStream = tokens.into(); let output: TokenStream = tokens.into();

View File

@ -44,8 +44,8 @@ pub struct Schala {
} }
impl Schala { impl Schala {
fn get_doc(&self, _commands: &Vec<&str>) -> Option<String> { fn get_doc(&self, commands: &Vec<&str>) -> Option<String> {
Some(format!("yup this is getting called right")) Some(format!("Documentation on commands: {:?}", commands))
} }
} }