Skip to content

Commit 0dc03a2

Browse files
committed
Ensure endsWithMultilineTupleParameter happens with correct Context. (#3125)
1 parent 506beb9 commit 0dc03a2

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

Diff for: 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+
"""

Diff for: src/Fantomas.Core/CodePrinter.fs

+13-10
Original file line numberDiff line numberDiff line change
@@ -2925,7 +2925,7 @@ let genBinding (b: BindingNode) (ctx: Context) : Context =
29252925
/// : rt
29262926
/// =
29272927
let long (ctx: Context) =
2928-
let endsWithMultilineTupleParameter =
2928+
let endsWithMultilineTupleParameter ctx =
29292929
match List.tryLast b.Parameters with
29302930
| Some(Pattern.Paren parenNode as p) ->
29312931
match parenNode.Pattern with
@@ -2950,21 +2950,24 @@ let genBinding (b: BindingNode) (ctx: Context) : Context =
29502950

29512951
beforeInline || beforeIdentifier || beforeAccessibility
29522952

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

0 commit comments

Comments
 (0)