Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [Unreleased]

### Fixed

* Idempotency problem with comments in applications on lambda expressions. [#3128](https://github.com/fsprojects/fantomas/issues/3128)

## 7.0.1 - 2025-02-21

### Fixed
Expand Down
19 changes: 19 additions & 0 deletions src/Fantomas.Core.Tests/LambdaTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1430,3 +1430,22 @@ MailboxProcessor<string>.Start(fun inbox ->
do! sw.WriteLineAsync(msg) |> Async.AwaitTask
})
"""

[<Test>]
let ``comment in app on lambda expr, 3128`` () =
formatSourceString
"""
f(
// some comment
fun x -> x)
"""
config
|> prepend newline
|> should
equal
"""
f
(
// some comment
fun x -> x)
"""
11 changes: 5 additions & 6 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2402,7 +2402,7 @@ let genAppWithLambda sep (node: ExprAppWithLambdaNode) =
+> onlyIf (List.isNotEmpty node.Arguments) sepSpace
+> (genSingleTextNode node.OpeningParen
+> (match node.Lambda with
| Choice1Of2 lambdaNode -> genLambdaWithParen lambdaNode |> genNode lambdaNode
| Choice1Of2 lambdaNode -> genLambdaWithParen lambdaNode
| Choice2Of2 matchLambdaNode ->
genSingleTextNode matchLambdaNode.Function
+> indentSepNlnUnindent (genClauses matchLambdaNode.Clauses)
Expand All @@ -2418,7 +2418,7 @@ let genAppWithLambda sep (node: ExprAppWithLambdaNode) =
match node.Lambda with
| Choice1Of2 lambdaNode ->
genSingleTextNode node.OpeningParen
+> (genLambdaWithParen lambdaNode |> genNode lambdaNode)
+> genLambdaWithParen lambdaNode
+> onlyIf (not (isStroustrupStyleExpr ctx.Config lambdaNode.Expr)) sepNln
+> genSingleTextNode node.ClosingParen
| Choice2Of2 matchLambdaNode ->
Expand All @@ -2437,8 +2437,7 @@ let genAppWithLambda sep (node: ExprAppWithLambdaNode) =
+> (match node.Lambda with
| Choice1Of2 lambdaNode ->
leadingExpressionIsMultiline
(genSingleTextNode node.OpeningParen
+> (genLambdaWithParen lambdaNode |> genNode lambdaNode))
(genSingleTextNode node.OpeningParen +> genLambdaWithParen lambdaNode)
(fun isMultiline ->
onlyIf
(isMultiline && not (isStroustrupStyleExpr ctx.Config lambdaNode.Expr))
Expand Down Expand Up @@ -2482,7 +2481,7 @@ let genAppWithLambda sep (node: ExprAppWithLambdaNode) =
+> col sepSpace node.Arguments genExpr
+> sep
+> genSingleTextNode node.OpeningParen
+> (genLambdaWithParen lambdaNode |> genNode lambdaNode)
+> genLambdaWithParen lambdaNode
+> sepNlnWhenWriteBeforeNewlineNotEmpty
+> addFixedSpaces startColumn
+> genSingleTextNode node.ClosingParen)
Expand All @@ -2496,7 +2495,7 @@ let genAppWithLambda sep (node: ExprAppWithLambdaNode) =
(col sepNln node.Arguments genExpr
+> onlyIfNot (List.isEmpty node.Arguments) sepNln
+> genSingleTextNode node.OpeningParen
+> (genLambdaWithParen lambdaNode |> genNode lambdaNode)
+> genLambdaWithParen lambdaNode
+> addFixedSpaces startColumn
+> genSingleTextNode node.ClosingParen)
ctx)
Expand Down
Loading