fantomas icon indicating copy to clipboard operation
fantomas copied to clipboard

Comments between tuple type are lost

Open nojaf opened this issue 2 years ago • 2 comments

Issue created from fantomas-online

Code

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)

Result

namespace Foo

type X =
    static member AsBeginEnd:
        computation: ('Arg -> Async<'T>) ->
            ('Arg * System.AsyncCallback * obj -> System.IAsyncResult) *
            (System.IAsyncResult -> 'T) *
            (System.IAsyncResult -> unit)

Problem description

Please describe here the Fantomas problem you encountered. Check out our Contribution Guidelines.

Extra information

  • [ ] The formatted result breaks by code.
  • [ ] The formatted result gives compiler warnings.
  • [ ] I or my company would be willing to help fix this.

Options

Fantomas master branch at 2022-03-11T14:10:39Z - c9407209c3ed3a12aa9d099173598fa92027f88d

Default Fantomas configuration

Signature file

Did you know that you can ignore files when formatting from fantomas-tool or the FAKE targets by using a .fantomasignore file?

nojaf avatar Mar 11 '22 14:03 nojaf

The problem here is that a comment is assigned to SynType_Typle and is not being printed somewhere in the CodePrinter.

@edgarfgp this can be a good issue to get your feet wet if you are interested. Somewhere in CodePrinter you need to add genTriviaFor SynType_Tuple tupleRange in order for the comment to be restored.

The code that is printing the tuple information needs to be wrapped with this.

I won't tell you where exactly just yet. Try and find the right location based on the AST.

Be aware that this issue inside a signature file.

You can use

[<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)
"""

nojaf avatar Jun 29 '22 20:06 nojaf

Nice 👍🏻. Will take a look

edgarfgp avatar Jun 29 '22 20:06 edgarfgp