From a1b1e7763884bdb3038da1536546f41adb497397 Mon Sep 17 00:00:00 2001 From: Chris Macklin Date: Tue, 2 Apr 2024 14:59:31 -0700 Subject: [PATCH] Capture the first line of each docstring instead of the last for multi-line docstrings. --- martian-derive/src/lib.rs | 10 +++++++--- martian-derive/tests/mro/test_struct.mro | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/martian-derive/src/lib.rs b/martian-derive/src/lib.rs index 87d1cf126e..f59f59d91d 100644 --- a/martian-derive/src/lib.rs +++ b/martian-derive/src/lib.rs @@ -518,11 +518,15 @@ pub fn martian_struct(item: proc_macro::TokenStream) -> proc_macro::TokenStream } mro_type = Some(val.value()) - } else if attr.path().is_ident("doc") { + } else if attr.path().is_ident("doc") && doc_comment.is_none() { if let Meta::NameValue(meta) = &attr.meta { if let Expr::Lit(elit) = &meta.value { if let Lit::Str(lstr) = &elit.lit { - doc_comment = Some(lstr.value()); + let val = lstr.value(); + let trimmed = val.trim(); + if !trimmed.is_empty() { + doc_comment = Some(trimmed.to_string()); + } } } } @@ -568,7 +572,7 @@ pub fn martian_struct(item: proc_macro::TokenStream) -> proc_macro::TokenStream let doc_comment_code = match doc_comment { Some(t) => { - quote![Some(#t.trim_start().to_string())] + quote![Some(#t.to_string())] } None => quote![None], }; diff --git a/martian-derive/tests/mro/test_struct.mro b/martian-derive/tests/mro/test_struct.mro index f9543f3909..232ba820d0 100644 --- a/martian-derive/tests/mro/test_struct.mro +++ b/martian-derive/tests/mro/test_struct.mro @@ -13,7 +13,7 @@ struct SampleDef( struct Config( SampleDef[] sample_def "The sample definition", - path reference_path "even more info about reference path" "the_reference_path", + path reference_path "The reference path" "the_reference_path", int force_cells "The number of cells to force the pipeline to call", json primers "The primer definitions as a JSON file" "renamed_primers_json.json", )