Skip to content

Commit

Permalink
Detect multiline clause by UnIndentBy event. Fixes #1721. (#1722)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed May 14, 2021
1 parent 52946a5 commit d787929
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
27 changes: 27 additions & 0 deletions src/Fantomas.Tests/PatternMatchingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1858,3 +1858,30 @@ match x with
with e -> printfn "failure %A" e)
--*-- bar
"""

[<Test>]
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"
"""
4 changes: 2 additions & 2 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d787929

Please sign in to comment.