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

Oscillating newlines in custom computation expression #1463

Closed
1 of 3 tasks
theothornhill opened this issue Feb 19, 2021 · 8 comments
Closed
1 of 3 tasks

Oscillating newlines in custom computation expression #1463

theothornhill opened this issue Feb 19, 2021 · 8 comments

Comments

@theothornhill
Copy link
Contributor

Issue created from fantomas-online

Code

namespace Fantomas

module Mapper =

    aggregateResult {
        apply id in someFunction
        also displayableId in AggregateResult.map (fun x -> string x.Z) g
        also person in getThing y |> AggregateResult.ofResult
        also more in AggregateResult.bind
                         (getLongfunctionNameWithLotsOfStuff
                          >> AggregateResult.ofResult)
                         mainThingThatHappens

        return
            { Id = id
              DisplayableId = displayableId
              More = more }
    }

Result

namespace Fantomas

module Mapper =

    aggregateResult {
        apply id in someFunction
        also displayableId in AggregateResult.map (fun x -> string x.Z) g
        also person in getThing y |> AggregateResult.ofResult

        also more in AggregateResult.bind
                         (getLongfunctionNameWithLotsOfStuff
                          >> AggregateResult.ofResult)
                         mainThingThatHappens

        return
            { Id = id
              DisplayableId = displayableId
              More = more }
    }

Problem description

Fantomas adds a newline here, which by itself I don't mind. But when fantomas is run again on the newly outputted code, it reverts back to the first example. This goes back and forth every time fantomas runs, which makes for an unstable experience. Also it seems for format things correctly inside the aggregateResult, apart from the oscillating newlines. This issue does seem similar to #1227 though?

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 at 02/19/2021 13:56:09 - 3304470

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 Feb 20, 2021

Hello Theodor, thank you for taking the time to report this issue.
The problem is indeed from the same problem space as #1227.

To solve this you will need to add | SynExpr.JoinIn _ -> genTriviaFor SynExpr_JoinIn synExpr.Range to

|> (match synExpr with
| SynExpr.App _ -> genTriviaFor SynExpr_App synExpr.Range
| SynExpr.Const _ -> genTriviaFor SynExpr_Const synExpr.Range
| SynExpr.AnonRecd _ -> genTriviaFor SynExpr_AnonRecd synExpr.Range
| SynExpr.Record _ -> genTriviaFor SynExpr_Record synExpr.Range
| SynExpr.Ident _ -> genTriviaFor SynExpr_Ident synExpr.Range
| SynExpr.IfThenElse _ -> genTriviaFor SynExpr_IfThenElse synExpr.Range
| SynExpr.Lambda _ -> genTriviaFor SynExpr_Lambda synExpr.Range
| SynExpr.ForEach _ -> genTriviaFor SynExpr_ForEach synExpr.Range
| SynExpr.For _ -> genTriviaFor SynExpr_For synExpr.Range
| SynExpr.Match _ -> genTriviaFor SynExpr_Match synExpr.Range
| SynExpr.MatchBang _ -> genTriviaFor SynExpr_MatchBang synExpr.Range
| SynExpr.YieldOrReturn _ -> genTriviaFor SynExpr_YieldOrReturn synExpr.Range
| SynExpr.YieldOrReturnFrom _ -> genTriviaFor SynExpr_YieldOrReturnFrom synExpr.Range
| SynExpr.TryFinally _ -> genTriviaFor SynExpr_TryFinally synExpr.Range
| SynExpr.LongIdentSet _ -> genTriviaFor SynExpr_LongIdentSet synExpr.Range
| SynExpr.ArrayOrList _ -> genTriviaFor SynExpr_ArrayOrList synExpr.Range
| SynExpr.ArrayOrListOfSeqExpr _ -> genTriviaFor SynExpr_ArrayOrListOfSeqExpr synExpr.Range
| SynExpr.Paren _ -> genTriviaFor SynExpr_Paren synExpr.Range
| SynExpr.InterpolatedString _ -> genTriviaFor SynExpr_InterpolatedString synExpr.Range
| SynExpr.Tuple _ -> genTriviaFor SynExpr_Tuple synExpr.Range
| SynExpr.DoBang _ -> genTriviaFor SynExpr_DoBang synExpr.Range
| SynExpr.TryWith _ -> genTriviaFor SynExpr_TryWith synExpr.Range
| SynExpr.New _ -> genTriviaFor SynExpr_New synExpr.Range
| SynExpr.Assert _ -> genTriviaFor SynExpr_Assert synExpr.Range
| SynExpr.While _ -> genTriviaFor SynExpr_While synExpr.Range
| SynExpr.MatchLambda _ -> genTriviaFor SynExpr_MatchLambda synExpr.Range
| SynExpr.LongIdent _ -> genTriviaFor SynExpr_LongIdent synExpr.Range
| SynExpr.DotGet _ -> genTriviaFor SynExpr_DotGet synExpr.Range
| SynExpr.Upcast _ -> genTriviaFor SynExpr_Upcast synExpr.Range
| SynExpr.Downcast _ -> genTriviaFor SynExpr_Downcast synExpr.Range
| SynExpr.DotIndexedGet _ -> genTriviaFor SynExpr_DotIndexedGet synExpr.Range
| SynExpr.DotIndexedSet _ -> genTriviaFor SynExpr_DotIndexedSet synExpr.Range
| SynExpr.ObjExpr _ -> genTriviaFor SynExpr_ObjExpr synExpr.Range
| _ -> id)

Are you interested in submitting a PR? If so, please read our Contribution Guidelines and add your test to ComputationExpressionTests.

@theothornhill
Copy link
Contributor Author

Thanks for replying :)

I will look into creating a pr this evening!

@nojaf
Copy link
Contributor

nojaf commented Feb 20, 2021

Wonderful! Thanks for taking the time. If you have any question along the way, feel free to ask!

@theothornhill
Copy link
Contributor Author

theothornhill commented Feb 20, 2021

Not sure what went wrong, but I checked fantomas-tools again, and it seemed to exhibit the same behavior as before the fix. It is using the latest commit from master. Do you know what went wrong here? It is not showing the same behavior that the tests do.

@nojaf
Copy link
Contributor

nojaf commented Feb 20, 2021

Hmm, not sure what happened there.
The latest deploy seems to be present. I did tinker with the tool today, perhaps my changes are related to the current behaviour.
It works on my machine though, pretty sure this is unrelated to your fix.

@theothornhill
Copy link
Contributor Author

Ok! Thanks for getting back to me. Let me know if there is something more for me to do :)

@nojaf
Copy link
Contributor

nojaf commented Feb 21, 2021

I redeployed again via an empty commit, the problem seems resolved now. Can you confirm?

@theothornhill
Copy link
Contributor Author

Yep, works on my end! Great :)

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

No branches or pull requests

2 participants