Skip to content

Commit

Permalink
Also apply style for ParameterWithTupleTypePattern.
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Jan 19, 2024
1 parent 261ecf5 commit 4539581
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
16 changes: 10 additions & 6 deletions src/Fantomas.Core.Tests/KeepIndentInBranchTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,18 +1114,22 @@ and [<CustomEquality ; NoComparison>] Bar<'context, 'a> =
a.Apply
{ new ApplyEval<_, _, _> with
member __.Eval<'bb>
(a :
Foo<'innerContextLongLongLong, 'bb -> 'b> *
Foo<'innerContextLongLongLong, 'bb>)
(
a :
Foo<'innerContextLongLongLong, 'bb -> 'b> *
Foo<'innerContextLongLongLong, 'bb>
)
=
let (af, av) = a
b.Apply
{ new ApplyEval<_, _, _> with
member __.Eval<'cb>
(b :
Foo<'innerContextLongLongLong, 'cb -> 'b> *
Foo<'innerContextLongLongLong, 'bc>)
(
b :
Foo<'innerContextLongLongLong, 'cb -> 'b> *
Foo<'innerContextLongLongLong, 'bc>
)
=
let (bf, bv) = b
Expand Down
14 changes: 8 additions & 6 deletions src/Fantomas.Core.Tests/TypeAnnotationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ type Meh
equal
"""
type Meh
(input:
LongTupleItemTypeOneThing *
LongTupleItemTypeThingTwo *
LongTupleItemTypeThree *
LongThingFour *
LongThingFiveYow) = class end
(
input:
LongTupleItemTypeOneThing *
LongTupleItemTypeThingTwo *
LongTupleItemTypeThree *
LongThingFour *
LongThingFiveYow
) = class end
"""

[<Test>]
Expand Down
16 changes: 10 additions & 6 deletions src/Fantomas.Core.Tests/TypeDeclarationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2794,18 +2794,22 @@ and [<CustomEquality ; NoComparison>] Bar<'context, 'a> =
a.Apply
{ new ApplyEval<_, _, _> with
member __.Eval<'bb>
(a :
Foo<'innerContextLongLongLong, 'bb -> 'b> *
Foo<'innerContextLongLongLong, 'bb>)
(
a :
Foo<'innerContextLongLongLong, 'bb -> 'b> *
Foo<'innerContextLongLongLong, 'bb>
)
=
let (af, av) = a
b.Apply
{ new ApplyEval<_, _, _> with
member __.Eval<'cb>
(b :
Foo<'innerContextLongLongLong, 'cb -> 'b> *
Foo<'innerContextLongLongLong, 'bc>)
(
b :
Foo<'innerContextLongLongLong, 'cb -> 'b> *
Foo<'innerContextLongLongLong, 'bc>
)
=
let (bf, bv) = b
Expand Down
13 changes: 13 additions & 0 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3256,12 +3256,25 @@ let sepNlnBetweenTypeAndMembers (node: ITypeDefn) (ctx: Context) : Context =
else
ctx

[<return: Struct>]
let inline (|ParameterWithTupleTypePattern|_|) (pat: Pattern) =
match pat with
| Pattern.Parameter parameterNode ->
match parameterNode.Type with
| Some t ->
match t with
| Type.Tuple _ -> ValueSome()
| _ -> ValueNone
| None -> ValueNone
| _ -> ValueNone

/// Format a long parentheses parameter pattern in a binding or constructor.
/// Alternate formatting will applied when a paren tuple does not fit on the remainder of the line.
let genLongParenPatParameter (pat: Pattern) =
match pat with
| Pattern.Paren patParen ->
match patParen.Pattern with
| ParameterWithTupleTypePattern
| Pattern.Tuple _ ->
genSingleTextNode patParen.OpeningParen
+> expressionFitsOnRestOfLine
Expand Down

0 comments on commit 4539581

Please sign in to comment.