Skip to content

Commit

Permalink
Fix #2149 comment lost between tuple type (#2488)
Browse files Browse the repository at this point in the history
* Fix #2149 comment lost between tuple type

* Add new line to test

* Format code

Co-authored-by: alanlomeli <45440937+yisusalanpng@users.noreply.github.com>
Co-authored-by: nojaf <florian.verdonck@outlook.com>
  • Loading branch information
3 people committed Sep 9, 2022
1 parent a3ea945 commit c1a16e6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* --check should fail if the number of newlines is different. [#2461](https://github.com/fsprojects/fantomas/issues/2461)
* Comment after closing brace of computation expression is lost. [#2466](https://github.com/fsprojects/fantomas/issues/2466)
* Match statements should not be split into separate lines between parentheses. [#2044](https://github.com/fsprojects/fantomas/issues/2044)
* Comments between tuple type are lost #2149. [#2149](https://github.com/fsprojects/fantomas/issues/2149)

## [5.0.0-beta-008] - 2022-08-30

Expand Down
34 changes: 34 additions & 0 deletions src/Fantomas.Core.Tests/CommentTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2481,3 +2481,37 @@ The same indentation is ensured to be consistent in a source file.
Default = 4.
*)
"""

[<Test>]
let ``trivia above tuple parameter in function type, 2149`` () =
formatSourceString
true
"""
namespace Foo

type X =
static member AsBeginEnd : computation:('Arg -> Async<'T>) ->
// The 'Begin' member
('Arg * System.AsyncCallback * obj -> System.IAsyncResult) *
// The 'End' member
(System.IAsyncResult -> 'T) *
// The 'Cancel' member
(System.IAsyncResult -> unit)
"""
config
|> prepend newline
|> should
equal
"""
namespace Foo

type X =
static member AsBeginEnd:
computation: ('Arg -> Async<'T>) ->
// The 'Begin' member
('Arg * System.AsyncCallback * obj -> System.IAsyncResult) *
// The 'End' member
(System.IAsyncResult -> 'T) *
// The 'Cancel' member
(System.IAsyncResult -> unit)
"""
2 changes: 2 additions & 0 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4008,7 +4008,9 @@ and genTypeList astContext node =

let shortExpr = gt sepStar
let longExpr = gt (sepSpace +> sepStarFixed +> sepNln)

expressionFitsOnRestOfLine shortExpr longExpr
|> genTriviaFor SynType_Tuple t.Range

| _, [ ArgInfo (ats, so, isOpt) ] ->
match t with
Expand Down

0 comments on commit c1a16e6

Please sign in to comment.