From 96c166bea81a37f8df4dc77e63512e3ba9f115c4 Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 15 May 2020 16:34:04 +0200 Subject: [PATCH] Add brace before indentation. Fixes #835 --- .../ComputationExpressionTests.fs | 48 +++++++++++++++++++ src/Fantomas/CodePrinter.fs | 8 ++-- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/Fantomas.Tests/ComputationExpressionTests.fs b/src/Fantomas.Tests/ComputationExpressionTests.fs index 26384a9614..93b5b30297 100644 --- a/src/Fantomas.Tests/ComputationExpressionTests.fs +++ b/src/Fantomas.Tests/ComputationExpressionTests.fs @@ -277,3 +277,51 @@ let tests = let tests = testList "tests" [ test "test" { Expect.equal true true "unexpected" } ] """ + +[] +let ``multiline computation expression with SynExpr.App identifier, 835`` () = + formatSourceString false """let meh = + create [] { + // foo + // bar + return 42 + }""" config + |> prepend newline + |> should equal """ +let meh = + create [] { + // foo + // bar + return 42 + } +""" + +[] +let ``multiline computation expression with SynExpr.App identifier and multiple expressions`` () = + formatSourceString false """ +let private validateLocation = + createValidatorFor () { + validate (fun l -> l.Id) [ isNotEmptyGuid ] + validate (fun l -> l.Name) + [ isNotEmpty + hasMinLengthOf 3 ] + validate (fun l -> fst l.Location) [ isValidLatitude ] + validate (fun l -> snd l.Location) [ isValidLongitude ] + validate (fun l -> l.Price) [ isGreaterThan 0. ] + validate (fun l -> l.Date) [ isNotMinDate ] + validate (fun l -> l.Creator) [ isNotEmpty ] + } +""" config + |> prepend newline + |> should equal """ +let private validateLocation = + createValidatorFor () { + validate (fun l -> l.Id) [ isNotEmptyGuid ] + validate (fun l -> l.Name) [ isNotEmpty; hasMinLengthOf 3 ] + validate (fun l -> fst l.Location) [ isValidLatitude ] + validate (fun l -> snd l.Location) [ isValidLongitude ] + validate (fun l -> l.Price) [ isGreaterThan 0. ] + validate (fun l -> l.Date) [ isNotMinDate ] + validate (fun l -> l.Creator) [ isNotEmpty ] + } +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 7b9d3f647e..df0ad07f1f 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -1189,11 +1189,9 @@ and genExpr astContext synExpr = atCurrentColumn (genExpr astContext e +> colPre sepSpace sepSpace es (fun e -> - indent - +> appNlnFun e - (indentIfNeeded - +> onlyIf (isCompExpr e) (sepSpace +> sepOpenSFixed +> sepSpace) - +> genExpr astContext e) + onlyIf (isCompExpr e) (sepSpace +> sepOpenSFixed +> sepSpace) + +> indent + +> appNlnFun e (indentIfNeeded +> genExpr astContext e) +> unindent)) | TypeApp(e, ts) -> genExpr astContext e -- "<" +> col sepComma ts (genType astContext false) -- ">"