-
Notifications
You must be signed in to change notification settings - Fork 115
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: Add functionality to export doc strings on types #187
Conversation
Concept ACK. Would love to see this merged |
Thanks for the PR! |
Hey @NyxCode! What are those minor problems? I can take a look when I have time if you want |
oh, seems like i didnt submit the review, sorry. |
No problem, I have also done that with a couple PRs lol |
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.
These are the notable changes I made on top of what @NyxCode asked
attrs | ||
.into_iter() | ||
.filter_map(|a| match a.meta { | ||
Meta::NameValue(ref x) if x.path.is_ident("doc") => Some(x), | ||
_ => None, | ||
}) | ||
.map(|attr| match attr.value { | ||
Expr::Lit(ExprLit { | ||
lit: Lit::Str(ref str), | ||
.. | ||
}) => Ok(str.value()), | ||
_ => syn_err!(attr.span(); "doc attribute with non literal expression found"), | ||
}) | ||
.collect::<Result<Vec<_>>>() |
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.
Managed to get rid of those panic!
s
@@ -116,6 +116,24 @@ pub fn parse_serde_attrs<'a, A: TryFrom<&'a Attribute, Error = Error>>( | |||
.into_iter() | |||
} | |||
|
|||
/// Return a vector of all lines of doc comments in the given vector of attributes. | |||
pub fn parse_docs(attrs: &[Attribute]) -> Result<Vec<String>> { |
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.
Always prefer &[T]
over &Vec<T>
Hi, First of all, thanks for refactoring the code and solving problems! Note: I made a commit I then realized was unnecessary, because the I believe it is possible to also add docs for struct fields and enum variants... (#188) |
Okay, I tried to implement docs for fields+variants as well.. But there were several complications that we need to resolve, I'd like to ask for your help doing that / making the right decisions. I have committed these changes to a separate branch and opened a new PR #228 for that. I suggest implementing this PR first / implementing the docs for fields/variants in that new PR. Thanks again for the help/coop! |
I think struct fields shouldn't be too dificult, but we have to make sure to handle Enum variants are a whole other beast though. They are represented as a type union of the different variants and there is no convenient way to add docs for specific type union members in TS. We could implement #86 and document each variant type, but at the end of the day, we'd do |
Definetly another PR, creating #228 was a good call
Agreed, since all the changes requested have already been made, I will merge this PR now |
Overview
I added functionality (and tests) to export doc strings on exported types.
Example
is exported as
How
This is achieved by parsing the
Vec<Attribute>
of an the exported typeItem
by filtering for"doc"
, and then passing that data down to theexport
layer wheregenerate_decl
prepends the doc string before the export definition in TypeScript.Comments
type_def
function which is used both for exported types and field types.include_str
doc comments or other "doc formats".Related
#52
#102