Skip to content

Commit

Permalink
fix: doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vidhanio committed Aug 31, 2024
1 parent bb14b33 commit 36e9e27
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ members = [".", "macros"]
license = "MIT"
readme = "README.md"
repository = "https://github.com/vidhanio/serenity-commands"
version = "0.5.0"
version = "0.5.1"

[workspace.dependencies]
serenity-commands-macros = { version = "0.5", path = "macros" }
Expand Down
31 changes: 25 additions & 6 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,23 +548,42 @@ fn documentation_string(
spanned: &impl Spanned,
acc: &mut Accumulator,
) -> LitStr {
let res = attrs
let mut doc_comments = attrs
.iter()
.find_map(|attr| match &attr.meta {
.filter_map(|attr| match &attr.meta {
Meta::NameValue(MetaNameValue {
path,
value:
Expr::Lit(ExprLit {
lit: Lit::Str(s), ..
}),
..
}) if path.is_ident("doc") => Some(LitStr::new(s.value().trim(), s.span())),
}) if path.is_ident("doc") => Some((s.span(), s.value())),
_ => None,
})
.ok_or_else(|| {
.peekable();

let res = if doc_comments.peek().is_none() {
Err(
Error::custom("missing documentation comment (`///`) to use as description")
.with_span(spanned)
});
.with_span(spanned),
)
} else {
let (span, s) = doc_comments.fold(
(Span::call_site(), String::new()),
|(span, mut acc), (_, s)| {
if !acc.is_empty() {
acc.push(' ');
}

acc.push_str(s.trim());

(span, acc)
},
);

Ok(LitStr::new(&s, span))
};

acc.handle(res)
.unwrap_or_else(|| LitStr::new("", Span::call_site()))
Expand Down

0 comments on commit 36e9e27

Please sign in to comment.