Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure endsWithMultilineTupleParameter happens with correct Context. #3125

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading