Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: Automatic arguments description for set/settings methods #35

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions build/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,24 @@ impl MessageDefinition {
let typ = variable.typ.to_rust();
quote! { #name: #typ }
});
let function_parameters_description = self.payload.iter().map(|variable| {
let comment = variable
.description
.clone()
.unwrap_or("Not documented".to_string());
let name = ident!(&variable.name);
let units = variable.units.clone();

let description = if let Some(units) = units {
format!(r"* `{name}` \[{units}\] - {comment}")
} else {
format!(r"* `{name}` - {comment}")
};

quote! {
#[doc = #description]
}
});
let function_assignments = self.payload.iter().map(|variable| {
let name = ident!(variable.name);
quote! { #name }
Expand All @@ -223,6 +241,8 @@ impl MessageDefinition {

quote! {
#[doc = #function_description]
#[doc = "# Arguments"]
#(#function_parameters_description)*
pub async fn #function_name(&self, #(#function_parameters),*) -> Result<(), PingError> {
let request = Messages::#pascal_message_name(#struct_name {
#(#function_assignments,)*
Expand Down
Loading