-
-
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
Be more cautious when adding a sepSpace before paren lambda #2232
Conversation
Hey, sorry for the delay. This PR touches a bit more than that. Though I must admit it can be subtle.
And to not need to repeat everything for // functionName arg1 arg2 (fun x y z -> ...)
| AppWithLambda (e, es, lpr, lambda, rpr, pr) -> ... And parameterize the logic to add a space or not. I hope this helps, good luck. |
It sure does. Thanks. I'll try to come up with something. |
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.
Getting closer, keep it up!
src/Fantomas.Core/CodePrinter.fs
Outdated
@@ -2088,215 +2088,12 @@ and genExpr astContext synExpr ctx = | |||
|
|||
expressionFitsOnRestOfLine short long | |||
|
|||
| DotGetAppWithLambda ((e, es, lpr, lambda, rpr, pr), lids) -> | |||
genAppWithLambda (e, es, lpr, lambda, rpr, pr) false (Some lids) astContext |
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.
I wouldn't pass in the lids
of the DotGet
here to the genAppWithLambda
function.
What you want to control from outside the genAppWithLambda
is whether there should be a space or not.
I would pass in a function (that adds the space) instead of a boolean.
Something long the lines of:
| DotGetAppWithLambda ((e, es, lpr, lambda, rpr, pr), lids) ->
leadingExpressionIsMultiline
(genAppWithLambda astContext sepNone (e, es, lpr, lambda, rpr, pr))
(fun isMultline -> // print lids and do the right thing based on isMultline)
// functionName arg1 arg2 (fun x y z -> ...)
| AppWithLambda (e, es, lpr, lambda, rpr, pr) ->
let sepSpaceAfterFunctionName =
let sepSpaceBasedOnSetting e =
match e with
| Paren _ -> sepSpace
| UppercaseSynExpr -> (fun ctx -> onlyIf ctx.Config.SpaceBeforeUppercaseInvocation sepSpace ctx)
| LowercaseSynExpr -> (fun ctx -> onlyIf ctx.Config.SpaceBeforeLowercaseInvocation sepSpace ctx)
match es with
| [] -> sepSpaceBasedOnSetting e
| _ -> sepSpace
genAppWithLambda astContext sepSpaceAfterFunctionName (e, es, lpr, lambda, rpr, pr)
The benefit here is that genAppWithLambda
has no knowledge about lids
so the function only does one thing (namely printing a function application that ends with a lambda).
Oh and in a lot of places astContext
is the first argument.
This is a bit historically.
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.
Thanks for the review and the suggestions. Really appreciate your patience.
I hope I'm not too confused here but I think this is now more in line with our default config of SpaceBeforeUppercaseInvocation = false
. As a consequence there were some tests which needed adjustments.
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.
I think the changes in the existing tests are all valid.
src/Fantomas.Core/CodePrinter.fs
Outdated
+> genSynLongIdent true lids | ||
+> unindent) | ||
else | ||
(indent >> genSynLongIdent true lids)) |
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.
This is dangerous that have an indent
without later restoring using an unindent
.
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.
All tests also seem to run just fine when removing indent >>
so not sure if we still need that here.
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.
Mmh, yeah. I think that was just an artefact of me screwing around.
src/Fantomas.Core/CodePrinter.fs
Outdated
| DotGetAppWithLambda ((e, es, lpr, lambda, rpr, pr), lids) -> | ||
leadingExpressionIsMultiline | ||
(genAppWithLambda astContext sepNone (e, es, lpr, lambda, rpr, pr)) | ||
(fun isMultline -> |
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.
Typo isMultiline
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.
fixed
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.
A couple of very small things left, but this is looking good!
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.
Many thanks for this!
- Fixes 2041 and 2231 - Adjust expected results of other tests
- Move logic of AppWithLambda to genAppWithLambda function - narrow scope down to just fix 2231
- adjust tests - add back test for fsprojects#2041 - add back CHANGELOG entry about fsprojects#2041
- Remove superfluous indent
Fixes #2231
Fixes #2041
Not super sure about this one and it may need more discussion, but I think we are a bit too liberal adding spaces before the lparen of lambda arguments. This can easily break calls to Linq methods. See the example in #2231