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

Format doc comments on variant leafs smoother #2194

Merged
merged 1 commit into from
Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions formatTest/unit_tests/expected_output/variants.re
Original file line number Diff line number Diff line change
Expand Up @@ -674,3 +674,12 @@ Delete({
});

let x: t = `Poly;

/* Format doc attrs consistent: https://github.com/facebook/reason/issues/2187 */
type t =
| /** This is some documentation that might be fairly long and grant a line break */
A
| /** Shorter docs */
B
| /** Some more longer docs over here that make sense to break lines on too */
C;
9 changes: 9 additions & 0 deletions formatTest/unit_tests/input/variants.re
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,12 @@ Delete({pub x = methodOne; pub y = methodTwo; pub z = methodThisBreaks});
`Delete({pub x = methodOne; pub y = methodTwo; pub z = methodThisBreaks});

let x: t = `Poly;

/* Format doc attrs consistent: https://github.com/facebook/reason/issues/2187 */
type t =
| /** This is some documentation that might be fairly long and grant a line break */
A
| /** Shorter docs */
B
| /** Some more longer docs over here that make sense to break lines on too */
C;
12 changes: 10 additions & 2 deletions src/reason-parser/reason_pprint_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2701,7 +2701,7 @@ let printer = object(self:'self)
* not parsed or printed correctly. *)
method type_variant_leaf1 opt_ampersand polymorphic print_bar x =
let {pcd_name; pcd_args; pcd_res; pcd_loc; pcd_attributes} = x in
let {stdAttrs} = partitionAttributes pcd_attributes in
let {stdAttrs; docAttrs} = partitionAttributes ~partDoc:true pcd_attributes in
let ampersand_helper i arg =
let ct = self#core_type arg in
let ct = match arg.ptyp_desc with
Expand Down Expand Up @@ -2764,10 +2764,18 @@ let printer = object(self:'self)
let prefix = if polymorphic then "`" else "" in
let sourceMappedName = atom ~loc:pcd_name.loc (prefix ^ pcd_name.txt) in
let sourceMappedNameWithAttributes =
match stdAttrs with
let layout = match stdAttrs with
| [] -> sourceMappedName
| stdAttrs ->
formatAttributed sourceMappedName (self#attributes stdAttrs)
in
match docAttrs with
| [] -> layout
| docAttrs ->
makeList ~break:Always ~inline:(true, true) [
makeList (self#attributes docAttrs);
layout
]
in
let constructorName = makeList ~postSpace:true [sourceMappedNameWithAttributes] in
let everything = match (args, gadtRes) with
Expand Down