-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Introduce local variable supporting target-type new syntax #76342
base: main
Are you sure you want to change the base?
Introduce local variable supporting target-type new syntax #76342
Conversation
@@ -54,7 +55,7 @@ protected override Document IntroduceLocal( | |||
[VariableDeclarator( | |||
newLocalNameToken.WithAdditionalAnnotations(RenameAnnotation.Create()), | |||
argumentList: null, | |||
EqualsValueClause(expression.WithoutTrivia()))])); | |||
EqualsValueClause(expression.WithAdditionalAnnotations(Simplifier.Annotation)).WithoutTrivia())])); |
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.
Is there any chance that this might work? It does not but I'm not exactly sure why it doesn't. I thought it might.
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 would not use the simplifier annotation. I would just generate the right expected results based ont he user's options specified.
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 took the time to debug TestIntroduceLocalInExpressionBodiedIndexer
. It is my understanding that var
in that test (instead of explicit type name) is added in a postprocessing step. However, that postprocessing is not able to convert it to "target-type form".
So then your suggestion is a reasonably easy solution here.
Happy to help with this. And we would accept a PR for this as logn as the the following holds:
If you can confirm this is the logic the PR maintains,a nd you have tests for this, i can review asap. I can also review any questions blocking you if you call them out. Thanks! |
Yes, that's I would like to achieve. I added a few comments to specific lines of code where some help would be great |
b01eca3
to
12a96b8
Compare
FYI, it's vacation time. So things may be slow to respond. Feel free to ping me on jan2 if you haven't heard from anyone else! |
12a96b8
to
42634bd
Compare
Thank you for the heads up. It would be great if at least tests could be run for the PR, I would get some feedback. If not, no problem, I can wait. Merry Christmas! |
Tears will automatically run for you pr as long as it builds successfully :-) |
Hm, I'm not too sure what that CI error
is about. |
src/Features/CSharpTest/IntroduceVariable/IntroduceVariableTests.cs
Outdated
Show resolved
Hide resolved
src/Features/CSharp/Portable/IntroduceVariable/CSharpIntroduceVariableService_IntroduceLocal.cs
Outdated
Show resolved
Hide resolved
var updatedExpression = expression.WithoutTrivia(); | ||
|
||
if (options.SimplifierOptions is CSharpSimplifierOptions csOptions && csOptions.ImplicitObjectCreationWhenTypeIsApparent.Value | ||
&& csOptions.GetUseVarPreference() == UseVarPreference.None) |
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.
needs docs explaining what is going on.
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 documented my approach. It is a really conservative one (either target-type new syntax is used exclusively, or codebase opts into using "var" in any case). My reasoning is as follows:
- It's a very conservative change, so it should not introduce some unwanted behavior.
- It's hard for me to tell what codebases in the wild actually use and want (i.e., how complex the implementation should be), so I basically wanted to cover my use-case because I understand it well (and hopefully, it's what other customers will like).
- With my PR, it should be easy to add missing cases, if people actually want it.
That being said, I'm certainly open to modify it.
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 it is what #76342 (comment) mentions.
src/Features/CSharp/Portable/IntroduceVariable/CSharpIntroduceVariableService_IntroduceLocal.cs
Outdated
Show resolved
Hide resolved
@dotnet/roslyn-infrastructure can someone help this community member with their PR? something has gone wonky with the test machines. Thanks! |
Perhaps it was my fault. I fixed a few failing tests. |
Our project uses target-type new syntax. Whenever, I have a line like this one:
and I want to extract a new variable from the marked expression, I get
but I would like to get
That's why I created this PR. Are you interested in such feature?1 Could you give me some pointers how to finish this PR (as it does not work at the moment)?
Footnotes
I sure am as I hit this daily. :) ↩