Skip to content

Copy doc comments from Rust to JS #265

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

Merged
merged 14 commits into from
Jun 15, 2018
Merged

Copy doc comments from Rust to JS #265

merged 14 commits into from
Jun 15, 2018

Conversation

FreeMasen
Copy link
Contributor

Addresses #57

Still to do:

  • add tests
  • add new example to travis test script

optional additions

  • Add comments to .ts file
  • Add type annotations for jsdoc comments
    • @param {*} [name]
    • @returns {*}

@fitzgen
Copy link
Member

fitzgen commented Jun 12, 2018

@FreeMasen let me know when this is ready for review!

@FreeMasen
Copy link
Contributor Author

@fitzgen This is ready for review.

Let me know if you would like the additional 2 items I listed above

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much @FreeMasen! This is a super valuable feature.

In the future, if you're going to split up the PR into many commits, it would help me as a reviewer if the commits had descriptive messages and each commit logically did one thing. If it is too hard to split up logically like that, then it is easier for me if everything is one commit (although nice commit messages are still preferred!)

I have a couple nitpicks below, and once they're addressed, then we can merge this.

Thanks again!

None
}
})
.fold(vec![], |mut acc, a| {acc.extend(a); acc});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a call to extract_doc_comments, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, this has been updated

.iter()
.filter_map(|a| {
//We only care about outer comments for now
if a.style == AttrStyle::Outer {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this also check that the attributes are doc? It seems to me that this will collect non-doc attributes as well, which we don't want.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I am pretty new at using syn/proc-macro2, I updated this to check the path segments for a "doc" Ident instead of just capturing outer attributes. Let me know if you know of a better way to differentiate doc comment attributes.

@@ -1072,3 +1105,24 @@ fn replace_self(name: &Ident, item: &mut syn::ImplItem) {

syn::visit_mut::VisitMut::visit_impl_item_mut(&mut Walk(name), item);
}
/// Extract the documentation comments from a Vec of attributes
fn extract_doc_comments(attrs: &Vec<syn::Attribute>) -> Vec<String> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this needs to take &Vec<syn::Attribute> rather than &[syn::Attribute]? If not, then we should switch to the latter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is not reason, just updated it

@@ -0,0 +1 @@
# TODO
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fill this out :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I think this was from an older commit it does have content.

p.gen_bindings(&root, &target);
let js = p.read_js();
let comments = extract_doc_comments(&js);
///
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there supposed to be something here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, not sure how this got there, it has been removed. I also updated the test to handle white-space a little better

@FreeMasen
Copy link
Contributor Author

I believe I have addressed all of you comments. Sorry about the commits, I will work on trying to break them apart a little better moving forward or just squash them all down.

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @FreeMasen !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants