Reason: Parse and format comments as markdown.

Created on 15 Jun 2018  路  11Comments  路  Source: reasonml/reason

We should parse doc blocks as markdown comments:

  1. Parse docblock comments as MD. Incorporate a lightweight markdown parser that doesn't depend on Oasis.
  2. Make sure they refmt nicely. That means the text portions would wrap, but code samples inside of comments (indented by four spaces or surrounded by tripple backticks) would remain untouched.
  3. Make changes in the Reason PPX to make sure that docbloc comments are represented properly. Currently the ppx attributes include leading stars in them. These show up as ocamldoc lists, which they shouldn't. We should strip the leading stars from the comment text when parsing into ppx attributes. We might also need to convert these comments into ocamldoc format when storing them in the AST - however, I think some of this should be on merlin's end. It could have a "markdown mode", and/or it could even be the one to strip the leading stars.
  4. Ensure the performance of parsing and printing has not regressed much. (Printing could be pretty expensive but that's not terrible since it only happens when reformatting).

cc @let-def about Merlin's end here. Who should be responsible for stripping leading stars from ppx comment attributes? Who should be responsible for converting it from markdown to ocamldoc?

Documentation Parser

All 11 comments

@rgrinberg Why does omd still depend on oasis?

@rrdelaney will look into this (I'll remove this comment if that changes)

I've forked Omd to fix some bugs, and I use it in both redoc and reason-language-server. Given that ocaml's parser doesn't strip leading stars, I don't think reason's should either. Let's have the AST directly represent the code that was written.
When refmt is printing out reason syntax code, then it can do parsing of the docblock so that it can reflow things. But I don't think it should do any doccomment processing one the "parse" side of things.

It would be really cool if markdown code examples within comments were also run through refmt themselves.

Yeah that should be totally doable 馃憦 (again we'd only incur the parsing + processing cost on the "print to reason" side, so compile times shouldn't be impacted)

for the record here's my vendored version of omd https://github.com/jaredly/reason-language-server/tree/master/omd

@bordoley Great idea!

@jaredly: One problem is that right now merlin doesn't know if your ppx attribute doc comments were written in ocamldoc format or markdown format and it assume ocamldoc format so it doesn't strip the leading stars when rendering markdown comments in Atom. What do you suggest doing?

Would it be worth supporting an attribute to specify the format of doc comments? Something like that could be coordinated with the odoc folks.

@jordwalke what I do in my language server is assume it was markdown if it came from a .re(i) file, and assume ocamldoc if it came from a .ml(i). Seems to work quite well

That is probably a pretty accurate heuristic!

I've split this task into two separate ones:

Let us know if anyone wants to help with this one. It will be greatly appreciated.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TrakBit picture TrakBit  路  3Comments

chenglou picture chenglou  路  3Comments

cristianoc picture cristianoc  路  4Comments

modlfo picture modlfo  路  4Comments

rickyvetter picture rickyvetter  路  3Comments