From 4539581b54e549a60dbdd7721231c791b9526d8e Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 19 Jan 2024 17:56:14 +0100 Subject: [PATCH] Also apply style for ParameterWithTupleTypePattern. --- .../KeepIndentInBranchTests.fs | 16 ++++++++++------ src/Fantomas.Core.Tests/TypeAnnotationTests.fs | 14 ++++++++------ src/Fantomas.Core.Tests/TypeDeclarationTests.fs | 16 ++++++++++------ src/Fantomas.Core/CodePrinter.fs | 13 +++++++++++++ 4 files changed, 41 insertions(+), 18 deletions(-) diff --git a/src/Fantomas.Core.Tests/KeepIndentInBranchTests.fs b/src/Fantomas.Core.Tests/KeepIndentInBranchTests.fs index ce553aa4a7..9ef21239c1 100644 --- a/src/Fantomas.Core.Tests/KeepIndentInBranchTests.fs +++ b/src/Fantomas.Core.Tests/KeepIndentInBranchTests.fs @@ -1114,18 +1114,22 @@ and [] 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 diff --git a/src/Fantomas.Core.Tests/TypeAnnotationTests.fs b/src/Fantomas.Core.Tests/TypeAnnotationTests.fs index 2d3c446eb9..d24c12d665 100644 --- a/src/Fantomas.Core.Tests/TypeAnnotationTests.fs +++ b/src/Fantomas.Core.Tests/TypeAnnotationTests.fs @@ -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 """ [] diff --git a/src/Fantomas.Core.Tests/TypeDeclarationTests.fs b/src/Fantomas.Core.Tests/TypeDeclarationTests.fs index 677ea59fcb..937dfcbf5e 100644 --- a/src/Fantomas.Core.Tests/TypeDeclarationTests.fs +++ b/src/Fantomas.Core.Tests/TypeDeclarationTests.fs @@ -2794,18 +2794,22 @@ and [] 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 diff --git a/src/Fantomas.Core/CodePrinter.fs b/src/Fantomas.Core/CodePrinter.fs index 5099ef4fa1..184569b140 100644 --- a/src/Fantomas.Core/CodePrinter.fs +++ b/src/Fantomas.Core/CodePrinter.fs @@ -3256,12 +3256,25 @@ let sepNlnBetweenTypeAndMembers (node: ITypeDefn) (ctx: Context) : Context = else ctx +[] +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