-
-
Notifications
You must be signed in to change notification settings - Fork 193
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
Extract setting for preference of newline placement for computation expressions #2746
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @josh-degraw, sorry for the slow response. I've been travelling last week.
From afar this PR looks good. I would explore the option to port some of the Oak
code to Context
.
let isStroustrup (config: FormatConfig) (e: Expr) =
let isMultiRecord = config.MultilineBracketStyle = ExperimentalStroustrup
match e with
| Expr.Record node when isMultiRecord ->
match node.Extra with
| RecordNodeExtra.Inherit _
| RecordNodeExtra.With _ -> false
| RecordNodeExtra.None -> true
| Expr.AnonRecord node when isMultiRecord ->
match node.CopyInfo with
| Some _ -> false
| None -> true
| Expr.ArrayOrList _ when isMultiRecord -> true
| Expr.NamedComputation _ when config.PreferComputationExpressionNameOnSameLine -> true
| _ -> false
I would however like to have another name for this.
The Prefer
in PreferComputationExpressionNameOnSameLine
really rubs me the wrong way. The word prefer
is a bit excessive, given that it is a setting, it already implies a preference. On the top of my head, I would go in the direction of StroustrupComputationExpression
. I'm not sure that exact name is what we want though, but I think Stroustrup
is just so well known on the streets that I would somehow incorporate it.
If I understand the code right now, you only need to enable the setting to do something.
Having MultilineBracketStyle = Stroustrup
is not required to enable the code. If that is the case, I do like that.
Lastly, this would need documentation. Perhaps we need to update the configuration.fsx
script to use a local version of Fantomas.Core
instead of a version on NuGet. Otherwise, we always need to play catch-up.
src/Fantomas.Core/Context.fs
Outdated
|
||
if isStroustrup then | ||
if isNamedComputationAndPreferSameLine e ctx || isStroustrup then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is TriviaBefore
in the NamedComputation
that should be captured as well.
Example:
[<Test>]
let ``prefer computation expression name on same line, with trivia`` () =
formatSourceString
false
"""
let t =
//
task {
let! thing = otherThing ()
return 5
}
"""
config
|> prepend newline
|> should
equal
"""
let t =
//
task {
let! thing = otherThing ()
return 5
}
"""
src/Fantomas.Core/SyntaxOak.fs
Outdated
@@ -1738,10 +1738,6 @@ type Expr = | |||
match node.CopyInfo with | |||
| Some _ -> false | |||
| None -> true | |||
| Expr.NamedComputation node -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a thought but I think this member should be extracted into a function in Context
.
If you have that, you can pass the FormatConfig
into it and just add an extra when
expression for the named computation expression.
I think this makes sense as it further removes the coupling between the Oak
model and any coding style.
By refactoring this, I think the current flow could be preserved slightly easier.
Yep, that was the goal, this setting should be able to be enabled whether or not the user has enabled
I agree the name is pretty chunky, I think removing
I see what you mean, the only hesitation I have to that is that like you mentioned this is intended to be fully orthogonal to the |
Yeah, I can see why you don't want to attach it to the I'm not overly crazy about the |
An alternative could be to do something like |
Oh, I like that one. Maybe |
Yeah that's longer but I think I'm fine with that. It's long but it still doesn't feel quite as clunky as my original suggested name, IMO. I'm fine with that if you are. |
This looks good! The only thing I'm really missing is a documentation entry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! I'm very happy you pulled this off with minimal changes.
…xpressions (#2746) * Add new setting * Add test * Implement new setting * Add setting-specific tests to its own file * Fix an issue with applying to lambdas * Fix issue when applying to LetBang and AndBang * Fix all failing tests, some cleanup * Remove invalid tests, some more cleanup * Rename some helpers * temp * Cleanup, add test * Rename setting * Use local Fantomas.Core reference for Configuration.fsx. * Rename some things and fix assertion * Update docs * Simplify isStroustrupStyleExpr * Rename test file to match setting name. * Add additional test to highlight that settings don't affect each other. --------- Co-authored-by: nojaf <[email protected]>
…xpressions (#2746) * Add new setting * Add test * Implement new setting * Add setting-specific tests to its own file * Fix an issue with applying to lambdas * Fix issue when applying to LetBang and AndBang * Fix all failing tests, some cleanup * Remove invalid tests, some more cleanup * Rename some helpers * temp * Cleanup, add test * Rename setting * Use local Fantomas.Core reference for Configuration.fsx. * Rename some things and fix assertion * Update docs * Simplify isStroustrupStyleExpr * Rename test file to match setting name. * Add additional test to highlight that settings don't affect each other. --------- Co-authored-by: nojaf <[email protected]>
…xpressions (#2746) * Add new setting * Add test * Implement new setting * Add setting-specific tests to its own file * Fix an issue with applying to lambdas * Fix issue when applying to LetBang and AndBang * Fix all failing tests, some cleanup * Remove invalid tests, some more cleanup * Rename some helpers * temp * Cleanup, add test * Rename setting * Use local Fantomas.Core reference for Configuration.fsx. * Rename some things and fix assertion * Update docs * Simplify isStroustrupStyleExpr * Rename test file to match setting name. * Add additional test to highlight that settings don't affect each other. --------- Co-authored-by: nojaf <[email protected]>
…xpressions (#2746) * Add new setting * Add test * Implement new setting * Add setting-specific tests to its own file * Fix an issue with applying to lambdas * Fix issue when applying to LetBang and AndBang * Fix all failing tests, some cleanup * Remove invalid tests, some more cleanup * Rename some helpers * temp * Cleanup, add test * Rename setting * Use local Fantomas.Core reference for Configuration.fsx. * Rename some things and fix assertion * Update docs * Simplify isStroustrupStyleExpr * Rename test file to match setting name. * Add additional test to highlight that settings don't affect each other. --------- Co-authored-by: nojaf <[email protected]>
…xpressions (#2746) * Add new setting * Add test * Implement new setting * Add setting-specific tests to its own file * Fix an issue with applying to lambdas * Fix issue when applying to LetBang and AndBang * Fix all failing tests, some cleanup * Remove invalid tests, some more cleanup * Rename some helpers * temp * Cleanup, add test * Rename setting * Use local Fantomas.Core reference for Configuration.fsx. * Rename some things and fix assertion * Update docs * Simplify isStroustrupStyleExpr * Rename test file to match setting name. * Add additional test to highlight that settings don't affect each other. --------- Co-authored-by: nojaf <[email protected]>
I'm very open to bike-shedding the name of the setting here, I just went with what made the most sense in my head at the time but I'm open to alternatives if something makes more sense.
Closes #2276