diff --git a/CHANGELOG.md b/CHANGELOG.md index c9bdf7bc5b..97d4214bd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixed * SRTP or condition disappear when non-generic type is used. [#2168](https://github.com/fsprojects/fantomas/issues/2168) * Multiline AbstractSlot without constraints introduces newline [#2175](https://github.com/fsprojects/fantomas/issues/2175) +* Multiline parentheses objectExpression in indexer expression, 2176 [#2176](https://github.com/fsprojects/fantomas/issues/2176) ## [4.7.5] - 2022-03-27 diff --git a/src/Fantomas.Tests/DotIndexedGetTests.fs b/src/Fantomas.Tests/DotIndexedGetTests.fs index 25b9e4be95..6e34729ac6 100644 --- a/src/Fantomas.Tests/DotIndexedGetTests.fs +++ b/src/Fantomas.Tests/DotIndexedGetTests.fs @@ -127,3 +127,42 @@ a ) .Meh().[0] """ + +[] +let ``multiline parentheses objectExpression in indexer expression, 2176`` () = + formatSourceString + false + """ +namespace FSX.Infrastructure + +module Unix = + + let GrabTheFirstStringBeforeTheFirstColon (lines: seq) = + seq { + for line in lines do + yield + (line.Split( + [| ":" |], + StringSplitOptions.RemoveEmptyEntries + )).[0] + } +""" + { config with MaxLineLength = 80 } + |> prepend newline + |> should + equal + """ +namespace FSX.Infrastructure + +module Unix = + + let GrabTheFirstStringBeforeTheFirstColon (lines: seq) = + seq { + for line in lines do + yield + (line.Split( + [| ":" |], + StringSplitOptions.RemoveEmptyEntries + )).[0] + } +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 308db3d8c9..44a3781084 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -2453,7 +2453,12 @@ and genExpr astContext synExpr ctx = expressionFitsOnRestOfLine (short +> idx) (long +> idx) | DotIndexedGet (objectExpr, indexArgs) -> - addParenIfAutoNln objectExpr (genExpr astContext) + let isParen = + match objectExpr with + | Paren _ -> true + | _ -> false + + ifElse isParen (genExpr astContext objectExpr) (addParenIfAutoNln objectExpr (genExpr astContext)) -- "." +> sepOpenLFixed +> genExpr astContext indexArgs