From b7dca797317471654fc693ed5a056cfb90bd73d4 Mon Sep 17 00:00:00 2001 From: Leaxe Date: Tue, 29 Oct 2024 03:28:00 -0500 Subject: [PATCH] Fix multiple line type expression with dotget idempotency (#3133) * Fix multiple line type expression with dotget idempotency * Minor refactor --------- Co-authored-by: nojaf --- CHANGELOG.md | 7 ++++++- src/Fantomas.Core.Tests/ChainTests.fs | 26 ++++++++++++++++++++++++++ src/Fantomas.Core/CodePrinter.fs | 5 +++-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62c59b8641..8f346263cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,14 @@ # Changelog +## 6.3.16 - 2024-10-29 + +### Fixed +* Idempotency problem when calling multi-line discriminated union with generic type parameter. [#3132](https://github.com/fsprojects/fantomas/issues/3132) + ## 6.3.15 - 2024-09-14 ### Fixed -* Non needed parentheses are added around lambda call from tuple/members [#3082](https://github.com/fsprojects/fantomas/issues/3082) +* Non needed parentheses are added around lambda call from tuple/members. [#3082](https://github.com/fsprojects/fantomas/issues/3082) ## 6.3.14 - 2024-09-14 diff --git a/src/Fantomas.Core.Tests/ChainTests.fs b/src/Fantomas.Core.Tests/ChainTests.fs index 83d6db658e..09780fea3d 100644 --- a/src/Fantomas.Core.Tests/ChainTests.fs +++ b/src/Fantomas.Core.Tests/ChainTests.fs @@ -414,3 +414,29 @@ v().w.x.y.z['a'].b """ v().w.x.y.z['a'].b """ + +[] +let ``multiple line type expression with dotget, 3132`` () = + formatSourceString + """ +Animal< + Identifier + > + .Dog( + "Spot" + ) +""" + { config with + MaxDotGetExpressionWidth = 0 + MaxLineLength = 10 } + |> prepend newline + |> should + equal + """ +Animal< + Identifier + > + .Dog( + "Spot" + ) +""" diff --git a/src/Fantomas.Core/CodePrinter.fs b/src/Fantomas.Core/CodePrinter.fs index 357eaf63af..0bed5fcd35 100644 --- a/src/Fantomas.Core/CodePrinter.fs +++ b/src/Fantomas.Core/CodePrinter.fs @@ -1014,8 +1014,9 @@ let genExpr (e: Expr) = (coli sepNone leadingChain (fun idx -> genLink (idx = lastIndex))) (match leadingChain with | [] -> sepNone - | head :: rest -> genLink false head +> indentSepNlnUnindent (genIndentedLinks false rest)) - +> indentSepNlnUnindent (genIndentedLinks false links) + | [ head ] -> genLink false head + | head :: rest -> genLink false head +> indentSepNlnUnindent (genIndentedLinks true rest)) + +> indentSepNlnUnindent (genIndentedLinks true links) | head :: links -> genFirstLinkAndIndentOther head links