diff --git a/src/Fantomas.Tests/PatternMatchingTests.fs b/src/Fantomas.Tests/PatternMatchingTests.fs index ed05a9f262..f0050737e2 100644 --- a/src/Fantomas.Tests/PatternMatchingTests.fs +++ b/src/Fantomas.Tests/PatternMatchingTests.fs @@ -2056,3 +2056,34 @@ match! | None -> false | Some balance -> someRetrievedBalance = balance """ + +[] +let ``vanity alignment used when using long case in match block, 1926`` () = + formatSourceString + false + """ +match foo with +| SomeVeryLongMatchCase(1234567890, 1234567890, 1234567890, 1234567890, 1234567890, 1234567890, 1234567890, 1234567890, 1234567890, 1234567890) -> + bar() +| _ -> () """ + config + |> prepend newline + |> should + equal + """ +match foo with +| SomeVeryLongMatchCase + ( + 1234567890, + 1234567890, + 1234567890, + 1234567890, + 1234567890, + 1234567890, + 1234567890, + 1234567890, + 1234567890, + 1234567890 + ) -> bar () +| _ -> () +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 79e956f2b7..b9bcc1ae00 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -4971,10 +4971,25 @@ and genPat astContext pat = | _ -> true | _ -> true - ifElse isParenNecessary sepOpenT sepSpace - +> genPat astContext p - +> enterNodeTokenByName pat.Range RPAREN - +> ifElse isParenNecessary sepCloseT sepNone + let shortExpr = + ifElse isParenNecessary sepOpenT sepSpace + +> genPat astContext p + +> enterNodeTokenByName pat.Range RPAREN + +> ifElse isParenNecessary sepCloseT sepNone + + let longExpr = + ifElse + astContext.IsInsideMatchClausePattern + (ifElse isParenNecessary ((indent +> sepNln +> sepOpenT +> indent +> sepNln)) sepNone) + (ifElse isParenNecessary sepOpenT sepSpace) + +> genPat astContext p + +> enterNodeTokenByName pat.Range RPAREN + +> (ifElse + astContext.IsInsideMatchClausePattern + (ifElse isParenNecessary (unindent +> sepNln +> sepCloseT +> unindent) sepNone) + (ifElse isParenNecessary sepCloseT sepNone)) + + expressionFitsOnRestOfLine shortExpr longExpr | PatTuple ps -> expressionFitsOnRestOfLine (col sepComma ps (genPat astContext))