-
-
Notifications
You must be signed in to change notification settings - Fork 120
fix(graindoc): Add all function parameters to the table, even if missing documentation #2293
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -396,46 +396,50 @@ let for_value_description = | |
| }; | ||
|
|
||
| let documented_args = | ||
| switch (args) { | ||
| | None => [] | ||
| | Some(function_args) => | ||
| List.mapi( | ||
| (index, (lab, exp)) => { | ||
| let param_id = | ||
| switch (lab) { | ||
| | Typedtree.Labeled(l) | ||
| | Default(l) => l.txt | ||
| | _ => string_of_int(index) | ||
| }; | ||
|
|
||
| // First try to match by name, then by position | ||
| let matched = | ||
| switch (match_label_to_arg(param_id)) { | ||
| | Some(_) as result => result | ||
| | None => match_label_to_arg(string_of_int(index)) | ||
| }; | ||
|
|
||
| // Extract documentation from the matched attribute | ||
| let documentation = | ||
| switch (matched) { | ||
| | Some((_, Comment_attributes.Param({attr_desc}))) => attr_desc | ||
| | _ => "" | ||
| }; | ||
|
|
||
| // Get parameter type | ||
| let param_type = | ||
| switch (lookup_arg_by_label(param_id, args)) { | ||
| | Some((Labeled(_), typ)) => Printtyp.string_of_type_sch(typ) | ||
| | Some((Default(_), {desc: TTyConstr(_, [typ], _)})) => | ||
| Printtyp.string_of_type_sch(typ) | ||
| | Some((_, typ)) => Printtyp.string_of_type_sch(typ) | ||
| | None => "" | ||
| }; | ||
|
|
||
| {param_id, param_type, param_msg: documentation}; | ||
| }, | ||
| function_args, | ||
| ) | ||
| switch (param_attributes) { | ||
| | [] => [] // no documented params so don't add to the table | ||
| | _ => | ||
| switch (args) { | ||
| | None => [] | ||
| | Some(function_args) => | ||
| List.mapi( | ||
| (index, (lab, exp)) => { | ||
| let param_id = | ||
| switch (lab) { | ||
| | Typedtree.Labeled(l) | ||
| | Default(l) => l.txt | ||
| | _ => string_of_int(index) | ||
| }; | ||
|
|
||
| // First try to match by name, then by position | ||
| let matched = | ||
| switch (match_label_to_arg(param_id)) { | ||
| | Some(_) as result => result | ||
| | None => match_label_to_arg(string_of_int(index)) | ||
| }; | ||
|
|
||
| // Extract documentation from the matched attribute | ||
| let documentation = | ||
| switch (matched) { | ||
| | Some((_, Comment_attributes.Param({attr_desc}))) => attr_desc | ||
| | _ => "" | ||
| }; | ||
|
|
||
| // Get parameter type | ||
| let param_type = | ||
| switch (lookup_arg_by_label(param_id, args)) { | ||
| | Some((Labeled(_), typ)) => Printtyp.string_of_type_sch(typ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: We could use an |
||
| | Some((Default(_), {desc: TTyConstr(_, [typ], _)})) => | ||
| Printtyp.string_of_type_sch(typ) | ||
| | Some((_, typ)) => Printtyp.string_of_type_sch(typ) | ||
| | None => "" | ||
| }; | ||
|
|
||
| {param_id, param_type, param_msg: documentation}; | ||
| }, | ||
| function_args, | ||
| ) | ||
| } | ||
| }; | ||
|
|
||
| let (deprecations, since, history, params, returns, throws, examples) = | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| --- | ||
| title: Params | ||
| --- | ||
|
|
||
| ## Values | ||
|
|
||
| Functions and constants included in the Params module. | ||
|
|
||
| ### Params.**test1** | ||
|
|
||
| ```grain | ||
| test1: (a: Number, b: Number) => Number | ||
| ``` | ||
|
|
||
| Parameters: | ||
|
|
||
| |param|type|description| | ||
| |-----|----|-----------| | ||
| |`a`|`Number`|This is the first| | ||
| |`b`|`Number`|This is the second| | ||
|
|
||
| ### Params.**test2** | ||
|
|
||
| ```grain | ||
| test2: (a: Number, b: Number) => Number | ||
| ``` | ||
|
|
||
| Parameters: | ||
|
|
||
| |param|type|description| | ||
| |-----|----|-----------| | ||
| |`a`|`Number`|| | ||
| |`b`|`Number`|This is the third| | ||
|
|
||
| ### Params.**test3** | ||
|
|
||
| ```grain | ||
| test3: (a: Number, b: Number, c: Number) => Number | ||
| ``` | ||
|
|
||
| Parameters: | ||
|
|
||
| |param|type|description| | ||
| |-----|----|-----------| | ||
| |`a`|`Number`|This is the first| | ||
| |`b`|`Number`|This is the third| | ||
| |`c`|`Number`|| | ||
|
|
||
| ### Params.**test4** | ||
|
|
||
| ```grain | ||
| test4: (a: Number, b: Number, c: Number, a) => Number | ||
| ``` | ||
|
|
||
| Parameters: | ||
|
|
||
| |param|type|description| | ||
| |-----|----|-----------| | ||
| |`a`|`Number`|This is the a| | ||
| |`b`|`Number`|This is the b| | ||
| |`c`|`Number`|| | ||
| |`3`|``|This is the 3| | ||
|
|
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also test a function without the params documented at all, and an only positional argument. We might also want to test the failing cases, i.e a param doesn't exist.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right. Every other test covered this case as they all have undocumented params so I use those as my test case, but an explicit one would be better |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| module Params | ||
|
|
||
| /** | ||
| * @param a: This is the first | ||
| * @param b: This is the second | ||
| */ | ||
| provide let test1 = (a, b) => a + b | ||
|
|
||
| /** | ||
| * @param b: This is the third | ||
| */ | ||
| provide let test2 = (a, b) => a + b | ||
|
|
||
| /** | ||
| * @param b: This is the third | ||
| * @param a: This is the first | ||
| */ | ||
| provide let test3 = (a, b, c) => a + b + c | ||
|
|
||
| /** | ||
| * @param a: This is the a | ||
| * @param b: This is the b | ||
| * @param 3: This is the 3 | ||
| */ | ||
| provide let test4 = (a, b, c, _) => a + b + c |
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.
Shouldn't the logic match specifially by name or position? i.e if we see an
intits a position and a name its a position? This way we can continue to give the well formedness errors from before.