From 4d0bd2b0174061fd2418a55b753eb5bd25327a58 Mon Sep 17 00:00:00 2001 From: Florian Verdonck Date: Fri, 16 Apr 2021 08:53:16 +0200 Subject: [PATCH] Indent multiline expression in ForEach. Fixes #1650. (#1655) --- ...ockBracketsOnSameColumnArrayOrListTests.fs | 56 +++++++++++++++++++ src/Fantomas/CodePrinter.fs | 2 +- 2 files changed, 57 insertions(+), 1 deletion(-) 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