Add support for await using and await foreach in DetectPreviewFeatureAnalyzer #51415
+293
−9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Follow-up work for await using and await foreach preview feature detection
This PR implements follow-up work from #50937 to detect preview features in
await usingandawait foreachconstructs, using the new Roslyn APIs added in dotnet/roslyn#80455.Changes
Core Analyzer Updates:
OperationKind.UsingandOperationKind.Loopto the analyzer's registered operations (building onOperationKind.Awaitfrom Update DetectPreviewFeatureAnalyzer for runtime async #50937)DetectPreviewFeatureAnalyzer:SymbolFromUsingOperation- handles await using declarations and statementsSymbolFromForEachOperation- handles await foreach loopsC# Implementation:
The C# analyzer now detects preview features in:
await using var stream = new MemoryStream()await using (var stream = new MemoryStream()) { }await foreach (var item in GetItemsAsync()) { }VB Implementation:
Lightup Wrappers for Backward Compatibility:
ForEachStatementInfoWrapper- accessesMoveNextAwaitableInfoandDisposeAwaitableInfopropertiesSemanticModelExtensions- extension methods for newGetAwaitExpressionInfooverloadsWhen the new Roslyn APIs (from dotnet/roslyn#80455) are not available, the lightup wrappers gracefully return defaults and no diagnostics are reported. Once the SDK updates to include those APIs, the analyzer will automatically detect preview features in the new constructs.
Tests:
Added comprehensive test cases for all scenarios. Three tests are currently marked as skipped because they require Roslyn APIs that haven't been integrated into the SDK yet:
VerifyRuntimeAsyncAwaitUsingDeclarationReportsDiagnosticVerifyRuntimeAsyncAwaitUsingStatementReportsDiagnosticVerifyRuntimeAsyncAwaitForeachReportsDiagnosticThese tests can be unskipped once the SDK updates to a version of Roslyn that includes dotnet/roslyn#80455.
Relates to test plan dotnet/roslyn#75960
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.