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

Code reformat breaks the code #58

Closed
drhumlen opened this issue Aug 16, 2019 · 8 comments
Closed

Code reformat breaks the code #58

drhumlen opened this issue Aug 16, 2019 · 8 comments

Comments

@drhumlen
Copy link

drhumlen commented Aug 16, 2019

When running code Reformat Code (cmd+opt+L), the produced code is broken because of indentation when using []:

[<CLIMutable>]
type CreateUser =
    { [<JsonRequired>]
      Name: string }

is changed to:

[<CLIMutable>]
type CreateUser =
    {  [<JsonRequired>]
      Name: string }

^ Notice the extra space in front of []. That make the code on the next line "off side", which causes the whole parsing to fail.


Also, one unrelated question: I read on fantomas' site that Rider uses it for its formatting. However, fantomas' formatting is way more opinionated than Rider's. Imo that's mostly a good thing, but it would be nice if it was configurable so that I could choose fantomas' more opinionated formatting if I wanted to.

@nojaf
Copy link
Contributor

nojaf commented Aug 16, 2019

Hey, Rider uses Fantomas so if there is a problem you should report in https://github.com/fsprojects/fantomas/.

Could you try this out in the online tool? https://jindraivanek.gitlab.io/fantomas-ui/#?fantomas=preview-trivia
We are working on a new version of Fantomas and some things might already be fixed.
If you encounter an issue in the tool (using the latest version, vNext 3.X), please create an issue using the create issue link below.

@drhumlen
Copy link
Author

@nojaf : Trying the code above in the online tool you linked gives correct code. When I do the same in Rider, it gives the wrong code. So it seems to have been fixed in Fantomas then I guess :D so unless the error is in Rider, it will probably start working again when you roll out your new version.

Is there an ETA on that? Also, can you add formatting options to the (fantomas) code formatting in Rider? Fantomas has a ton of options, and Rider seems to deviate quite far from Fantomas' default settings.

@auduchinok
Copy link
Member

@nojaf : Trying the code above in the online tool you linked gives correct code. When I do the same in Rider, it gives the wrong code.

This could be due to Rider uses different default settings compared to the online tool. We have PreserveEndOfLine enabled by default to try to preserve used formatting style where possible.

Is there an ETA on that? Also, can you add formatting options to the (fantomas) code formatting in Rider? Fantomas has a ton of options

All Fantomas options are already in File | Settings | Editor | Code Style | F#.

@drhumlen
Copy link
Author

drhumlen commented Aug 16, 2019

@auduchinok : Ah. Nice. I tried to search for "fantomas" in the settings without finding anything, so that's why I assumed the settings wasn't there. But that's the fantomas settings. I see. Nice 😄

This could be due to Rider uses different default settings compared to the online tool. We have PreserveEndOfLine enabled by default to try to preserve used formatting style where possible.

I tried removing PreserveEndOfLine now, and now none of my code breaks when I hit Reformat Code 😄. I don't always agree with Fantomas (it formats certain code in a weird way), but it's nice to have the option to see how Fantomas' would've formatted my code by comparison.

--edit--
I did notice one thing though: the Indent size option does nothing it seems..? 🤔 Maybe that's a bug? I tried changing it from 4->2, but it still indents with 4...?

@rulrok
Copy link

rulrok commented Oct 2, 2019

Hello, I'm experiencing this annoying issue as well.
Also, it deletes the code that follows a certain portion of my file. Very awkward.

I created a bug on Rider bug track but they asked to go on fantomas project.

There, I found that the bug had been fixed already.

I'd like that the formatting would work without having to change the PreserveEndOfLine option.

I prefer having:

    and SubscriptionSuspendedEvent = {
        SubscriptionId: SubscriptionId
        AccountId: string
    }

rather than (PreserveEndOfLine disabled):

    and SubscriptionSuspendedEvent =
        { SubscriptionId: SubscriptionId
          AccountId: string }

@drhumlen
Copy link
Author

drhumlen commented Oct 2, 2019

Maybe @nojaf can answer? ^

@rulrok I too prefer the former style. While the second style is prettier in many ways, the former is more practical and will result in less git diff when add another field. It's almost more similar to how you would define types in other languages like TypeScript.

@nojaf Maybe there should be an option for formatting types & lists in the former style? Or has that already been discussed somewhere?

@nojaf
Copy link
Contributor

nojaf commented Oct 2, 2019

Hey, this looks like fsprojects/fantomas#453

@auduchinok
Copy link
Member

Fixed in 2019.3 with Fantomas update.

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

No branches or pull requests

4 participants