From c5c9f468513696f409cae5947f4357f404cfe2e7 Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 14 May 2021 20:24:49 +0200 Subject: [PATCH] Detect multiline clause by UnIndentBy event. Fixes #1721. --- src/Fantomas.Tests/PatternMatchingTests.fs | 27 ++++++++++++++++++++++ src/Fantomas/CodePrinter.fs | 4 ++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Fantomas.Tests/PatternMatchingTests.fs b/src/Fantomas.Tests/PatternMatchingTests.fs index 2cf7b19ea0..f41abb1d91 100644 --- a/src/Fantomas.Tests/PatternMatchingTests.fs +++ b/src/Fantomas.Tests/PatternMatchingTests.fs @@ -1858,3 +1858,30 @@ match x with with e -> printfn "failure %A" e) --*-- bar """ + +[] +let ``match with single line last clause followed by line comment and infix operator, 1721 `` () = + formatSourceString + false + """ + let select p = + match p with + | voo _ -> "v_" + | dd -> "dd_" + | q -> "q_" // comment + |> List.singleton + |> instruction "s" +""" + { config with IndentSize = 2 } + |> prepend newline + |> should + equal + """ +let select p = + match p with + | voo _ -> "v_" + | dd -> "dd_" + | q -> "q_" // comment + |> List.singleton + |> instruction "s" +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 0f2d52a13a..cec764bc3d 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -2695,8 +2695,8 @@ and genMultilineInfixExpr astContext e1 operatorText operatorExpr e2 = |> Seq.tryHead |> fun e -> match e with - | Some (Write _) -> true - | _ -> false + | Some (UnIndentBy _) -> false + | _ -> true if lastClauseIsSingleLine then ctxAfterMatch