Skip to content

Commit

Permalink
fix(grainfmt): Wrap type annotation for a long line let assignment (#…
Browse files Browse the repository at this point in the history
…1005)

Wrap type annotation for a long line let assignment

Co-authored-by: Blaine Bublitz <[email protected]>
  • Loading branch information
marcusroberts and phated committed Oct 26, 2021
1 parent 63d07f7 commit 963b505
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 44 deletions.
111 changes: 68 additions & 43 deletions compiler/grainformat/reformat.re
Original file line number Diff line number Diff line change
Expand Up @@ -1029,16 +1029,22 @@ and print_type =
| PTyTuple(parsed_types) =>
Doc.concat([
Doc.lparen,
Doc.join(
Doc.comma,
List.map(t => print_type(t, original_source), parsed_types),
Doc.indent(
Doc.concat([
Doc.softLine,
Doc.join(
Doc.concat([Doc.comma, Doc.line]),
List.map(t => print_type(t, original_source), parsed_types),
),
if (List.length(parsed_types) == 1) {
// single arg tuple
Doc.comma;
} else {
Doc.nil;
},
]),
),
if (List.length(parsed_types) == 1) {
// single arg tuple
Doc.comma;
} else {
Doc.nil;
},
Doc.softLine,
Doc.rparen,
])

Expand Down Expand Up @@ -1248,38 +1254,52 @@ and print_application =
]);
} else {
Doc.group(
Doc.concat([
print_expression(
~parentIsArrow=false,
~endChar=None,
~original_source,
~parent_loc=func.pexp_loc,
func,
),
Doc.lparen,
Doc.indent(
Doc.concat([
Doc.softLine,
Doc.join(
Doc.concat([Doc.text(","), Doc.line]),
List.map(
e =>
print_expression(
~parentIsArrow=false,
~endChar=None,
~original_source,
~parent_loc,
e,
),
expressions,
if (List.length(expressions) == 0) {
Doc.concat([
print_expression(
~parentIsArrow=false,
~endChar=None,
~original_source,
~parent_loc=func.pexp_loc,
func,
),
Doc.lparen,
Doc.rparen,
]);
} else {
Doc.concat([
print_expression(
~parentIsArrow=false,
~endChar=None,
~original_source,
~parent_loc=func.pexp_loc,
func,
),
Doc.lparen,
Doc.indent(
Doc.concat([
Doc.softLine,
Doc.join(
Doc.concat([Doc.comma, Doc.line]),
List.map(
e =>
print_expression(
~parentIsArrow=false,
~endChar=None,
~original_source,
~parent_loc,
e,
),
expressions,
),
),
),
Doc.ifBreaks(Doc.comma, Doc.nil),
]),
),
Doc.softLine,
Doc.rparen,
]),
Doc.ifBreaks(Doc.comma, Doc.nil),
]),
),
Doc.softLine,
Doc.rparen,
]);
},
);
}
};
Expand Down Expand Up @@ -2123,9 +2143,14 @@ and print_expression =
),
Doc.text(":"),
Doc.space,
Doc.lparen, // needed to fix compiler bug (trailing type annotation needs paren, #866)
print_type(parsed_type, original_source),
Doc.rparen,
Doc.indent(
Doc.concat([
Doc.softLine,
Doc.lparen, // TODO needed to fix compiler bug (trailing type annotation needs paren, #866)
print_type(parsed_type, original_source),
Doc.rparen,
]),
),
]),
)
| PExpLambda(patterns, expression) =>
Expand Down
10 changes: 10 additions & 0 deletions compiler/test/formatter_inputs/application.gr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Array from "array"
import Option from "option"
import Map from "map"

let data = [>]

Expand Down Expand Up @@ -39,3 +40,12 @@ let ret = filteri(
src + _VALUE_OFFSET + srcIndex,
length,
)


let preExistingObjectsWithRefCountMismatch = Map.make(): (Map.Map<Number, (Number,Number,Number,Number)>)

let preEmatch = Map.make(): (Map.Map<Number, (Number,Number,Number,Number)>)

let preExistingObjectsch2 = Map.make(): (Map.Map<Number, (Number,Number)>)

let preExistingObjectsWithRefCountMismatch2 = Map.make(): (Map.Map<Number, (Number,Number,Number,Number,Number,Number,Number,Number,Number,Number,Number)>)
26 changes: 26 additions & 0 deletions compiler/test/formatter_outputs/application.gr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Array from "array"
import Option from "option"
import Map from "map"

let data = [>]

Expand Down Expand Up @@ -52,3 +53,28 @@ let ret = filteri(
src + _VALUE_OFFSET + srcIndex,
length,
)

let preExistingObjectsWithRefCountMismatch = Map.make():
(Map.Map<Number, (Number, Number, Number, Number)>)

let preEmatch = Map.make(): (Map.Map<Number, (Number, Number, Number, Number)>)

let preExistingObjectsch2 = Map.make(): (Map.Map<Number, (Number, Number)>)

let preExistingObjectsWithRefCountMismatch2 = Map.make():
(Map.Map<
Number,
(
Number,
Number,
Number,
Number,
Number,
Number,
Number,
Number,
Number,
Number,
Number
)
>)
2 changes: 1 addition & 1 deletion compiler/test/formatter_outputs/enums.gr
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ enum ParsedRegularExpression {
Bool
), // regex, n-start, num-n, needs-backtrack
REReference(Number, Bool), // n, case-sensitive
RERange(List<(Number,Number)>),
RERange(List<(Number, Number)>),
REUnicodeCategories(
List<UnicodeCategory>,
Bool
Expand Down

0 comments on commit 963b505

Please sign in to comment.