-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Update DetectPreviewFeatureAnalyzer for runtime async #50937
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,15 +3,29 @@ | |
| using System.Collections.Immutable; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using Microsoft.CodeAnalysis; | ||
| using Microsoft.CodeAnalysis.CSharp; | ||
| using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
| using Microsoft.CodeAnalysis.Diagnostics; | ||
| using Microsoft.CodeAnalysis.Operations; | ||
| using Microsoft.NetCore.Analyzers.Runtime; | ||
| using Analyzer.Utilities.Lightup; | ||
|
|
||
| namespace Microsoft.NetCore.CSharp.Analyzers.Runtime | ||
| { | ||
| [DiagnosticAnalyzer(LanguageNames.CSharp)] | ||
| public class CSharpDetectPreviewFeatureAnalyzer : DetectPreviewFeatureAnalyzer | ||
| { | ||
| protected override ISymbol? SymbolFromAwaitOperation(IAwaitOperation operation) | ||
| { | ||
| if (operation.Syntax is not AwaitExpressionSyntax awaitSyntax) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider testing with
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are going to need new public APIs. I'll open a followup.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| { | ||
| return null; | ||
| } | ||
|
|
||
| var awaitableInfo = operation.SemanticModel.GetAwaitExpressionInfo(awaitSyntax); | ||
| return awaitableInfo.RuntimeAwaitMethod; | ||
| } | ||
|
|
||
| protected override SyntaxNode? GetPreviewSyntaxNodeForFieldsOrEvents(ISymbol fieldOrEventSymbol, ISymbol previewSymbol) | ||
| { | ||
| ImmutableArray<SyntaxReference> fieldOrEventReferences = fieldOrEventSymbol.DeclaringSyntaxReferences; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
|
||
| using Microsoft.CodeAnalysis; | ||
| using Microsoft.CodeAnalysis.CSharp; | ||
|
|
||
| namespace Analyzer.Utilities.Lightup | ||
| { | ||
| internal static class AwaitExpressionInfoWrapper | ||
| { | ||
| private static Func<AwaitExpressionInfo, IMethodSymbol?>? s_RuntimeAwaitMethodAccessor; | ||
|
|
||
| extension(AwaitExpressionInfo info) | ||
| { | ||
| public IMethodSymbol? RuntimeAwaitMethod | ||
| { | ||
| get | ||
| { | ||
| LazyInitializer.EnsureInitialized(ref s_RuntimeAwaitMethodAccessor, () => | ||
333fred marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| return LightupHelpers.CreatePropertyAccessor<AwaitExpressionInfo, IMethodSymbol?>( | ||
| typeof(AwaitExpressionInfo), | ||
| "info", | ||
| "RuntimeAwaitMethod", | ||
| fallbackResult: null); | ||
| }); | ||
|
|
||
| return s_RuntimeAwaitMethodAccessor!(info); | ||
|
||
| } | ||
| } | ||
333fred marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
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.
sort usings?