Skip to content

Commit 6108fc4

Browse files
authored
Merge pull request #3154 from dawedawe/fix-3128
Fix idempotency issue with comments in apps on lambda expressions
2 parents b3b3e62 + 22ad8ca commit 6108fc4

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [Unreleased]
4+
5+
### Fixed
6+
7+
* Idempotency problem with comments in applications on lambda expressions. [#3128](https://github.com/fsprojects/fantomas/issues/3128)
8+
39
## 7.0.1 - 2025-02-21
410

511
### Fixed

src/Fantomas.Core.Tests/LambdaTests.fs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,3 +1430,22 @@ MailboxProcessor<string>.Start(fun inbox ->
14301430
do! sw.WriteLineAsync(msg) |> Async.AwaitTask
14311431
})
14321432
"""
1433+
1434+
[<Test>]
1435+
let ``comment in app on lambda expr, 3128`` () =
1436+
formatSourceString
1437+
"""
1438+
f(
1439+
// some comment
1440+
fun x -> x)
1441+
"""
1442+
config
1443+
|> prepend newline
1444+
|> should
1445+
equal
1446+
"""
1447+
f
1448+
(
1449+
// some comment
1450+
fun x -> x)
1451+
"""

src/Fantomas.Core/CodePrinter.fs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2402,7 +2402,7 @@ let genAppWithLambda sep (node: ExprAppWithLambdaNode) =
24022402
+> onlyIf (List.isNotEmpty node.Arguments) sepSpace
24032403
+> (genSingleTextNode node.OpeningParen
24042404
+> (match node.Lambda with
2405-
| Choice1Of2 lambdaNode -> genLambdaWithParen lambdaNode |> genNode lambdaNode
2405+
| Choice1Of2 lambdaNode -> genLambdaWithParen lambdaNode
24062406
| Choice2Of2 matchLambdaNode ->
24072407
genSingleTextNode matchLambdaNode.Function
24082408
+> indentSepNlnUnindent (genClauses matchLambdaNode.Clauses)
@@ -2418,7 +2418,7 @@ let genAppWithLambda sep (node: ExprAppWithLambdaNode) =
24182418
match node.Lambda with
24192419
| Choice1Of2 lambdaNode ->
24202420
genSingleTextNode node.OpeningParen
2421-
+> (genLambdaWithParen lambdaNode |> genNode lambdaNode)
2421+
+> genLambdaWithParen lambdaNode
24222422
+> onlyIf (not (isStroustrupStyleExpr ctx.Config lambdaNode.Expr)) sepNln
24232423
+> genSingleTextNode node.ClosingParen
24242424
| Choice2Of2 matchLambdaNode ->
@@ -2437,8 +2437,7 @@ let genAppWithLambda sep (node: ExprAppWithLambdaNode) =
24372437
+> (match node.Lambda with
24382438
| Choice1Of2 lambdaNode ->
24392439
leadingExpressionIsMultiline
2440-
(genSingleTextNode node.OpeningParen
2441-
+> (genLambdaWithParen lambdaNode |> genNode lambdaNode))
2440+
(genSingleTextNode node.OpeningParen +> genLambdaWithParen lambdaNode)
24422441
(fun isMultiline ->
24432442
onlyIf
24442443
(isMultiline && not (isStroustrupStyleExpr ctx.Config lambdaNode.Expr))
@@ -2482,7 +2481,7 @@ let genAppWithLambda sep (node: ExprAppWithLambdaNode) =
24822481
+> col sepSpace node.Arguments genExpr
24832482
+> sep
24842483
+> genSingleTextNode node.OpeningParen
2485-
+> (genLambdaWithParen lambdaNode |> genNode lambdaNode)
2484+
+> genLambdaWithParen lambdaNode
24862485
+> sepNlnWhenWriteBeforeNewlineNotEmpty
24872486
+> addFixedSpaces startColumn
24882487
+> genSingleTextNode node.ClosingParen)
@@ -2496,7 +2495,7 @@ let genAppWithLambda sep (node: ExprAppWithLambdaNode) =
24962495
(col sepNln node.Arguments genExpr
24972496
+> onlyIfNot (List.isEmpty node.Arguments) sepNln
24982497
+> genSingleTextNode node.OpeningParen
2499-
+> (genLambdaWithParen lambdaNode |> genNode lambdaNode)
2498+
+> genLambdaWithParen lambdaNode
25002499
+> addFixedSpaces startColumn
25012500
+> genSingleTextNode node.ClosingParen)
25022501
ctx)

0 commit comments

Comments
 (0)