in src/Microsoft.VisualStudio.SDK.Analyzers/VSSDK003SupportAsyncToolWindowAnalyzer.cs [48:70]
public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze);
// Register for compilation first so that we only activate the analyzer for applicable compilations
context.RegisterCompilationStartAction(compilationContext =>
{
INamedTypeSymbol? asyncPackageType = compilationContext.Compilation.GetTypeByMetadataName(Types.AsyncPackage.FullName)?.OriginalDefinition;
if (asyncPackageType is object)
{
INamedTypeSymbol? provideToolWindowAttribute = compilationContext.Compilation.GetTypeByMetadataName(Types.ProvideToolWindowAttribute.FullName)?.OriginalDefinition;
bool targetVSSupportsAsyncToolWindows = asyncPackageType.MemberNames.Any(n => n == Types.AsyncPackage.GetAsyncToolWindowFactory);
if (targetVSSupportsAsyncToolWindows && provideToolWindowAttribute is object)
{
// Reuse the type symbols we looked up so that we don't have to look them up for every single class declaration.
compilationContext.RegisterSyntaxNodeAction(
Utils.DebuggableWrapper(ctxt => this.AnalyzeClassDeclaration(ctxt, asyncPackageType, provideToolWindowAttribute)),
SyntaxKind.ClassDeclaration);
}
}
});
}