Skip to content

Commit b45a0d3

Browse files
authored
fix(sol-macro): flatten doc strings correctly (#357)
1 parent 5585abd commit b45a0d3

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

Diff for: crates/sol-macro/src/attr.rs

+24-5
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,31 @@ pub fn docs(attrs: &[Attribute]) -> impl Iterator<Item = &Attribute> {
2424
attrs.iter().filter(|a| is_doc(a))
2525
}
2626

27+
/// Flattens all the `#[doc = "..."]` attributes into a single string.
2728
pub fn docs_str(attrs: &[Attribute]) -> String {
28-
docs(attrs)
29-
.filter_map(|attr| attr.parse_args::<LitStr>().ok())
30-
.map(|doc| doc.value())
31-
.collect::<Vec<_>>()
32-
.join("\n")
29+
let mut doc = String::new();
30+
for attr in docs(attrs) {
31+
let syn::Meta::NameValue(syn::MetaNameValue {
32+
value:
33+
syn::Expr::Lit(syn::ExprLit {
34+
lit: syn::Lit::Str(s),
35+
..
36+
}),
37+
..
38+
}) = &attr.meta
39+
else {
40+
continue
41+
};
42+
43+
let value = s.value();
44+
if !value.is_empty() {
45+
if !doc.is_empty() {
46+
doc.push('\n');
47+
}
48+
doc.push_str(&value);
49+
}
50+
}
51+
doc
3352
}
3453

3554
pub fn derives(attrs: &[Attribute]) -> impl Iterator<Item = &Attribute> {

0 commit comments

Comments
 (0)