-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(doc): add support for @custom:variant documentation for enums #9905
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,7 +229,26 @@ impl AsDoc for Document { | |
writer.write_subtitle("Enums")?; | ||
enums.into_iter().try_for_each(|(item, comments, code)| { | ||
writer.write_heading(&item.name.safe_unwrap().name)?; | ||
writer.write_section(comments, code) | ||
writer.write_section(comments, code)?; | ||
|
||
let variants: Vec<_> = comments | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't forget to format your code, with |
||
.include_tag(CommentTag::Variant) | ||
.iter() | ||
.filter_map(|c| { | ||
let (name, desc) = c.value.split_once(' ')?; | ||
Some((name.trim().to_string(), desc.trim().to_string())) | ||
}) | ||
.collect(); | ||
if !variants.is_empty() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can add a break line before and after the if statement |
||
writer.writeln()?; | ||
writer.write_bold("Cases:")?; | ||
writer.writeln_raw("| Name | Description |")?; | ||
writer.writeln_raw("|------|-------------|")?; | ||
for (name, desc) in variants { | ||
writer.writeln_raw(&format!("| `{}` | {} |", name, desc))?; | ||
} | ||
} | ||
Ok::<_, std::fmt::Error>(()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think the type needs to be explicit |
||
})?; | ||
} | ||
} | ||
|
@@ -273,7 +292,29 @@ impl AsDoc for Document { | |
writer.write_section(&item.comments, &item.code)?; | ||
writer.try_write_errors_table(&err.fields, &item.comments)?; | ||
} | ||
ParseSource::Variable(_) | ParseSource::Enum(_) | ParseSource::Type(_) => { | ||
ParseSource::Enum(_) => { | ||
writer.writeln_doc(&item.comments)?; | ||
writer.write_code(&item.code)?; | ||
|
||
let variants: Vec<_> = item.comments | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here for the |
||
.include_tag(CommentTag::Variant) | ||
.iter() | ||
.filter_map(|c| { | ||
let (name, desc) = c.value.split_once(' ')?; | ||
Some((name.trim().to_string(), desc.trim().to_string())) | ||
}) | ||
.collect(); | ||
if !variants.is_empty() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A breakline before the if statement can be appreciate |
||
writer.writeln()?; | ||
writer.write_bold("Cases:")?; | ||
writer.writeln_raw("| Name | Description |")?; | ||
writer.writeln_raw("|------|-------------|")?; | ||
for (name, desc) in variants { | ||
writer.writeln_raw(&format!("| `{}` | {} |", name, desc))?; | ||
} | ||
} | ||
} | ||
ParseSource::Variable(_) | ParseSource::Type(_) => { | ||
writer.write_section(&item.comments, &item.code)?; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every element of this enum is one of the natspec tags defined in the specs here. And
variant
isn't one of them.Instead, is it not possible to parse this as
Custom("variant")
and do the filtering in the writer?