Skip to content

Commit

Permalink
Format multiple clauses named underneath each other. Fixes #1395 (#1412)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf authored Jan 29, 2021
1 parent 8c5011b commit c1a4fe6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
60 changes: 60 additions & 0 deletions src/Fantomas.Tests/ControlStructureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -836,3 +836,63 @@ with ex ->
Infrastructure.ReportWarning ex
return None
"""

[<Test>]
let ``try/with with multiple type checks, 1395`` () =
formatSourceString
false
"""
things
|> Seq.map (fun a ->
try
Some i
with
| :? Foo
| :? Bar as e when true ->
None
)
"""
config
|> prepend newline
|> should
equal
"""
things
|> Seq.map
(fun a ->
try
Some i
with
| :? Foo
| :? Bar as e when true -> None)
"""

[<Test>]
let ``try/with with named or pattern`` () =
formatSourceString
false
"""
things
|> Seq.map (fun a ->
try
Some i
with
| Foo _
| Bar _ as e when true ->
None
)
"""
config
|> prepend newline
|> should
equal
"""
things
|> Seq.map
(fun a ->
try
Some i
with
| Foo _
| Bar _ as e when true -> None)
"""
3 changes: 2 additions & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2067,7 +2067,8 @@ and genExpr astContext synExpr ctx =
(genClause astContext b c)

match cs with
| [ SynMatchClause.Clause (SynPat.Or _, _, _, _, _) ] ->
| [ SynMatchClause.Clause (PatOr _, _, _, _, _) ]
| [ SynMatchClause.Clause (PatNamed (_, (PatOr _), _), _, _, _, _) ] ->
atCurrentColumn (
prefix
+> indentOnWith
Expand Down

0 comments on commit c1a4fe6

Please sign in to comment.