Exemplo n.º 1
0
        private static ImmutableArray <AnalyzerReference> CreateAnalyzerReferencesFromPackages(
            ImmutableArray <HostDiagnosticAnalyzerPackage> analyzerPackages,
            HostAnalyzerReferenceDiagnosticReporter reporter,
            IAnalyzerAssemblyLoader hostAnalyzerAssemblyLoader)
        {
            if (analyzerPackages.IsEmpty)
            {
                return(ImmutableArray <AnalyzerReference> .Empty);
            }

            Contract.ThrowIfNull(hostAnalyzerAssemblyLoader);

            var analyzerAssemblies = analyzerPackages.SelectMany(p => p.Assemblies);

            var builder = ImmutableArray.CreateBuilder <AnalyzerReference>();

            foreach (var analyzerAssembly in analyzerAssemblies.Distinct(StringComparer.OrdinalIgnoreCase))
            {
                var reference = new AnalyzerFileReference(analyzerAssembly, hostAnalyzerAssemblyLoader);
                reference.AnalyzerLoadFailed += reporter.OnAnalyzerLoadFailed;

                builder.Add(reference);
            }

            var references = builder.ToImmutable();

            DiagnosticAnalyzerLogger.LogWorkspaceAnalyzers(references);

            return(references);
        }
Exemplo n.º 2
0
        public WorkspaceAnalyzerManager(ImmutableArray <AnalyzerReference> hostAnalyzerReferences, AbstractHostDiagnosticUpdateSource hostDiagnosticUpdateSource)
        {
            _hostAnalyzerReferencesMap                  = hostAnalyzerReferences.IsDefault ? ImmutableDictionary <string, AnalyzerReference> .Empty : CreateAnalyzerReferencesMap(hostAnalyzerReferences);
            _hostDiagnosticAnalyzersPerLanguageMap      = new ConcurrentDictionary <string, ImmutableDictionary <string, ImmutableArray <DiagnosticAnalyzer> > >(concurrencyLevel: 2, capacity: 2);
            _lazyHostDiagnosticAnalyzersPerReferenceMap = new Lazy <ImmutableDictionary <string, ImmutableArray <DiagnosticAnalyzer> > >(() => CreateDiagnosticAnalyzersPerReferenceMap(_hostAnalyzerReferencesMap), isThreadSafe: true);
            _hostDiagnosticUpdateSource                 = hostDiagnosticUpdateSource;

            DiagnosticAnalyzerLogger.LogWorkspaceAnalyzers(hostAnalyzerReferences);
        }
Exemplo n.º 3
0
        public AnalyzerManager(ImmutableArray <AnalyzerReference> hostAnalyzerReferences)
        {
            _hostAnalyzerReferencesMap = hostAnalyzerReferences.IsDefault ? ImmutableDictionary <string, AnalyzerReference> .Empty : CreateAnalyzerReferencesMap(hostAnalyzerReferences);
            _hostDiagnosticAnalyzersPerReferenceMap = CreateDiagnosticAnalyzersPerReferenceMap(_hostAnalyzerReferencesMap);

            _hostDiagnosticAnalyzersPerLanguageMap = new ConcurrentDictionary <string, ImmutableDictionary <string, ImmutableArray <DiagnosticAnalyzer> > >(concurrencyLevel: 2, capacity: 2);
            _descriptorCache = new ConditionalWeakTable <DiagnosticAnalyzer, IReadOnlyList <DiagnosticDescriptor> >();

            DiagnosticAnalyzerLogger.LogWorkspaceAnalyzers(hostAnalyzerReferences);
        }
Exemplo n.º 4
0
        private HostAnalyzerManager(
            ImmutableArray <AnalyzerReference> hostAnalyzerReferences, ImmutableArray <HostDiagnosticAnalyzerPackage> hostAnalyzerPackages, AbstractHostDiagnosticUpdateSource hostDiagnosticUpdateSource)
        {
            _hostDiagnosticAnalyzerPackages = hostAnalyzerPackages;
            _hostDiagnosticUpdateSource     = hostDiagnosticUpdateSource;

            _hostAnalyzerReferencesMap                  = hostAnalyzerReferences.IsDefault ? ImmutableDictionary <string, AnalyzerReference> .Empty : CreateAnalyzerReferencesMap(hostAnalyzerReferences);
            _hostDiagnosticAnalyzersPerLanguageMap      = new ConcurrentDictionary <string, ImmutableDictionary <string, ImmutableArray <DiagnosticAnalyzer> > >(concurrencyLevel: 2, capacity: 2);
            _lazyHostDiagnosticAnalyzersPerReferenceMap = new Lazy <ImmutableDictionary <string, ImmutableArray <DiagnosticAnalyzer> > >(() => CreateDiagnosticAnalyzersPerReferenceMap(_hostAnalyzerReferencesMap), isThreadSafe: true);

            _compilerDiagnosticAnalyzerMap           = ImmutableDictionary <string, DiagnosticAnalyzer> .Empty;
            _compilerDiagnosticAnalyzerDescriptorMap = ImmutableDictionary <DiagnosticAnalyzer, HashSet <string> > .Empty;
            _hostDiagnosticAnalzyerPackageNameMap    = ImmutableDictionary <DiagnosticAnalyzer, string> .Empty;

            DiagnosticAnalyzerLogger.LogWorkspaceAnalyzers(hostAnalyzerReferences);
        }
Exemplo n.º 5
0
 // internal for testing purposes.
 internal DiagnosticAnalyzerService(ImmutableArray <AnalyzerReference> workspaceAnalyzers) : this()
 {
     this.diagnosticMap      = new Dictionary <DiagnosticAnalyzer, ImmutableArray <DiagnosticDescriptor> >();
     this.workspaceAnalyzers = workspaceAnalyzers.IsDefault ? ImmutableArray <AnalyzerReference> .Empty : workspaceAnalyzers;
     DiagnosticAnalyzerLogger.LogWorkspaceAnalyzers(this.workspaceAnalyzers);
 }