Skip to content

Fix await completion for expression body lambda#58042

Merged
genlu merged 1 commit intodotnet:mainfrom
genlu:AwaitCompletionFix
Dec 2, 2021
Merged

Fix await completion for expression body lambda#58042
genlu merged 1 commit intodotnet:mainfrom
genlu:AwaitCompletionFix

Conversation

@genlu
Copy link
Copy Markdown
Member

@genlu genlu commented Nov 30, 2021

Fix https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1442700

From the feedback:

Start with this code:

void Foo()
{
    Task.Run(async () => $$
}

Then type await in the Task.Run lambda (include the space after await).

Expected:

No change to Foo’s signature.

Actual:

Now it’s been updated to

async void Foo()

This behavior is generating errors (adding async where it shouldn’t be) and doing so arbitrarily far from my current cursor, and it’s really distracting to have to track these down and delete.

@genlu genlu requested a review from a team as a code owner November 30, 2021 23:38
@ghost ghost added the Area-IDE label Nov 30, 2021
@genlu genlu enabled auto-merge December 1, 2021 00:15
}

return parent.Ancestors().FirstOrDefault(node => node.IsAsyncSupportingFunctionSyntax());
return parent.AncestorsAndSelf().FirstOrDefault(node => node.IsAsyncSupportingFunctionSyntax());
Copy link
Copy Markdown
Member

@Youssef1313 Youssef1313 Dec 1, 2021

Choose a reason for hiding this comment

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

VB should be having the same bug.

Protected Overrides Function GetAsyncSupportingDeclaration(token As SyntaxToken) As SyntaxNode
Return token.GetAncestor(Function(node) node.IsAsyncSupportedFunctionSyntax())
End Function

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.

I think this is not an issue in VB. Unlike C#, SingleLineFunctionLambdaExpression is not parent of any token. Here's a few tests I believe covered this scenario.

Public Async Function AwaitCompletionAddsAsync_SingleLineFunctionLambdaExpression() As Task

@genlu genlu merged commit 8b71240 into dotnet:main Dec 2, 2021
@ghost ghost added this to the Next milestone Dec 2, 2021
@genlu genlu deleted the AwaitCompletionFix branch December 2, 2021 18:33
@vatsalyaagrawal vatsalyaagrawal modified the milestones: Next, 17.1.P3 Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants