diff --git a/derive/src/lib.rs b/derive/src/lib.rs index 5dae988..baf3f19 100644 --- a/derive/src/lib.rs +++ b/derive/src/lib.rs @@ -5,7 +5,7 @@ use darling::FromMeta; use heck::{ToKebabCase, ToLowerCamelCase, ToShoutySnakeCase, ToSnakeCase, ToUpperCamelCase}; use proc_macro2::{Literal, TokenStream}; use quote::{format_ident, quote}; -use syn::{Attribute, FnArg, Ident, Pat, Signature, Type}; +use syn::{spanned::Spanned, Attribute, FnArg, Ident, Pat, Signature, Type}; use proxy::proxy_macro; use service::service_macro; @@ -51,7 +51,7 @@ impl MethodAttributes { pub(crate) struct RpcMethod<'a> { signature: &'a Signature, - args: Vec<(&'a Ident, &'a Type)>, + args: Vec<(Ident, &'a Type)>, method_name: String, method_name_literal: Literal, args_struct_ident: Ident, @@ -67,6 +67,7 @@ impl<'a> RpcMethod<'a> { ) -> Self { let mut has_self = false; let mut args = vec![]; + let rename_all = rename_all.as_ref(); for arg in &signature.inputs { match arg { @@ -75,7 +76,12 @@ impl<'a> RpcMethod<'a> { } FnArg::Typed(pat_type) => { let ident = match &*pat_type.pat { - Pat::Ident(ty) => &ty.ident, + Pat::Ident(ty) => { + let fn_arg = rename_all + .map(|r| r.rename(&ty.ident.to_string())) + .unwrap_or(ty.ident.to_string()); + Ident::new(&fn_arg, ty.span().clone()) + } _ => panic!("Arguments must not be patterns."), }; args.push((ident, &*pat_type.ty)); @@ -92,7 +98,6 @@ impl<'a> RpcMethod<'a> { let method_name = signature.ident.to_string(); let method_name = rename_all - .as_ref() .map(|r| r.rename(&method_name)) .unwrap_or(method_name); let method_name_literal = Literal::string(&method_name); @@ -120,6 +125,7 @@ impl<'a> RpcMethod<'a> { let tokens = quote! { #[derive(Debug, ::serde::Serialize, ::serde::Deserialize)] #[allow(non_camel_case_types)] + #[allow(non_snake_case)] struct #args_struct_ident { #(#struct_fields)* } @@ -213,6 +219,7 @@ impl<'a> RpcMethod<'a> { }; quote! { + #[allow(non_snake_case)] async fn #method_ident(&mut self, #(#method_args),*) #output { let args = #args_struct_ident { #(#struct_fields),*