Skip to content

Commit

Permalink
fix: pass through doc comments for server fns (#2099)
Browse files Browse the repository at this point in the history
  • Loading branch information
rakshith-ravi authored Dec 18, 2023
1 parent fb0a62f commit 880002d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions leptos_macro/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ use proc_macro2::Literal;
use quote::{ToTokens, __private::TokenStream as TokenStream2};
use syn::{
parse::{Parse, ParseStream},
Ident, ItemFn, LitStr, Token,
Attribute, Ident, ItemFn, LitStr, Token,
};

pub fn server_impl(
args: proc_macro::TokenStream,
s: TokenStream,
) -> TokenStream {
pub fn server_impl(args: TokenStream, s: TokenStream) -> TokenStream {
let function: syn::ItemFn = match syn::parse(s.clone()) {
Ok(f) => f,
// Returning the original input stream in the case of a parsing
Expand All @@ -35,6 +32,11 @@ pub fn server_impl(
Ok(args) => args,
Err(e) => return e.to_compile_error().into(),
};
args.docs = attrs
.iter()
.cloned()
.filter(|attr| attr.meta.path().is_ident("doc"))
.collect();
// default to PascalCase version of function name if no struct name given
if args.struct_name.is_none() {
let upper_camel_case_name = Converter::new()
Expand Down Expand Up @@ -66,6 +68,7 @@ pub fn server_impl(
}

struct ServerFnArgs {
docs: Vec<Attribute>,
struct_name: Option<Ident>,
prefix: Option<Literal>,
encoding: Option<Literal>,
Expand All @@ -79,7 +82,9 @@ impl ToTokens for ServerFnArgs {
let prefix = self.prefix.as_ref().map(|p| quote::quote! { #p, });
let encoding = self.encoding.as_ref().map(|e| quote::quote! { #e, });
let fn_path = self.fn_path.as_ref().map(|f| quote::quote! { #f });
let docs = &self.docs;
tokens.extend(quote::quote! {
#(#docs)*
#struct_name
#prefix
#encoding
Expand Down Expand Up @@ -191,6 +196,7 @@ impl Parse for ServerFnArgs {
}

Ok(Self {
docs: vec![],
struct_name,
prefix,
encoding,
Expand Down

0 comments on commit 880002d

Please sign in to comment.