Esempio n. 1
0
        private IEnumerable <AnalyzerSetting> GetSettings(AnalyzerReference analyzerReference, AnalyzerConfigOptions editorConfigOptions)
        {
            IEnumerable <DiagnosticAnalyzer> csharpAnalyzers      = analyzerReference.GetAnalyzers(LanguageNames.CSharp);
            IEnumerable <DiagnosticAnalyzer> visualBasicAnalyzers = analyzerReference.GetAnalyzers(LanguageNames.VisualBasic);
            var dotnetAnalyzers = csharpAnalyzers.Intersect(visualBasicAnalyzers, DiagnosticAnalyzerComparer.Instance);

            csharpAnalyzers      = csharpAnalyzers.Except(dotnetAnalyzers, DiagnosticAnalyzerComparer.Instance);
            visualBasicAnalyzers = visualBasicAnalyzers.Except(dotnetAnalyzers, DiagnosticAnalyzerComparer.Instance);

            var csharpSettings = ToAnalyzerSetting(csharpAnalyzers, Language.CSharp);
            var csharpAndVisualBasicSettings = csharpSettings.Concat(ToAnalyzerSetting(visualBasicAnalyzers, Language.VisualBasic));

            return(csharpAndVisualBasicSettings.Concat(ToAnalyzerSetting(dotnetAnalyzers, Language.CSharp | Language.VisualBasic)));

            IEnumerable <AnalyzerSetting> ToAnalyzerSetting(IEnumerable <DiagnosticAnalyzer> analyzers,
                                                            Language language)
            {
                return(analyzers
                       .SelectMany(a => _analyzerService.AnalyzerInfoCache.GetDiagnosticDescriptors(a))
                       .GroupBy(d => d.Id)
                       .OrderBy(g => g.Key, StringComparer.CurrentCulture)
                       .Select(g =>
                {
                    var selectedDiagnostic = g.First();
                    var severity = selectedDiagnostic.GetEffectiveSeverity(editorConfigOptions);
                    return new AnalyzerSetting(selectedDiagnostic, severity, SettingsUpdater, language);
                }));
            }
        }
Esempio n. 2
0
        private BulkObservableCollection <BaseItem> CreateDiagnosticAndGeneratorItems(ProjectId projectId, string language, CompilationOptions options, AnalyzerConfigOptionsResult?analyzerConfigOptions)
        {
            // Within an analyzer assembly, an individual analyzer may report multiple different diagnostics
            // with the same ID. Or, multiple analyzers may report diagnostics with the same ID. Or a
            // combination of the two may occur.
            // We only want to show one node in Solution Explorer for a given ID. So we pick one, but we need
            // to be consistent in which one we pick. Diagnostics with the same ID may have different
            // descriptions or messages, and it would be strange if the node's name changed from one run of
            // VS to another. So we group the diagnostics by ID, sort them within a group, and take the first
            // one.

            Contract.ThrowIfFalse(HasItems);

            var collection = new BulkObservableCollection <BaseItem>();

            collection.AddRange(
                AnalyzerReference.GetAnalyzers(language)
                .SelectMany(a => _diagnosticAnalyzerService.AnalyzerInfoCache.GetDiagnosticDescriptors(a))
                .GroupBy(d => d.Id)
                .OrderBy(g => g.Key, StringComparer.CurrentCulture)
                .Select(g =>
            {
                var selectedDiagnostic = g.OrderBy(d => d, s_comparer).First();
                var effectiveSeverity  = selectedDiagnostic.GetEffectiveSeverity(options, analyzerConfigOptions);
                return(new DiagnosticItem(projectId, AnalyzerReference, selectedDiagnostic, effectiveSeverity, language, CommandHandler));
            }));

            collection.AddRange(
                AnalyzerReference.GetGenerators(language)
                .Select(g => new SourceGeneratorItem(projectId, g, AnalyzerReference)));

            return(collection);
        }
        private IEnumerable <BaseDiagnosticItem> GetDiagnosticItems(string language, CompilationOptions options, ImmutableDictionary <string, ReportDiagnostic> analyzerConfigSpecificDiagnosticOptions)
        {
            // Within an analyzer assembly, an individual analyzer may report multiple different diagnostics
            // with the same ID. Or, multiple analyzers may report diagnostics with the same ID. Or a
            // combination of the two may occur.
            // We only want to show one node in Solution Explorer for a given ID. So we pick one, but we need
            // to be consistent in which one we pick. Diagnostics with the same ID may have different
            // descriptions or messages, and it would be strange if the node's name changed from one run of
            // VS to another. So we group the diagnostics by ID, sort them within a group, and take the first
            // one.

            return(AnalyzerReference.GetAnalyzers(language)
                   .SelectMany(a => _diagnosticAnalyzerService.GetDiagnosticDescriptors(a))
                   .GroupBy(d => d.Id)
                   .OrderBy(g => g.Key, StringComparer.CurrentCulture)
                   .Select(g =>
            {
                var selectedDiagnostic = g.OrderBy(d => d, s_comparer).First();
                var effectiveSeverity = selectedDiagnostic.GetEffectiveSeverity(options, analyzerConfigSpecificDiagnosticOptions);
                return CreateItem(selectedDiagnostic, effectiveSeverity);
            }));
        }