dotnet/roslyn

await code fix / analyzer enhancement

Open

#60,318 opened on Mar 22, 2022

View on GitHub
 (1 comment) (4 reactions) (0 assignees)C# (4,257 forks)batch import
Area-AnalyzersConcept-Continuous Improvementhelp wanted

Repository metrics

Stars
 (20,414 stars)
PR merge metrics
 (Avg merge 6d 17h) (256 merged PRs in 30d)

Description

Discussed in https://github.com/dotnet/roslyn/discussions/60285

Originally posted by TonyValenti March 20, 2022 Today, if you have a method like this:

public Task FooAsync() {

  return Task.Completed;
}

and you type "await " in the body of the method, the signature of the method automatically changes to include "async" so that it reads as so:

public async Task FooAsync() { // Notice that async was added.

  await //this is where I was typing

  return Task.CompletedTask;
}

This is great but it would be even better if a few other changes would happen:

  1. Change any "return Task.CompletedTask" to just "Return" (or, perhaps, omit it completely depending on location)
  2. Change any "Task.FromResult(x)" to just x

Contributor guide