diff --git a/src/Fantomas.Tests/ComputationExpressionTests.fs b/src/Fantomas.Tests/ComputationExpressionTests.fs index b5edf970dd..26384a9614 100644 --- a/src/Fantomas.Tests/ComputationExpressionTests.fs +++ b/src/Fantomas.Tests/ComputationExpressionTests.fs @@ -258,3 +258,22 @@ let f2 = return r + s } """ + +[] +let ``computation expression with app identifier, 806`` () = + formatSourceString false """ +[] +let tests = + testList "tests" + [ + test "test" { + Expect.equal true true "unexpected" + } + ] +""" config + |> prepend newline + |> should equal """ +[] +let tests = + testList "tests" [ test "test" { Expect.equal true true "unexpected" } ] +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 0989401df3..50e1ae5412 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -1128,14 +1128,10 @@ and genExpr astContext synExpr = fun (ctx:Context) -> let hasPar = hasParenthesis e2 let addSpaceBefore = addSpaceBeforeParensInFunCall e1 e2 ctx - let isCompExpr = - match e2 with - | CompExpr _ -> true - | _ -> false let genApp = atCurrentColumn ( genExpr astContext e1 - +> onlyIf isCompExpr (sepSpace +> sepOpenSFixed +> sepSpace) + +> onlyIf (isCompExpr e2) (sepSpace +> sepOpenSFixed +> sepSpace) +> ifElse (not astContext.IsInsideDotGet) (ifElse hasPar @@ -1165,9 +1161,15 @@ and genExpr astContext synExpr = else sepSpace ctx - atCurrentColumn (genExpr astContext e +> - colPre sepSpace sepSpace es (fun e -> - indent +> appNlnFun e (indentIfNeeded +> genExpr astContext e) +> unindent)) + atCurrentColumn + (genExpr astContext e + +> colPre sepSpace sepSpace es (fun e -> + indent + +> appNlnFun e + (indentIfNeeded + +> onlyIf (isCompExpr e) (sepSpace +> sepOpenSFixed +> sepSpace) + +> genExpr astContext e) + +> unindent)) | TypeApp(e, ts) -> genExpr astContext e -- "<" +> col sepComma ts (genType astContext false) -- ">" | LetOrUses(bs, e) -> diff --git a/src/Fantomas/SourceParser.fs b/src/Fantomas/SourceParser.fs index 62fe301d74..a5749a6990 100644 --- a/src/Fantomas/SourceParser.fs +++ b/src/Fantomas/SourceParser.fs @@ -600,6 +600,8 @@ let (|CompExpr|_|) = function Some(isArray, expr) | _ -> None +let isCompExpr = function | CompExpr _ -> true | _ -> false + let (|ArrayOrListOfSeqExpr|_|) = function | SynExpr.ArrayOrListOfSeqExpr(isArray, expr, _) -> Some(isArray, expr)