-
Notifications
You must be signed in to change notification settings - Fork 97
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
Extract documentation #1536
Conversation
This PR does not affect the produced WebAssembly code. |
- Generates docs for lets - Generates id's that allow cross-referencing
40871f5
to
b45bb08
Compare
Also switches it to render into a buffer
Treats comments as Markdown in html renderer
src/docs/plain.ml
Outdated
| 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; |
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.
suppress scope type parameter & what about the sort?
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.
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.
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.
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
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.
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?)
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.
module class makes some sense but don't know how useful it is since we don't have open type definitions.
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.
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)
4ceca29
to
be72ca2
Compare
Allright, I think that should be all the comments adressed, PTAL. (And thank you for the thorough review!) |
Adds a heading for every declaration
It's now placed between declaration heading and its signature
60f791f
to
8b23d95
Compare
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 withinsrc_dir
and output it intoout_dir
. It mirrors the file structure and outputs documentation in the specifiedformat
.By default
mo-doc
will generate documentation fromsrc/
intodocs/
using thehtml
format.For example, running these commands inside
motoko-base
yields
Comment syntax
mo-doc
recognizes two forms of documentation comments:///
starts a line comment (Notice the trailing space!)/**
starts a block commentIdeally 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 afunc
declaration, which either makes the generated documentation:or
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:
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)