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

Add SimplifyLambdaFix #176

Merged
merged 23 commits into from
Sep 22, 2020
Merged

Conversation

DedSec256
Copy link
Contributor

@DedSec256 DedSec256 commented Sep 12, 2020

@DedSec256 DedSec256 force-pushed the ber.a/simplifyLambdaFix branch from 927ca40 to 4cd1105 Compare September 16, 2020 00:01
Copy link
Member

@auduchinok auduchinok left a comment

Choose a reason for hiding this comment

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

Lots of warnings reported in #175 don't have a quick fix implemented here, we should provide it or disable the warnings until it's done.

Please looks at the comments about cases where the quick fix will break code.


let countRedundantArgs expr =
let rec countRedundantArgsRec (expr: IFSharpExpression) i =
let expr = PrefixAppExprNavigator.GetByFunctionExpression expr
Copy link
Member

Choose a reason for hiding this comment

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

It'll fail on this code:

fun a b -> (foo ()) b

use writeCookie = WriteLockCookie.Create(lambda.IsPhysical())
use disableFormatter = new DisableCodeFormatter()

replaceWithCopy lambda.Expression (replaceCandidate.IgnoreInnerParens())
Copy link
Member

Choose a reason for hiding this comment

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

Syntax error after applying:

fun a b -> foo [ 1
                 2 ] b

@@ -33,6 +33,7 @@ type LambdaAnalyzer() =
let hasMatches = i > 0

match expr with
| :? IParenExpr as expr -> compareArgsRec (expr.IgnoreInnerParens()) i
Copy link
Member

Choose a reason for hiding this comment

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

Why not match expr.IgnoreInnerParens() with?

deleteChildRange firstNodeToDelete lastNodeToDelete
addNodesBefore expr [Whitespace(indentDiff)] |> ignore
shiftWithWhitespaceBefore -indentDiff expr
Copy link
Member

Choose a reason for hiding this comment

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

Why shiftWithWhitespaceBefore instead of shiftExpr?


if equal then compareArgsRec app (i + 1) else (hasMatches, false, app)
| _ -> hasMatches, i = pats.Count, expr
if equal then compareArgsRec funExpr (i + 1) else (hasMatches, false, app :> IFSharpExpression)
Copy link
Member

Choose a reason for hiding this comment

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

Is explicit type needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, since type inference tries to infer a narrower type

Copy link
Member

Choose a reason for hiding this comment

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

What does it infer to when :> _ is used?

use disableFormatter = new DisableCodeFormatter()

let indentDiff = lambda.Indent - replaceCandidate.Indent
let expr = ModificationUtil.ReplaceChild(lambda, replaceCandidate)
Copy link
Member

Choose a reason for hiding this comment

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

ReplaceChild says it should not be done this way:

/// <summary>
/// Warning: <paramref name="newChild" /> should not be child of <paramref name="oldChild" />
/// </summary>

Also, the quick fix could inherit ReplaceWithInnerExpressionFixBase.

@@ -148,6 +148,7 @@
<Message value="{0}">
<Argument>getLambdaCanBeReplacedWarningText replaceCandidate</Argument>
</Message>
<QuickFix>ReplaceLambdaFix</QuickFix>
Copy link
Member

Choose a reason for hiding this comment

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

Let's try using a clearer name? Replace lambda with what?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe 'with expression'?

P.S.
to replace it with 'id', I plan to write a separate quickfix

@DedSec256 DedSec256 force-pushed the ber.a/simplifyLambdaFix branch from 6c0782c to f90a838 Compare September 17, 2020 22:56
@auduchinok
Copy link
Member

Another case to consider is struct tuples:

fun (struct (a, b)) -> a, b
fun (a, b) -> struct (a, b)

@DedSec256 DedSec256 force-pushed the ber.a/simplifyLambdaFix branch 2 times, most recently from 3d252f9 to efecff3 Compare September 21, 2020 20:44
@auduchinok
Copy link
Member

auduchinok commented Sep 22, 2020

🤔

module Foo =
    let [<Literal>] Bar = 123

fun Foo.Bar -> Bar

Screenshot 2020-09-22 at 11 47 23

let [<Literal>] Bar = 123

fun Bar -> Bar

Screenshot 2020-09-22 at 11 54 59

@auduchinok auduchinok force-pushed the ber.a/simplifyLambdaFix branch from edade10 to c83b8ea Compare September 22, 2020 14:22
@auduchinok auduchinok merged commit 1b62c48 into JetBrains:net203 Sep 22, 2020
@DedSec256 DedSec256 deleted the ber.a/simplifyLambdaFix branch September 22, 2020 15:37
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.

2 participants