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 expression in ForEach. #1655

Merged
merged 1 commit into from
Apr 16, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,59 @@ let fns =
// I think the space at the start of the lines above matter
|]
"""

[<Test>]
let ``long list in for loop, 1650`` () =
formatSourceString
false
"""
module Foo =

let foo () =
let bar =
seq {
for i in ["hello1" ; "hello1" ; "hello1" ; "hello1" ; "hello1"] do
yield i, seq {
yield "hi"
yield "bye"
}
}
()
"""
{ config with
MaxLineLength = 100
SpaceBeforeUppercaseInvocation = true
SpaceBeforeClassConstructor = true
SpaceBeforeMember = true
SpaceBeforeColon = true
SpaceBeforeSemicolon = true
MultilineBlockBracketsOnSameColumn = true
AlignFunctionSignatureToIndentation = true
MultiLineLambdaClosingNewline = true }
|> prepend newline
|> should
equal
"""
module Foo =

let foo () =
let bar =
seq {
for i in
[
"hello1"
"hello1"
"hello1"
"hello1"
"hello1"
] do
yield
i,
seq {
yield "hi"
yield "bye"
}
}

()
"""
2 changes: 1 addition & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ and genExpr astContext synExpr ctx =
| ForEach (p, e1, e2, isArrow) ->
atCurrentColumn (
!- "for " +> genPat astContext p -- " in "
+> genExpr { astContext with IsNakedRange = true } e1
+> autoIndentAndNlnIfExpressionExceedsPageWidth (genExpr { astContext with IsNakedRange = true } e1)
+> ifElse
isArrow
(sepArrow
Expand Down