Skip to content

Commit

Permalink
Indent multiline expression in ForEach. Fixes #1650. (#1655)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf authored Apr 16, 2021
1 parent 15e3d6d commit 4d0bd2b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
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

0 comments on commit 4d0bd2b

Please sign in to comment.