diff --git a/src/Fantomas.Tests/PatternMatchingTests.fs b/src/Fantomas.Tests/PatternMatchingTests.fs index d32e73296c..7604aaac78 100644 --- a/src/Fantomas.Tests/PatternMatchingTests.fs +++ b/src/Fantomas.Tests/PatternMatchingTests.fs @@ -1217,8 +1217,10 @@ type Thing = | Foo of msg: string override this.ToString() = match this with - | Foo (ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) -> - "" + | Foo + ( + ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff + ) -> "" """ [] @@ -1248,8 +1250,10 @@ type Thing = | Foo of msg : string override this.ToString() : string = match this with - | Foo (ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) -> - "" + | Foo + ( + ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff + ) -> "" """ [] @@ -2165,6 +2169,37 @@ match! a with // foo | B b -> () """ +[] +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 () +| _ -> () +""" + [] let ``comment after match keyword, 1851`` () = formatSourceString diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 8509616ae1..de8cddcea9 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -5026,9 +5026,28 @@ and genPat astContext pat = | PatParen (_, PatUnitConst, _) -> !- "()" | PatParen (lpr, p, rpr) -> - genTriviaFor SynPat_Paren_OpeningParenthesis lpr sepOpenT - +> genPat astContext p - +> genTriviaFor SynPat_Paren_ClosingParenthesis rpr sepCloseT + let shortExpr = + genTriviaFor SynPat_Paren_OpeningParenthesis lpr sepOpenT + +> genPat astContext p + +> genTriviaFor SynPat_Paren_ClosingParenthesis rpr sepCloseT + + let longExpr = + ifElse + astContext.IsInsideMatchClausePattern + (indent + +> sepNln + +> genTriviaFor SynPat_Paren_OpeningParenthesis lpr sepOpenT + +> sepNln + +> (fun ctx -> (rep ctx.Config.IndentSize (!- " ")) ctx) + +> genPat astContext p + +> sepNln + +> genTriviaFor SynPat_Paren_ClosingParenthesis rpr sepCloseT + +> unindent) + (genTriviaFor SynPat_Paren_OpeningParenthesis lpr sepOpenT + +> genPat astContext p + +> genTriviaFor SynPat_Paren_ClosingParenthesis rpr sepCloseT) + + expressionFitsOnRestOfLine shortExpr longExpr | PatTuple ps -> expressionFitsOnRestOfLine (col sepComma ps (genPat astContext))