Skip to content

Commit

Permalink
build: parser: Add automatic arguments description for set/settings f…
Browse files Browse the repository at this point in the history
…unctions type
  • Loading branch information
RaulTrombin authored and patrickelectric committed May 14, 2024
1 parent 43a316b commit 5d4bd4a
Showing 1 changed file with 20 additions and 0 deletions.
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

0 comments on commit 5d4bd4a

Please sign in to comment.