From c3dea788a290d64e6a31277b358156fea3402c18 Mon Sep 17 00:00:00 2001 From: Florian Verdonck Date: Wed, 19 May 2021 21:33:52 +0200 Subject: [PATCH] Combine KeepIndentInBranch and MultiLineLambdaClosingNewline. Fixes #1715. (#1734) --- src/Fantomas.Tests/KeepIndentInBranchTests.fs | 100 ++++++++++++++++++ src/Fantomas/CodePrinter.fs | 9 +- 2 files changed, 105 insertions(+), 4 deletions(-) diff --git a/src/Fantomas.Tests/KeepIndentInBranchTests.fs b/src/Fantomas.Tests/KeepIndentInBranchTests.fs index bd8b9a2927..1b3ca4f857 100644 --- a/src/Fantomas.Tests/KeepIndentInBranchTests.fs +++ b/src/Fantomas.Tests/KeepIndentInBranchTests.fs @@ -1587,3 +1587,103 @@ let x = let ipv4 = string result.["ipv4"] None """ + +[] +let ``combination with MultiLineLambdaClosingNewline, 1715`` () = + formatSourceString + false + """ +module Foo = + let bar () = + let baz = + [] + |> List.filter (fun ref -> + if ref.Type <> "h" then false + else + let m = regex.Match ref.To + m.Success && things |> Set.contains (m.Groups.[1].ToString ()) + ) + 0 +""" + { config with + SpaceBeforeUppercaseInvocation = true + SpaceBeforeClassConstructor = true + SpaceBeforeMember = true + SpaceBeforeColon = true + SpaceBeforeSemicolon = true + AlignFunctionSignatureToIndentation = true + AlternativeLongMemberDefinitions = true + MultiLineLambdaClosingNewline = true + KeepIndentInBranch = true } + |> prepend newline + |> should + equal + """ +module Foo = + let bar () = + let baz = + [] + |> List.filter (fun ref -> + if ref.Type <> "h" then + false + else + + let m = regex.Match ref.To + + m.Success + && things |> Set.contains (m.Groups.[1].ToString ()) + ) + + 0 +""" + +[] +let ``combination with MultiLineLambdaClosingNewline, multiple params`` () = + formatSourceString + false + """ +module Foo = + let bar () = + let baz = + [] + |> List.filterWith X (fun ref -> + if ref.Type <> "h" then false + else + let m = regex.Match ref.To + m.Success && things |> Set.contains (m.Groups.[1].ToString ()) + ) + 0 +""" + { config with + SpaceBeforeUppercaseInvocation = true + SpaceBeforeClassConstructor = true + SpaceBeforeMember = true + SpaceBeforeColon = true + SpaceBeforeSemicolon = true + AlignFunctionSignatureToIndentation = true + AlternativeLongMemberDefinitions = true + MultiLineLambdaClosingNewline = true + KeepIndentInBranch = true } + |> prepend newline + |> should + equal + """ +module Foo = + let bar () = + let baz = + [] + |> List.filterWith + X + (fun ref -> + if ref.Type <> "h" then + false + else + + let m = regex.Match ref.To + + m.Success + && things |> Set.contains (m.Groups.[1].ToString ()) + ) + + 0 +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index b59710faca..6465b5a9cd 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -3198,9 +3198,9 @@ and genApp astContext e es ctx = let genExprAfterArrow (e: SynExpr) ctx = if Option.isSome (findTriviaTokenFromName RARROW e.Range ctx) then - genExpr astContext e ctx + genExprKeepIndentInBranch astContext e ctx else - autoNlnIfExpressionExceedsPageWidth (genExpr astContext e) ctx + autoNlnIfExpressionExceedsPageWidth (genExprKeepIndentInBranch astContext e) ctx leadingExpressionIsMultiline (sepOpenTFor lpr -- "fun " @@ -3234,8 +3234,9 @@ and genApp astContext e es ctx = let genExprAfterArrow (e: SynExpr) ctx = match findTriviaTokenFromName RARROW e.Range ctx with - | Some _ -> genExpr astContext e ctx - | None -> autoNlnIfExpressionExceedsPageWidth (genExpr astContext e) ctx + | Some _ -> genExprKeepIndentInBranch astContext e ctx + | None -> + autoNlnIfExpressionExceedsPageWidth (genExprKeepIndentInBranch astContext e) ctx sepOpenTFor lpr -- "fun " +> pats