Skip to content

Commit

Permalink
Indent multiline yield expression. Fixes #882. (#1001)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Aug 17, 2020
1 parent ee6dd12 commit ab5e8da
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
38 changes: 38 additions & 0 deletions src/Fantomas.Tests/ListTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1601,3 +1601,41 @@ let value =
if bar then yield "d" else yield! [ "e"; "f" ]
]
"""

[<Test>]
let ``multiline yield expression should be indented, 882`` () =
formatSourceString false """
let choices : Foo list =
[
yield! getMore 9
yield
// Test
Foo 2
]
""" config
|> prepend newline
|> should equal """
let choices: Foo list =
[ yield! getMore 9
yield
// Test
Foo 2 ]
"""

[<Test>]
let ``multiline yield bang inside list`` () =
formatSourceString false """
let choices : Foo list =
[
yield!
// Test
[ Foo 2 ]
]
""" config
|> prepend newline
|> should equal """
let choices: Foo list =
[ yield!
// Test
[ Foo 2 ] ]
"""
8 changes: 7 additions & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,13 @@ and genExpr astContext synExpr =
str "lazy "
+> ifElse isInfixExpr genInfixExpr genNonInfixExpr

| SingleExpr(kind, e) -> str kind +> genExpr astContext e
| SingleExpr(kind, e) ->
str kind
+> (match kind with
| YieldFrom
| Yield -> autoIndentAndNlnIfExpressionExceedsPageWidth (genExpr astContext e)
| _ -> genExpr astContext e)

| ConstExpr(c,r) -> genConst c r
| NullExpr -> !- "null"
// Not sure about the role of e1
Expand Down

0 comments on commit ab5e8da

Please sign in to comment.