diff --git a/src/Fantomas.Core.Tests/ClassTests.fs b/src/Fantomas.Core.Tests/ClassTests.fs index 1231463d3..7a9f9a39f 100644 --- a/src/Fantomas.Core.Tests/ClassTests.fs +++ b/src/Fantomas.Core.Tests/ClassTests.fs @@ -1323,3 +1323,22 @@ type X() = // some comment with get, set """ + +[] +let ``long tuple on single line, 3124`` () = + formatSourceString + """ +type Y = + static member putItem (client: AmazonDynamoDBClient, tableName: string, attributeValueDict: Dictionary) : TaskResult = () +""" + config + |> prepend newline + |> should + equal + """ +type Y = + static member putItem + (client: AmazonDynamoDBClient, tableName: string, attributeValueDict: Dictionary) + : TaskResult = + () +""" diff --git a/src/Fantomas.Core/CodePrinter.fs b/src/Fantomas.Core/CodePrinter.fs index bcddf6700..c3c7c2e43 100644 --- a/src/Fantomas.Core/CodePrinter.fs +++ b/src/Fantomas.Core/CodePrinter.fs @@ -2924,7 +2924,7 @@ let genBinding (b: BindingNode) (ctx: Context) : Context = /// : rt /// = let long (ctx: Context) = - let endsWithMultilineTupleParameter = + let endsWithMultilineTupleParameter ctx = match List.tryLast b.Parameters with | Some(Pattern.Paren parenNode as p) -> match parenNode.Pattern with @@ -2949,21 +2949,24 @@ let genBinding (b: BindingNode) (ctx: Context) : Context = beforeInline || beforeIdentifier || beforeAccessibility - let nlnOnSeparateLine = not endsWithMultilineTupleParameter || alternativeSyntax - (onlyIf hasTriviaAfterLeadingKeyword indent +> afterLetKeyword +> sepSpace +> genFunctionName +> indent +> sepNln - +> genParameters - +> onlyIf nlnOnSeparateLine sepNln - +> leadingExpressionIsMultiline (genReturnType nlnOnSeparateLine) (fun isMultiline -> - if (alternativeSyntax && Option.isSome b.ReturnType) || isMultiline then - sepNln +> genSingleTextNode b.Equals - else - sepSpace +> genSingleTextNode b.Equals) + +> (fun ctx -> + let nlnOnSeparateLine = + not (endsWithMultilineTupleParameter ctx) || alternativeSyntax + + (genParameters + +> onlyIf nlnOnSeparateLine sepNln + +> leadingExpressionIsMultiline (genReturnType nlnOnSeparateLine) (fun isMultiline -> + if (alternativeSyntax && Option.isSome b.ReturnType) || isMultiline then + sepNln +> genSingleTextNode b.Equals + else + sepSpace +> genSingleTextNode b.Equals)) + ctx) +> unindent +> onlyIf hasTriviaAfterLeadingKeyword unindent) ctx