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

Ignore non doc attributes at top level genrated by ppx #819

Merged
merged 3 commits into from Feb 5, 2022

Conversation

jorisgio
Copy link
Contributor

@jorisgio jorisgio commented Feb 4, 2022

Currently, odoc fails to extract synopsis from a signature pre-processed by a ppx. This is because ppx add a "ocaml.ppx.context" attribute at top level before the top comment.
I'm not sure the current fix is the best way to fix, since it uses string matching "ocaml.text" to continue unrolling the list of items until it finds an attribute that is a document.

@@ -139,7 +139,7 @@ let extract_top_comment internal_tags ~classify parent items =
let rec extract ~classify = function
| hd :: tl as items -> (
match classify hd with
| Some (`Attribute attr) -> (
| Some (`Attribute ({ Parsetree.attr_name = { txt = "ocaml.text" ; _ }; _ } as attr)) -> (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Matching this is already the responsibility of parse_attribute. I think what you mean is to change the None case below to continue iterating rather than stopping.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed - nice find though!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, i missed that. Thanks !

@jorisgio jorisgio force-pushed the extract_top_comment_from_ppx_files branch from eed0688 to 03b4dc5 Compare February 4, 2022 14:33
Copy link
Collaborator

@Julow Julow left a comment

Choose a reason for hiding this comment

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

There's some documentation about this in doc/odoc_for_authors.mld in section top_comment that should be updated (where it talks about the exception for open statements).

Otherwise the code looks good.

@jorisgio
Copy link
Contributor Author

jorisgio commented Feb 4, 2022

where it talks about the exception for open statements
I'm not sure i understand what you mean

@Julow
Copy link
Collaborator

Julow commented Feb 4, 2022

I mean that there's documentation about what is "ignored" at the beginning of a file in doc/odoc_for_authors.mld at line 579. It should be updated to mention that it also ignores attributes.

@jonludlam
Copy link
Member

We could also do with a CHANGES entry.

@jonludlam jonludlam merged commit 8964ebb into ocaml:master Feb 5, 2022
jonludlam pushed a commit that referenced this pull request Feb 5, 2022
@jonludlam
Copy link
Member

Thanks @jorisgio !

jonludlam added a commit to jonludlam/opam-repository that referenced this pull request Feb 8, 2022
CHANGES:

Additions
- New subcommand to resolve references (@panglesd, @lubega-simon, ocaml/odoc#812)
- Improved rendering of long signatures (@panglesd, ocaml/odoc#782)
- Handle comments attached to open statement as floating comment, instead
  of dropping them (@panglesd, ocaml/odoc#797)
- Empty includes (containing entirely shadowed entries) are now hidden (@panglesd, ocaml/odoc#798)

Bugs fixed
- Fix a missing Result constructor during compile. This will cause some
  functor arguments to have different filenames (@jonludlam, ocaml/odoc#795)
- Better memory/disk space usage when handling module alias chains (@jonludlam, ocaml/odoc#799)
- Resolving class-type paths (ie., `val x : #c`) (@jonludlam, ocaml/odoc#809)
- Skip top-level attributes while extracting the top comment. Fix top-comment extraction with PPX preprocessing (@jorisgio, ocaml/odoc#819)
- Better handling of @canonical tags (@jonludlam, ocaml/odoc#820)
- css: improved layout (@jonludlam, @Julow, ocaml/odoc#822)
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.

None yet

3 participants