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

Extract documentation #1536

Merged
merged 39 commits into from
Jun 3, 2020
Merged

Extract documentation #1536

merged 39 commits into from
Jun 3, 2020

Conversation

kritzcreek
Copy link
Contributor

@kritzcreek kritzcreek commented May 22, 2020

This PR adds a documentation generator in the form of a mo-doc binary.

Usage

Running mo-doc --source <src_dir> --output <out_dir> --format<html|adoc|plain> will generate documentation for all .mo files within src_dir and output it into out_dir. It mirrors the file structure and outputs documentation in the specified format.

By default mo-doc will generate documentation from src/ into docs/ using the html format.

For example, running these commands inside motoko-base

$ mo-doc
$ firefox docs/List.html

yields
grafik

Comment syntax

mo-doc recognizes two forms of documentation comments:

/// starts a line comment (Notice the trailing space!)
/** starts a block comment

Ideally I'd like to not support block comments because dealing with indentation is awkward and hard to explain to users, but for now it's recognized so I can demonstrate it working on the current base library.

Documentation comments are parsed as Markdown for the HTML format and copied verbatim when emitting Asciidoc. I didn't want to write a Markdown -> Asciidoc conversion here, because I think we should special case the base library as little as possible and instead work towards tooling that works on all Motoko libraries.

Recognized declarations

Documentation is generated for all public module level types, values, functions and classes as well as their members.

The tool also recognizes leading documentation comments describing the purpose of the module and serving as an introduction. Those module level documentation comments must be placed before the import section.

When writing documentation for functions one has the option of choosing between a let-binding and a func declaration, which either makes the generated documentation:

public let isNil : <T>(List<T>) -> Bool

Returns true if the list is empty.

or

public func isNil<T>(l : List<T>) : Bool

Returns true if the list is empty.

depending on whether one would like the argument names to show up. In future versions using the func declaration will also allow documenting the individual arguments.

Cross-Referencing

Right now the HTML renderer emits ids for all declarations that can be referenced using Markdown syntax:

[Local reference to List.filter](#value.filter)
[Relative reference to Array.map](Array.html#value.map)

I intend to add an understanding about packages, so we can also reference identifiers across those.
None of the types in type signature are references yet, I plan on making them links in a follow-up PR.

Features not in this PR (that I'd like to implement in the future)

  • Parse and typecheck Motoko code blocks in comments
  • ToC/Navigation
  • A documentation page for the primitive types
  • Hyperlinks in all type signatures
  • Documentation for record and variant fields in type declarations
  • A few markdown extensions (like safe inline HTML)
  • Syntax coloring for Motoko code blocks in the markdown

@dfinity-ci
Copy link

This PR does not affect the produced WebAssembly code.

@kritzcreek kritzcreek force-pushed the christoph/extract-documentation branch from 40871f5 to b45bb08 Compare May 28, 2020 10:14
@kritzcreek kritzcreek marked this pull request as ready for review May 29, 2020 17:12
@kritzcreek kritzcreek changed the title [WIP] Extract documentation Extract documentation May 29, 2020
src/docs/plain.ml Outdated Show resolved Hide resolved
src/docs/plain.ml Outdated Show resolved Hide resolved
| Class class_doc ->
bprintf buf "Class %s\n========\nbegin class %s" class_doc.name
class_doc.name;
sep_by' buf "<" ", " ">" (plain_of_typ_bind buf) class_doc.type_args;
Copy link
Contributor

Choose a reason for hiding this comment

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

suppress scope type parameter & what about the sort?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suppressed scope parameters but I'll need a refresher on where those obj/func_sort 's go and which are the defaults/which need to be displayed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Roughly: but look at type pretty printer for inspiration.
T.Local -> default
T.Shared T.Write pat-> shared
T.Shared T.Query pat-> shared query

T.Actor -> 'actor'
T.Module -> 'module'
T.Object -> default

Copy link
Contributor Author

@kritzcreek kritzcreek Jun 2, 2020

Choose a reason for hiding this comment

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

Allright, should be fixed. (My main question was where the obj sort goes for classes, but I went with before the class so we'd get actor class ... (Does module class .... ever make sense?)

Copy link
Contributor

Choose a reason for hiding this comment

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

module class makes some sense but don't know how useful it is since we don't have open type definitions.

Copy link
Contributor

@crusso crusso left a comment

Choose a reason for hiding this comment

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

Some minor things to fix.

You probably don't need to fix the scope parameter issue to produce doc for the Motoko-base, so feel free to do that in a separate PR if easier (or bored with this)

@kritzcreek kritzcreek force-pushed the christoph/extract-documentation branch from 4ceca29 to be72ca2 Compare June 2, 2020 08:01
@kritzcreek
Copy link
Contributor Author

Allright, I think that should be all the comments adressed, PTAL. (And thank you for the thorough review!)

@kritzcreek kritzcreek force-pushed the christoph/extract-documentation branch from 60f791f to 8b23d95 Compare June 3, 2020 06:46
@kritzcreek kritzcreek added the automerge-squash When ready, merge (using squash) label Jun 3, 2020
@mergify mergify bot merged commit 489f1ad into master Jun 3, 2020
@mergify mergify bot deleted the christoph/extract-documentation branch June 3, 2020 12:53
@mergify mergify bot removed the automerge-squash When ready, merge (using squash) label Jun 3, 2020
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