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

Update config to accept a single option for multiline_bracket_style #2658

Merged
merged 11 commits into from
Dec 23, 2022

Conversation

josh-degraw
Copy link
Contributor

Updates configuration to accept a single option for multiline bracket style. Names could be bike-shedded if necessary. I made sure to keep it backwards compatible, so existing editorconfig settings using either of the previously existing settings will be respected as before.

One other point I'm not in love with is that it currently requires open Fantomas.Core.FormatConfig any time it's used. I think I'd rather just move the type directly into the Fantomas.Core namespace, but I just left it for now. If you're open to that I'll move it.

Closes #2425

Copy link
Contributor

@nojaf nojaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very good, well done!
A lot of nitpicks, but overall nothing major to adress.

We can moveFormatConfig to the Fantomas.Core namespace in the next major release (6.x). It would be breaking if we did it now. Unless we alias it.


static member OfConfigString(cfgString: string) =
match cfgString with
| "classic" -> Some(box Classic)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to box here, EndOfLineStyle doesn't do it, MultilineFormatterType does.
Let's settle on not boxing here and always box in the EditorConfig.fs code.

@@ -25,6 +25,24 @@ type MultilineFormatterType =
| "number_of_items" -> Some(box MultilineFormatterType.NumberOfItems)
| _ -> None

type MultilineBracketStyle =
| Classic
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to go with something other else for Classic.
I think Don call this Cramped style. Pico is another option I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like cramped!

@@ -79,8 +79,11 @@ module WriterModel =
let update maxPageWidth cmd m =
let doNewline m =
let m = { m with Indent = max m.Indent m.AtColumn }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove these additional newlines. You didn't touch this code.

src/Fantomas.Core/FormatConfig.fs Outdated Show resolved Hide resolved
src/Fantomas.Core/Context.fs Outdated Show resolved Hide resolved
src/Fantomas.Core/Context.fs Outdated Show resolved Hide resolved
@@ -1027,7 +1043,14 @@ let sepSemi (ctx: Context) =
<| ctx

let ifAlignBrackets f g =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename this to ifAlignOrStroustupBrackets?

match ctx.Config.MultilineBracketStyle with
| Aligned
| ExperimentalStroustrup -> aligned
| Classic when (List.exists (fun (fieldNode: FieldNode) -> fieldNode.XmlDoc.IsSome) node.Fields) -> aligned
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code was already a bit icky but could you extract List.exists (fun (fieldNode: FieldNode) -> fieldNode.XmlDoc.IsSome) node.Fields to some value? Call it anyFieldHasXmlDoc maybe.

@josh-degraw
Copy link
Contributor Author

We can moveFormatConfig to the Fantomas.Core namespace in the next major release (6.x). It would be breaking if we did it now. Unless we alias it.

FWIW, I was specifically talking about just moving MultilineBracketStyle into Fantomas.Core, not all of FormatConfig.

Copy link
Member

@dawedawe dawedawe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very, very nice, I'm all in favor of this.
Just one thing:
Configuration.fsx needs a little bit of adjustment.

@nojaf
Copy link
Contributor

nojaf commented Dec 23, 2022

FWIW, I was specifically talking about just moving MultilineBracketStyle into Fantomas.Core, not all of FormatConfig.

Well, I think there is value in having most of the config type in that namespace.
That way you can open Fantomas.Core and access the CodeFormatter API without any additional open statements.

Configuration.fsx needs a little bit of adjustment.

You can only update that once there is a version on NuGet with these changes.

@dawedawe
Copy link
Member

Configuration.fsx needs a little bit of adjustment.

You can only update that once there is a version on NuGet with these changes.

Uh, sorry. Nevermind...

Copy link
Contributor

@nojaf nojaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @josh-degraw! I'm very happy to see movement on this front.

@nojaf nojaf merged commit 898c3c5 into fsprojects:v5.2 Dec 23, 2022
nojaf pushed a commit that referenced this pull request Jan 2, 2023
…2658)

* Add BracketStyle DU, update everything except editorconfig parsing

* Rename enum and config member

* Update editorconfig parsing to remain backwards-compatible

* Remove need for computed property on FormatConfig

* Fix rebase issues

* Rename some backcompat tests

* Don't box in MultilineBracketStyle.OfConfigString

* Rename Classic to Cramped

* Remove ifStroustrup and ifStroustrupElse & revert unintended newlines

* Rename ifAlignBrackets to ifAlignOrStroustrupBrackets

* Refactor record multiline expression condition
@josh-degraw josh-degraw deleted the bracket-du branch January 11, 2023 18:54
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

Successfully merging this pull request may close these issues.

3 participants