/// <summary> /// Generate a json file that has the implementation status of the passed in analyzer references. /// </summary> private static void GenerateStatus(IEnumerable<AnalyzerFileReference> analyzerReferences) { DescriptorEqualityComparer comparer = new DescriptorEqualityComparer(); var allAnalyzers = analyzerReferences .Select(analyzerReference => new { AnalyzerPackage = analyzerReference.Display, Analyzers = analyzerReference.GetAnalyzersForAllLanguages() }); var fixableDiagnosticIds = analyzerReferences .SelectMany(analyzerReference => analyzerReference.GetFixers()) .SelectMany(fixer => fixer.FixableDiagnosticIds) .Distinct(); Dictionary<string, AnalyzersStatusInfo> diagnosticInfoMap = new Dictionary<string, AnalyzersStatusInfo>(); foreach (var group in allAnalyzers) { foreach (var analyzer in group.Analyzers) { bool hasImplementation = HasImplementation(analyzer); bool hasCSharpImplementation = hasImplementation && analyzer.GetType().GetCustomAttribute<DiagnosticAnalyzerAttribute>().Languages.Contains(LanguageNames.CSharp); bool hasVBImplementation = hasImplementation && analyzer.GetType().GetCustomAttribute<DiagnosticAnalyzerAttribute>().Languages.Contains(LanguageNames.VisualBasic); foreach (var descriptor in analyzer.SupportedDiagnostics.Distinct(comparer)) { if (!diagnosticInfoMap.ContainsKey(descriptor.Id)) { var hasCodeFix = fixableDiagnosticIds.Contains(descriptor.Id); // This assumes a convention similar to A.B.Analyzers and A.B.CSharp.Analyzers and A.B.VisualBasic.Analyzers // Some common dlls might have a common prefix as well. var analyzerPackage = group.AnalyzerPackage.Replace(".CSharp", string.Empty).Replace(".VisualBasic", string.Empty).Replace(".Common", string.Empty); var diagnosticInfo = new AnalyzersStatusInfo { Id = descriptor.Id, Category = descriptor.Category, HasCSharpImplementation = hasCSharpImplementation, HasVBImplementation = hasVBImplementation, Name = analyzer.GetType().Name, Title = descriptor.Title.ToString(), HelpLink = descriptor.HelpLinkUri, HasCodeFix = hasCodeFix, IsEnabledByDefault = descriptor.IsEnabledByDefault.ToString(), AnalyzerPackage = analyzerPackage }; diagnosticInfoMap.Add(descriptor.Id, diagnosticInfo); } else { // Update the state of the existing info. var diagnosticInfo = diagnosticInfoMap[descriptor.Id]; diagnosticInfo.HasCSharpImplementation |= hasCSharpImplementation; diagnosticInfo.HasVBImplementation |= hasVBImplementation; } } } } Console.WriteLine(JsonConvert.SerializeObject(new { Diagnostics = diagnosticInfoMap.Values})); }
public static void Main(string[] args) { Loader loader = new Loader(); DescriptorEqualityComparer comparer = new DescriptorEqualityComparer(); string outputMarkdown = args .Select(arg => new AnalyzerFileReference(arg, loader)) .SelectMany(analyzerReference => analyzerReference.GetAnalyzersForAllLanguages()) .Where(HasImplementation) .SelectMany(analyzer => analyzer.SupportedDiagnostics) .Distinct(comparer) .OrderBy(descriptor => descriptor.Id) .Select(GenerateDescriptorText) .Join(Environment.NewLine + Environment.NewLine); Console.Write(outputMarkdown); }