Skip to content

Commit

Permalink
Capture the first line of each docstring instead of the last for mult…
Browse files Browse the repository at this point in the history
…i-line docstrings.
  • Loading branch information
macklin-10x committed Apr 2, 2024
1 parent 5111114 commit a1b1e77
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions martian-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
}
Expand Down Expand Up @@ -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],
};
Expand Down
2 changes: 1 addition & 1 deletion martian-derive/tests/mro/test_struct.mro
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down

0 comments on commit a1b1e77

Please sign in to comment.