-
-
Notifications
You must be signed in to change notification settings - Fork 418
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
docgen: ingore test types and only document public types by default #2112
Conversation
Open questions
|
src/libponyc/pass/docgen.c
Outdated
// Define options for doc generation | ||
typedef struct docgen_opt_t | ||
{ | ||
bool include_private; |
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 should only be indented 2 spaces.
src/libponyc/pass/docgen.c
Outdated
static void doc_type_list(docgen_t* docgen, ast_t* list, const char* preamble, | ||
const char* separator, const char* postamble, bool generate_links, bool line_breaks); | ||
static void doc_type_list(docgen_t* docgen, docgen_opt_t* docgen_opt, ast_t* list, | ||
const char* preamble, const char* separator, const char* postamble, |
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.
to keep formatting consistent the formatting here should be 2 spaces
src/libponyc/pass/docgen.c
Outdated
@@ -291,7 +343,8 @@ static const char* doc_get_cap(ast_t* cap) | |||
|
|||
|
|||
// Write the given type to the current type file | |||
static void doc_type(docgen_t* docgen, ast_t* type, bool generate_links) | |||
static void doc_type(docgen_t* docgen, docgen_opt_t* docgen_opt, | |||
ast_t* type, bool generate_links) |
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.
2 space indent only
src/libponyc/pass/docgen.c
Outdated
// and if the type not private if we exclude private types. | ||
const char* type_id_name = ast_name(id); | ||
if(generate_links && *type_id_name != '$' | ||
&& (docgen_opt->include_private || !is_name_private(type_id_name))) |
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.
formatting
src/libponyc/pass/docgen.c
Outdated
const char* separator, const char* postamble, bool generate_links, bool line_breaks) | ||
static void doc_type_list(docgen_t* docgen, docgen_opt_t* docgen_opt, ast_t* list, | ||
const char* preamble, const char* separator, const char* postamble, | ||
bool generate_links, bool line_breaks) |
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.
formatting
src/libponyc/pass/docgen.c
Outdated
|
||
|
||
// Functions to handle everything else | ||
|
||
// Write the given list of fields to the current type file. | ||
// The given title text is used as a section header. | ||
// If the field list is empty nothing is written. | ||
static void doc_fields(docgen_t* docgen, ast_list_t* fields, const char* title) | ||
static void doc_fields(docgen_t* docgen, docgen_opt_t* docgen_opt, ast_list_t* fields, const char* title) |
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 should be wrapped so its no more than 80 columns
src/libponyc/pass/docgen.c
Outdated
fprintf(docgen->type_file, "\n\n---\n\n"); | ||
} | ||
} | ||
|
||
|
||
// Write the given list of type parameters to the current type file, with | ||
// surrounding []. If the given list is empty nothing is written. | ||
static void doc_type_params(docgen_t* docgen, ast_t* t_params, | ||
static void doc_type_params(docgen_t* docgen, docgen_opt_t* docgen_opt, ast_t* t_params, |
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 should be wrapped at 80 columns
src/libponyc/pass/docgen.c
Outdated
@@ -550,7 +580,8 @@ static void doc_type_params(docgen_t* docgen, ast_t* t_params, | |||
|
|||
// Write the given list of parameters to the current type file, with | |||
// surrounding (). If the given list is empty () is still written. | |||
static void code_block_doc_params(docgen_t* docgen, ast_t* params) | |||
static void code_block_doc_params(docgen_t* docgen, docgen_opt_t* docgen_opt, | |||
ast_t* params) |
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.
only indent 2
src/libponyc/pass/docgen.c
Outdated
@@ -592,7 +623,8 @@ static void code_block_doc_params(docgen_t* docgen, ast_t* params) | |||
fprintf(docgen->type_file, ")"); | |||
} | |||
|
|||
static void list_doc_params(docgen_t* docgen, ast_t* params) | |||
static void list_doc_params(docgen_t* docgen, docgen_opt_t* docgen_opt, | |||
ast_t* params) |
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.
formatting
src/libponyc/pass/docgen.c
Outdated
@@ -636,7 +668,8 @@ static void list_doc_params(docgen_t* docgen, ast_t* params) | |||
} | |||
|
|||
// Write a description of the given method to the current type file | |||
static void doc_method(docgen_t* docgen, ast_t* method) | |||
static void doc_method(docgen_t* docgen, docgen_opt_t* docgen_opt, | |||
ast_t* method) |
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.
formatting
src/libponyc/pass/docgen.c
Outdated
doc_type_params(docgen, tparams, false); | ||
doc_type_list(docgen, provides, " is\n ", ",\n ", "", false, false); | ||
doc_type_params(docgen, docgen_opt, tparams, false); | ||
doc_type_list(docgen, docgen_opt, provides, " is\n ", ",\n ", "", false, false); |
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 should be wrapped to 80
src/libponyc/pass/docgen.c
Outdated
break; | ||
|
||
case TK_BE: | ||
doc_list_add_named(&pub_bes, p, 1, true, false); | ||
doc_list_add_named(&priv_bes, p, 1, false, true); | ||
doc_list_add_named(&priv_bes, p, 1, false, docgen_opt->include_private); |
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.
should wrap to 80
src/libponyc/pass/docgen.c
Outdated
break; | ||
|
||
case TK_FUN: | ||
doc_list_add_named(&pub_funs, p, 1, true, false); | ||
doc_list_add_named(&priv_funs, p, 1, false, true); | ||
doc_list_add_named(&priv_funs, p, 1, false, docgen_opt->include_private); |
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.
should wrap to 80
src/libponyc/pass/docgen.c
Outdated
t, | ||
0, | ||
true, | ||
docgen_opt->include_private |
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.
formatting
src/libponyc/pass/docgen.c
Outdated
docgen->public_types = NULL; | ||
docgen->private_types = NULL; | ||
} | ||
|
||
|
||
// Document the packages in the given program | ||
static void doc_packages(docgen_t* docgen, ast_t* ast) | ||
static void doc_packages(docgen_t* docgen, docgen_opt_t* docgen_opt, ast_t* ast) |
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.
should wrap to 80
src/libponyc/pass/docgen.c
Outdated
for(ast_list_t* p = packages.next; p != NULL; p = p->next) { | ||
const char* p_name = package_qualified_name(p->ast); | ||
if (!is_package_for_testing(p_name)) { | ||
doc_package(docgen, docgen_opt, p->ast); |
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.
too much indentation
src/libponyc/pass/docgen.c
Outdated
|
||
for(ast_list_t* p = packages.next; p != NULL; p = p->next) | ||
doc_package(docgen, p->ast); | ||
for(ast_list_t* p = packages.next; p != NULL; p = p->next) { |
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.
{ goes on next line
src/libponyc/pass/docgen.c
Outdated
doc_package(docgen, p->ast); | ||
for(ast_list_t* p = packages.next; p != NULL; p = p->next) { | ||
const char* p_name = package_qualified_name(p->ast); | ||
if (!is_package_for_testing(p_name)) { |
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.
{ goes on next line
src/libponyc/pass/docgen.c
Outdated
doc_package(docgen, p->ast); | ||
for(ast_list_t* p = packages.next; p != NULL; p = p->next) { | ||
const char* p_name = package_qualified_name(p->ast); | ||
if (!is_package_for_testing(p_name)) { |
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.
no space between if and (
src/ponyc/main.c
Outdated
@@ -120,6 +122,8 @@ static void usage() | |||
" --runtimebc Compile with the LLVM bitcode file for the runtime.\n" | |||
" --pic Compile using position independent code.\n" | |||
" --docs, -g Generate code documentation.\n" | |||
" --docs-private Generate code documentation for private types\n" |
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.
what happens if this is used without --docs ?
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.
nothing, at the moment.
The compiler just does its passes (like it would do without).
I will ad a stance about it to the help string and add a warning output that it will be ignored.
Other possibility is to model this switch differently, having --docs-public
generating docs for public types only and --docs
generating docs for both, just like --docs
did before.
Now that i think about it, adding --docs-public
looks about right to me. Give me a day to implement the different behavior (and the formatting). :)
@mfelsche thanks for this. there's a lot of code formatting style things to address but they should be quick. everything makes sense to me although, the proof is in the output. i'm assuming you've tested it and get the correct stuff. once the formatting stuff is taken care of i think we can merge this unless someone else see something off. thanks for this! |
@ponylang/committer we really need to document the c-style as well as the pony. |
this includes implementations of TestList and UnitTest as well as classes starting with _Test. This does not exclude packages named test (like builtin/test)
when calling ponyc with --docs option. To enable doc generation for private types, methods and behaviours as well, the flag --docs-private can be used.
otherwise they would show up in generated documentation
to produce public-only docs only when used with --docs-public and create docs for private types as well, when using --docs. This leaves the old behavior untouched.
with 22d9f3c this PR will actually leave the private types inside the stdlib docs. |
The only thing i could add are some tests for properly detecting test and private types during docgen. |
I'm not particularly worried about tests at the moment. Let's have @Praetonus or @jemc give this a once over. It looks good to me but I've had a long day so another set of eyes wouldn't hurt. |
Thanks @mfelsche! |
٩(ˊᗜˋ*)و |
This PR changes the docgen pass (invoked by calling
ponyc --docs
) to ignore all types that are considered to be test related. That is:_Test
TestList
andUnitTest
implementationsbuiltin_test
(static check to filter out stdlib package) ortest
A new command-line flag "--docs-public" is introduced to only generate documentation for public types, behaviors, constructors and methods.
This fixes #2092 and #2089