diff --git a/src/Fantomas.Tests/MultilineBlockBracketsOnSameColumnArrayOrListTests.fs b/src/Fantomas.Tests/MultilineBlockBracketsOnSameColumnArrayOrListTests.fs index 3d38408bcb..24ebf84686 100644 --- a/src/Fantomas.Tests/MultilineBlockBracketsOnSameColumnArrayOrListTests.fs +++ b/src/Fantomas.Tests/MultilineBlockBracketsOnSameColumnArrayOrListTests.fs @@ -390,3 +390,59 @@ let fns = // I think the space at the start of the lines above matter |] """ + +[] +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" + } + } + + () +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 148fb56a84..06a6d1a1f8 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -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