Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix newline idempotency issue with multiline abstract members #2183

Merged
merged 1 commit into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,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)

## [4.7.5] - 2022-03-27

Expand Down
23 changes: 23 additions & 0 deletions src/Fantomas.Tests/NewlineBetweenTypeDefinitionAndMembersTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,26 @@ type A =
| B x -> x
| _ -> failwith "shouldn't happen"
"""

[<Test>]
let ``multiline abstract member without constraints, 2175`` () =
formatSourceString
false
"""
type FuseSortFunctionItem =
abstract Item: key: string -> U2<{| ``$``: string |}, ResizeArray<{| ``$``: string; idx: float |}>> with get, set
abstract X : int
"""
{ config with MaxLineLength = 60 }
|> prepend newline
|> should
equal
"""
type FuseSortFunctionItem =
abstract Item:
key: string ->
U2<{| ``$``: string |}, ResizeArray<{| ``$``: string
idx: float |}>> with get, set

abstract X: int
"""
7 changes: 6 additions & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4835,7 +4835,12 @@ and genMemberDefn astContext node =
+> ifElse hasGenerics sepColonWithSpacesFixed sepColon
+> autoIndentAndNlnIfExpressionExceedsPageWidth (genTypeList astContext namedArgs)
-- genPropertyKind (not isFunctionProperty) mf.MemberKind
+> autoIndentAndNlnIfExpressionExceedsPageWidth (genConstraints astContext t vi)
+> onlyIf
(match t with
| TWithGlobalConstraints _ -> true
| _ -> false)
autoIndentAndNlnIfExpressionExceedsPageWidth
(genConstraints astContext t vi)

| md -> failwithf "Unexpected member definition: %O" md
|> genTriviaFor (synMemberDefnToFsAstType node) node.Range
Expand Down