-
Notifications
You must be signed in to change notification settings - Fork 46
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
Upgrade to Odoc 2.0.0 #333
Conversation
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.
The new API of the parser is still WIP: ocaml/odoc#685
dune-project
Outdated
@@ -35,6 +35,6 @@ | |||
result | |||
(ocaml-version | |||
(>= 2.3.0)) | |||
(odoc (>= 1.4.1)) | |||
(odoc-parser (>= 2.0.0)) |
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.
This makes Mdx incompatible with Odoc 1.5. Odoc 2.0.0 should be fully retrocompatible. The only reason I can think of a user keeping the current version is the change in the output.
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.
This is fixed now. Odoc 1.5 is co-installable with odoc-parser.
Thanks for taking care of this! I haven't looked at the code but there are a couple of high level things I'd like to discuss. My first concern is compatibility with older code. I'd like the behaviour of MDX not to change after this patch, as much as possible. Blocks with no headers should run exactly the same as before. My understanding was that the content between The last point is more of an open quesiton but I'm wondering if we should not use language headers at all in mli files and rely on the |
I agree that this change was a bit out of scope. I'll revert it.
The first word would be the language tag and it might be used for syntax highlighting in the html backend.
Yes, that's what I meant.
That would be great! Do you think we should change the syntax to have the language tag optional to avoid passing informations twice in this case ? We don't have clear plans yet for the language tag, it looked interesting to add because Mdx might use it. |
You're right. I think supporting an optional language tag in odoc, so that it can be used to generate the right, syntax highlighted HTML is a perfectly valid reason to allow adding language tag to code blocks. I think it should be optional indeed, both for compatibility reasons and because sometimes there might be blocks we don't know how to highlight and for which there isn't really a point in adding a language tag but where you might still want to add headers. For example, an MDX file include block that's importing the content of a text file. I think the Regarding simple blocks and MDX, if I remember correctly, the current behaviour is that blocks are inspected: if they follow the toplevel blocks syntax, they are evaluated by MDX, otherwise they are simply ignored. I think we should preserve this with this patch. The good news is that now, users are able to add a This all looks really promising, I'm fairly excited to get that out! Let me know if there's anything I can do to help with this on either sides (MDX or odoc)! |
Thanks for looking this over @NathanReb! I'm curious about the problems you encountered with the language tag? I can't immediately see a useful difference between |
In Markdown, the language tag is used for markdown interpeters to generate the styling for the code blocks. MDX used this information to infer how to interpret the content of the block, along with the syntax of the block content itself but it has not strong semantic meaning. There are 4 different ways to interpret a block for MDX:
For example, the first 3 blocks can contain OCaml code, or something you'd want to style as OCaml code. The language tag is too ambiguous on its own and MDX can't rely on that only to find out how to interpret the block. At some point it will have to make a guess, which might differ from what the user wanted. This guess will affect how MDX report errors and it can lead to a great deal of confusion when MDX and the user had different expectations for that block. Another issue with this is that, atm, toplevel blocks have a different syntax than the raw OCaml one, and can't be styled the same way. In short, the block type and the language tag are two different piece of information, used for different purposes and this is why I believe they should be handled differently. For compat reasons, we'll maintain that behaviour in markdown files but we'd like to encourage our users to slowly migrate to the prefered block kind approach. If I can avoid doing the same mistakes in mli files from the start, I would much rather do that! |
Does this mean that if a block is |
I think this PR should be split - one PR to switch to odoc-parser (with no support of code-block metadata) and a follow up with the rest of the changes. |
@jonludlam this definitely sounds sensible! |
The parser is released, I updated this PR and removed the commit about the metadata field, it is ignored for now. |
end of "[**", but doesn't add those three characters to the within-the-file column | ||
number. Here, we make the adjustment. | ||
*) | ||
let account_for_docstring_open_token (location : Odoc_model.Location_.span) = |
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.
The parser now keeps the location :)
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.
I talked too fast. This is still needed, an other force-push.
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.
I debugged this a bit more and found that there is no bug into odoc-parser but rather that it expects the starting location to account for the comment opening. That's how odoc does it: https://github.com/ocaml/odoc/blob/master/src/loader/doc_attr.ml#L56
I pushed a fix.
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.
Indeed, as described here: https://ocaml-doc.github.io/odoc-parser/Odoc_parser/index.html#val-parse_comment
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.
Thanks! This looks great!
I have a minor comment but otherwise it all looks good to me.
Could you add a changelog entry? In theory it shouldn't matter as the behaviour is expected to remain the same but I think it's good to mention it, just in case we uncover bugs or changes in the future. I'll cut a release with this straight after we merge!
You mentioned a required bug fix on the odoc-parser side, has it been released? If so we can fix that module alias thing and merge!
Ouh also, could you please rebase on top of master so the 4.13 build succeeds? |
I don't think there was a bug fix required for |
Remove the extra step of correcting locations by padding it before.
Rebased, changelog update and alias removed. Good to merge for me. |
It appears the opam file isn't up to date anymore with what dune generates, I'll push the update! |
Signed-off-by: Nathan Rebours <[email protected]>
This is due to the master branch updating the dune lang version! |
Okay, let's merge this! Huge thanks to both of you @Julow @jonludlam for taking care of this! |
CHANGES: #### Added #### Changed - Use odoc-parser.0.9.0 (realworldocaml/mdx#333, @Julow) #### Deprecated - Add a deprecation warning for toplevel blocks that are not terminated with `;;` (realworldocaml/mdx#342, @Leonidas-from-XIV) #### Fixed - Fix accidental redirect of stderr to stdout (realworldocaml/mdx#343, @Leonidas-from-XIV) - Remove trailing whitespaces that were added to indent empty lines (realworldocaml/mdx#341, @gpetiot) #### Removed #### Security
In Odoc 2.0.0 (which is not released yet), the parser will be packaged separately and the API will change slightly. The API might change a bit again, I'll update this PR accordingly.
An other change is the "metadata" field, allowing to attach informations on every code blocks:
{@ocaml labels... [ ... ]}
This PR updates the code to work with the new version and handle the metadata field.
An other change in this PR is that code blocks without header are no longer run. Existing code blocks that were running before need to be changed. Perhaps this change is out of scope and should be removed ?