Skip to content

Commit

Permalink
Ensure endsWithMultilineTupleParameter happens with correct Context. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf authored Sep 19, 2024
1 parent 88cb207 commit 979fb9d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
19 changes: 19 additions & 0 deletions src/Fantomas.Core.Tests/ClassTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1323,3 +1323,22 @@ type X() =
// some comment
with get, set
"""

[<Test>]
let ``long tuple on single line, 3124`` () =
formatSourceString
"""
type Y =
static member putItem (client: AmazonDynamoDBClient, tableName: string, attributeValueDict: Dictionary<string, AttributeValue>) : TaskResult<unit,Error> = ()
"""
config
|> prepend newline
|> should
equal
"""
type Y =
static member putItem
(client: AmazonDynamoDBClient, tableName: string, attributeValueDict: Dictionary<string, AttributeValue>)
: TaskResult<unit, Error> =
()
"""
23 changes: 13 additions & 10 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 979fb9d

Please sign in to comment.