Skip to content

Commit 979fb9d

Browse files
authored
Ensure endsWithMultilineTupleParameter happens with correct Context. (#3125)
1 parent 88cb207 commit 979fb9d

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

src/Fantomas.Core.Tests/ClassTests.fs

+19
Original file line numberDiff line numberDiff line change
@@ -1323,3 +1323,22 @@ type X() =
13231323
// some comment
13241324
with get, set
13251325
"""
1326+
1327+
[<Test>]
1328+
let ``long tuple on single line, 3124`` () =
1329+
formatSourceString
1330+
"""
1331+
type Y =
1332+
static member putItem (client: AmazonDynamoDBClient, tableName: string, attributeValueDict: Dictionary<string, AttributeValue>) : TaskResult<unit,Error> = ()
1333+
"""
1334+
config
1335+
|> prepend newline
1336+
|> should
1337+
equal
1338+
"""
1339+
type Y =
1340+
static member putItem
1341+
(client: AmazonDynamoDBClient, tableName: string, attributeValueDict: Dictionary<string, AttributeValue>)
1342+
: TaskResult<unit, Error> =
1343+
()
1344+
"""

src/Fantomas.Core/CodePrinter.fs

+13-10
Original file line numberDiff line numberDiff line change
@@ -2924,7 +2924,7 @@ let genBinding (b: BindingNode) (ctx: Context) : Context =
29242924
/// : rt
29252925
/// =
29262926
let long (ctx: Context) =
2927-
let endsWithMultilineTupleParameter =
2927+
let endsWithMultilineTupleParameter ctx =
29282928
match List.tryLast b.Parameters with
29292929
| Some(Pattern.Paren parenNode as p) ->
29302930
match parenNode.Pattern with
@@ -2949,21 +2949,24 @@ let genBinding (b: BindingNode) (ctx: Context) : Context =
29492949

29502950
beforeInline || beforeIdentifier || beforeAccessibility
29512951

2952-
let nlnOnSeparateLine = not endsWithMultilineTupleParameter || alternativeSyntax
2953-
29542952
(onlyIf hasTriviaAfterLeadingKeyword indent
29552953
+> afterLetKeyword
29562954
+> sepSpace
29572955
+> genFunctionName
29582956
+> indent
29592957
+> sepNln
2960-
+> genParameters
2961-
+> onlyIf nlnOnSeparateLine sepNln
2962-
+> leadingExpressionIsMultiline (genReturnType nlnOnSeparateLine) (fun isMultiline ->
2963-
if (alternativeSyntax && Option.isSome b.ReturnType) || isMultiline then
2964-
sepNln +> genSingleTextNode b.Equals
2965-
else
2966-
sepSpace +> genSingleTextNode b.Equals)
2958+
+> (fun ctx ->
2959+
let nlnOnSeparateLine =
2960+
not (endsWithMultilineTupleParameter ctx) || alternativeSyntax
2961+
2962+
(genParameters
2963+
+> onlyIf nlnOnSeparateLine sepNln
2964+
+> leadingExpressionIsMultiline (genReturnType nlnOnSeparateLine) (fun isMultiline ->
2965+
if (alternativeSyntax && Option.isSome b.ReturnType) || isMultiline then
2966+
sepNln +> genSingleTextNode b.Equals
2967+
else
2968+
sepSpace +> genSingleTextNode b.Equals))
2969+
ctx)
29672970
+> unindent
29682971
+> onlyIf hasTriviaAfterLeadingKeyword unindent)
29692972
ctx

0 commit comments

Comments
 (0)