Skip to content

IntroduceLocal on simple names#25856

Merged
jcouv merged 2 commits intodotnet:dev15.7.xfrom
jcouv:extract-local
Apr 4, 2018
Merged

IntroduceLocal on simple names#25856
jcouv merged 2 commits intodotnet:dev15.7.xfrom
jcouv:extract-local

Conversation

@jcouv
Copy link
Copy Markdown
Member

@jcouv jcouv commented Mar 31, 2018

Customer scenario

Allow introducing a local for simple expressions.

Bugs this fixes

Fixes #10123

Risk

Performance impact

Is this a regression from a previous update?

No

@jcouv jcouv added the Area-IDE label Mar 31, 2018
@jcouv jcouv added this to the 15.7 milestone Mar 31, 2018
@jcouv jcouv self-assigned this Mar 31, 2018
@jcouv jcouv requested a review from a team as a code owner March 31, 2018 02:25
@jcouv jcouv added the 4 - In Review A fix for the issue is submitted for review. label Mar 31, 2018
{
void M(int a)
{
System.Console.Write([|a|]);
Copy link
Copy Markdown
Contributor

@CyrusNajmabadi CyrusNajmabadi Mar 31, 2018

Choose a reason for hiding this comment

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

Does thsi mean on every local/parameter/variable, i'll always get an optin to make a local out of it? #Resolved

if (this.Expression is TTypeSyntax)
if (isSpanEmpty && this.Expression is TNameSyntax)
{
// to extract a name, you must have a selection (this avoids making the refactoring too noisy)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ah, nice. that seems like a good thing to do.

return false;
}

if (this.Expression is TTypeSyntax && !(this.Expression is TNameSyntax))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

probably good to comment this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so condition that can hit here is

1, span not empty and expression is not name syntax
2, span is empty but expression is not name syntax
3. span not empty but expression is name syntax

so, if expression is not name syntax, regardless of span, if expression is typesyntax, we don't support refactoring.

shouldn't this check move before isSpanEmpty check?

where TTypeSyntax : TExpressionSyntax
where TTypeDeclarationSyntax : SyntaxNode
where TQueryExpressionSyntax : TExpressionSyntax
where TNameSyntax : SyntaxNode
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note: TNameSyntax should probably derive from TTypeSyntax

@jcouv jcouv removed the 4 - In Review A fix for the issue is submitted for review. label Mar 31, 2018
@jcouv
Copy link
Copy Markdown
Member Author

jcouv commented Apr 3, 2018

@dotnet/roslyn-ide for review for 15.7. Thanks

{
void M(int a)
{
int {|Rename:a1|} = a;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

test that prefer var?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ignore this. I see this use existing introduce var code. which should take care of code style.

}

if (this.Expression is TTypeSyntax)
if (isSpanEmpty && this.Expression is TNameSyntax)
Copy link
Copy Markdown
Contributor

@heejaechang heejaechang Apr 4, 2018

Choose a reason for hiding this comment

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

so, is it okay for the span to intersect with span of the expression? or it must be exactly the span of the expression?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

When the expression is found for a given span, there is a special case for empty span. That's why it needs to be treated specially here.

If you place your cursor on a name, the expression will be found, and it must be rejected (should not introduce variable).
If you select a portion of a name, the expression is not found.
If you select a whole name, the expression is found and it is accepted (can introduce variable).

There are tests to illustrate those scenarios (_EmptySelection, _SmallSelection).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see. it relies on the fact that FindNode will not return expression if selection doesn't include whole expression.

yep, I saw the test. and wondered where that rejection happens.

thank you.

@jcouv
Copy link
Copy Markdown
Member Author

jcouv commented Apr 4, 2018

@jinujoseph for ask-mode approval for 15.7. Or let me know if I should push out to 15.8. Thanks

@jinujoseph
Copy link
Copy Markdown
Contributor

@Pilchie for 15.7.preview4 ask mode approval

@Pilchie
Copy link
Copy Markdown
Member

Pilchie commented Apr 4, 2018

Approved for 15.7 P4.

@jcouv jcouv merged commit 31fa789 into dotnet:dev15.7.x Apr 4, 2018
@jcouv jcouv deleted the extract-local branch April 4, 2018 19:12
@DustinCampbell
Copy link
Copy Markdown
Member

This PR makes me so happy. It's always been a frustration of mine that I can't use Introduce Local in more cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants