From ee24f4d50a85e0c4fc722cd03cc8de8c747e0f43 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 | 28 ++++++++++++++++++++++ src/Fantomas/CodePrinter.fs | 4 ++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/Fantomas.Tests/PatternMatchingTests.fs b/src/Fantomas.Tests/PatternMatchingTests.fs index 2cf7b19ea0..36ae06e5e4 100644 --- a/src/Fantomas.Tests/PatternMatchingTests.fs +++ b/src/Fantomas.Tests/PatternMatchingTests.fs @@ -1858,3 +1858,31 @@ 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" +""" \ No newline at end of file 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