Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indent multiline yield expression #1001

Merged
merged 1 commit into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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