Skip to content
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

IDL Doc Field #1561

Merged
merged 29 commits into from
Apr 21, 2022
Merged

IDL Doc Field #1561

merged 29 commits into from
Apr 21, 2022

Conversation

ebrightfield
Copy link
Contributor

Adds a new, optional doc field to several of the IDL structs. The program module, instruction functions, and account structs are searched for inner doc comments (this is intended to minimize intrusion on existing programs, which likely use outer doc comments on those elements). IxArg and IdlField also will grab their associated doc comment.

The doc field is not included in the IDL JSON in cases when it parses to None.

Todo:

  • Someone already got close with adding a docs field to the AccountField, it just needs wiring up.
  • Considering a command-line flag to suppress inclusion of doc fields in anchor idl parse.

@ebrightfield ebrightfield changed the title Draft PR -- IDL Doc Field IDL Doc Field Mar 6, 2022
@paul-schaaf
Copy link
Contributor

hey @ebrightfield I would like to get this into the next release. Do you have time to finish this or do you want me to take over?

  • We can include outer comments in the IDL too. But we should include a feature like tom did in his PR lang: Parse instruction doc comments into description fields in IDL #1546 I suggest we make this an anti-feature though. So it's enabled by default and the feature turns it off.
  • agree that a flag to supress docs in anchor idl parse would be good
  • Please also have a look at tom's PR regarding the tests

@ebrightfield
Copy link
Contributor Author

@paul-schaaf Awesome! I can knock it out tomorrow.

To reiterate, action items are:

@paul-schaaf
Copy link
Contributor

great!

To reiterate, action items are:

yup!

thanks! @ebrightfield

@ebrightfield
Copy link
Contributor Author

@paul-schaaf just took care of everything, or nearly. Unsure how best to automate testing the anchor idl parse --no-doc, and turning on/off the no_docs feature (they work when I manually test). The rest of the feature has accompanying Typescript tests in the same fashion as Tom's PR.

Also, took the liberty of skipping over the CHECK doc strings during parsing.

@paul-schaaf
Copy link
Contributor

On second thought, I think we don't need the feature.

It seems like features are most useful if your code changes depending on whether your code would change depending on whether it's turned off or on. This isn't the case here, so I think that having a flag on the build command is good enough.

@paul-schaaf
Copy link
Contributor

Also, took the liberty of skipping over the CHECK doc strings during parsing.

sounds good!

@ebrightfield
Copy link
Contributor Author

Okay, feature removed.

Any ideas on how best to automate test of anchor idl parse --no-doc?

Also, should --no-doc also be an option on anchor build?

@paul-schaaf
Copy link
Contributor

Also, should --no-doc also be an option on anchor build?

yes that is what I meant by flag on build

Any ideas on how best to automate test of anchor idl parse --no-doc?

Manual testing is fine. Not critical if it doesn't work.

  • I think it would be easier to parse the idl doc field if it was an array of the lines instead of a space separated list
  • also pls move the tests into their own program inside the misc workspace and have them run as a separate test suite. Once you merge master and fix the conflicts, you'll be able to see 2 test suites in misc already that you can check out for how to do it

@ebrightfield
Copy link
Contributor Author

ebrightfield commented Apr 18, 2022

Okay, --no-doc added to build and publish commands. And doc fields are Option<Vec<String>> instead of Option<String> now.

After merging, I created a dedicated program for testing under tests/misc/programs/idl_doc, and I emulated the structure of the rest of the misc tests on master, although I am too much of a newbie with JS tooling and could not figure out how they're supposed to get executed.

Edit: Got tests working. Should be good to go.

@paul-schaaf
Copy link
Contributor

paul-schaaf commented Apr 19, 2022

what's the need for --no-doc for publish? I can see there's a call to build in the publish code but I think thats only used to check whether compilation succeeded, so it doesn't matter if there are docs generated or not.

@ebrightfield
Copy link
Contributor Author

Ah, got it. Wasn't sure about that one. Just removed it from the publish command.

@@ -494,6 +499,8 @@ pub struct CompositeField {
pub instruction_constraints: ConstraintGroup,
pub symbol: String,
pub raw_field: syn::Field,
/// IDL Doc comment
pub doc: Option<Vec<String>>,
/// Documentation string.
pub docs: String,
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like there already has been code to parse docs before your PR that was saved in this docs var. That code can be deleted now and the var too.

Although I think docs is the more common name so it would make sense to me to use docs everywhere instead of doc

Copy link
Contributor Author

@ebrightfield ebrightfield Apr 21, 2022

Choose a reason for hiding this comment

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

Sounds good, renamed to docs across the board (including no_doc --> no_docs where applicable.

Removal of the older docs var caused a few compile errors in lang/syn/src/codegen/accounts/__*.rs. Unsure how best to proceed on those. Appears to be formatting the string back into source code.

Edit: For now, I just decided to convert the is_empty check to an if let Some(docs) = s.docs, and construct the TokenStream by iterating over the doc strings.

@paul-schaaf
Copy link
Contributor

paul-schaaf commented Apr 21, 2022

@ebrightfield is there anything else that youre about to push or can I merge now?

@ebrightfield
Copy link
Contributor Author

I'm satisfied, go for it.

@paul-schaaf paul-schaaf merged commit ed15922 into coral-xyz:master Apr 21, 2022
@paul-schaaf
Copy link
Contributor

thanks for the contribution!

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