diff --git a/src/Fantomas.Tests/PatternMatchingTests.fs b/src/Fantomas.Tests/PatternMatchingTests.fs index f0050737e2..db36d87389 100644 --- a/src/Fantomas.Tests/PatternMatchingTests.fs +++ b/src/Fantomas.Tests/PatternMatchingTests.fs @@ -2087,3 +2087,45 @@ match foo with ) -> bar () | _ -> () """ + +[] +let ``vanity alignment removed from multiline match expression`` () = + formatSourceString + false + """ +match directoryRouter.GetIdentity() + |> self.ServerDescriptors.TryFind with +| None -> CircuitNodeDetail.FastCreate +| Some serverDescriptor -> self.ConvertToCircuitNodeDetail serverDescriptor +""" + config + |> prepend newline + |> should + equal + """ +match + directoryRouter.GetIdentity() + |> self.ServerDescriptors.TryFind + with +| None -> CircuitNodeDetail.FastCreate +| Some serverDescriptor -> self.ConvertToCircuitNodeDetail serverDescriptor +""" + +[] +let ``match expression covering one line`` () = + formatSourceString + false + """ +match directoryRouter.GetIdentity() with +| None -> CircuitNodeDetail.FastCreate +| Some serverDescriptor -> + self.ConvertToCircuitNodeDetail serverDescriptor""" + config + |> prepend newline + |> should + equal + """ +match directoryRouter.GetIdentity() with +| None -> CircuitNodeDetail.FastCreate +| Some serverDescriptor -> self.ConvertToCircuitNodeDetail serverDescriptor +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index f2be6218ae..e75566b361 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -1614,7 +1614,10 @@ and genExpr astContext synExpr ctx = +> expressionFitsOnRestOfLine (genExpr astContext e +> genWithAfterMatch withRange) - (genExprInIfOrMatch astContext e + (genExprInIfOrMatch + { astContext with + IsInsideMatchClausePattern = true } + e +> (sepNlnUnlessLastEventIsNewline +> (genWithAfterMatch withRange))) @@ -3320,6 +3323,14 @@ and genExprInIfOrMatch astContext (e: SynExpr) (ctx: Context) : Context = let fallback = if hasCommentBeforeExpr e then genExpr astContext e |> indentNlnUnindentNln + elif astContext.IsInsideMatchClausePattern then + indent + +> sepNln + +> genExpr + { astContext with + IsInsideMatchClausePattern = false } + e + +> unindent else sepNlnWhenWriteBeforeNewlineNotEmpty sepNone +> genExpr astContext e