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

Idempotency problem when formatting quotations #2203

Closed
1 of 3 tasks
sergey-tihon opened this issue Apr 17, 2022 · 2 comments · Fixed by #2211
Closed
1 of 3 tasks

Idempotency problem when formatting quotations #2203

sergey-tihon opened this issue Apr 17, 2022 · 2 comments · Fixed by #2211

Comments

@sergey-tihon
Copy link
Member

Issue created from fantomas-online

Original code

let action =
    <@
        let msg = %httpRequestMessageWithPayload
        RuntimeHelpers.fillHeaders msg %heads
        async {
            let! response = (%this).HttpClient.SendAsync(msg) |> Async.AwaitTask
            return response.EnsureSuccessStatusCode().Content
        }
    @>

Formatted code

let action =
    <@ let msg = %httpRequestMessageWithPayload
    RuntimeHelpers.fillHeaders msg %heads

    async {
        let! response =
            (%this).HttpClient.SendAsync(msg)
            |> Async.AwaitTask

        return response.EnsureSuccessStatusCode().Content
    } @>

Reformatted code

let action =
    <@ let msg = %httpRequestMessageWithPayload

       RuntimeHelpers.fillHeaders
           msg
           %heads

           async {
           let! response =
               (%this).HttpClient.SendAsync(msg)
               |> Async.AwaitTask

           return response.EnsureSuccessStatusCode().Content
       } @>

Problem description

Fantomas was not able to produce the same code after reformatting the result.

Extra information

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

Options

Fantomas master branch at 2022-04-12T06:26:27Z - 7b35c89

Default Fantomas configuration

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

@nojaf
Copy link
Contributor

nojaf commented Apr 19, 2022

Hello, thank you for reporting this!

I believe we currently, don't have a good way of dealing with multiline quotation expressions.
We should extend

let e =
match e2 with
| DotGetApp _ -> atCurrentColumnIndent (genExpr astContext e2)
| _ -> genExpr astContext e2
ifElse isRaw (!- "<@@ " +> e -- " @@>") (!- "<@ " +> e -- " @>")

to something like:

    let e = expressionFitsOnRestOfLine (genExpr astContext e2) (indent +> sepNln +> genExpr astContext e2 +> unindent +> sepNln)
    ifElse isRaw (!- "<@@" +> sepSpace +> e => sepSpace +> !- " @@>") (!- "<@" +> sepSpace +> e +> sepSpace +>  !- "@>")

(Didn't test this code)

This will slightly change the outcome of #2154
But as I reported this one myself, it should be fine to change it.

Are you interested in submitting a PR for this one?

@sergey-tihon
Copy link
Member Author

Are you interested in submitting a PR for this one?

Sorry, no, at least not now.

This bug is not critical at all, I just tried Fantomas on TypeProvider project and discovered this issues.
It may leave for a while in Open state if it is not critical for others

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants