From 09345a47e5895850cc431efcdc4f5cfd0418722a Mon Sep 17 00:00:00 2001 From: Raul Victor Trombin Date: Mon, 13 May 2024 20:40:33 -0300 Subject: [PATCH] build: parser: Add automatic arguments description for set/settings functions type --- build/parser.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/build/parser.rs b/build/parser.rs index aa4a5323d..c722aa114 100644 --- a/build/parser.rs +++ b/build/parser.rs @@ -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 } @@ -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,)*