protected DiagnosticAnalyzerService(
     DiagnosticAnalyzerInfoCache analyzerInfoCache,
     AbstractHostDiagnosticUpdateSource?hostDiagnosticUpdateSource,
     IDiagnosticUpdateSourceRegistrationService registrationService,
     IAsynchronousOperationListener?listener = null)
     : this(registrationService)
 {
     _analyzerInfoCache          = analyzerInfoCache;
     _hostDiagnosticUpdateSource = hostDiagnosticUpdateSource;
     Listener = listener ?? AsynchronousOperationListenerProvider.NullListener;
 }
Beispiel #2
0
 internal static void OnAnalyzerException_NoTelemetryLogging(
     DiagnosticAnalyzer analyzer,
     Diagnostic?diagnostic,
     AbstractHostDiagnosticUpdateSource?hostDiagnosticUpdateSource,
     ProjectId?projectId)
 {
     if (diagnostic != null)
     {
         hostDiagnosticUpdateSource?.ReportAnalyzerDiagnostic(analyzer, diagnostic, hostDiagnosticUpdateSource?.Workspace, projectId);
     }
 }
 protected DiagnosticAnalyzerService(
     Lazy <ImmutableArray <HostDiagnosticAnalyzerPackage> > workspaceAnalyzerPackages,
     IAnalyzerAssemblyLoader?hostAnalyzerAssemblyLoader,
     AbstractHostDiagnosticUpdateSource?hostDiagnosticUpdateSource,
     PrimaryWorkspace primaryWorkspace,
     IDiagnosticUpdateSourceRegistrationService registrationService,
     IAsynchronousOperationListener?listener = null)
     : this(new DiagnosticAnalyzerInfoCache(workspaceAnalyzerPackages, hostAnalyzerAssemblyLoader, hostDiagnosticUpdateSource, primaryWorkspace),
            hostDiagnosticUpdateSource,
            registrationService,
            listener)
 {
 }
Beispiel #4
0
 public DiagnosticAnalyzerService(
     IDiagnosticUpdateSourceRegistrationService registrationService,
     IAsynchronousOperationListenerProvider listenerProvider,
     PrimaryWorkspace primaryWorkspace,
     [Import(AllowDefault = true)] IHostDiagnosticAnalyzerPackageProvider?diagnosticAnalyzerProviderService = null,
     [Import(AllowDefault = true)] AbstractHostDiagnosticUpdateSource?hostDiagnosticUpdateSource            = null)
     : this(new Lazy <ImmutableArray <HostDiagnosticAnalyzerPackage> >(() => GetHostDiagnosticAnalyzerPackage(diagnosticAnalyzerProviderService), isThreadSafe : true),
            diagnosticAnalyzerProviderService?.GetAnalyzerAssemblyLoader(),
            hostDiagnosticUpdateSource,
            primaryWorkspace,
            registrationService, listenerProvider.GetListener(FeatureAttribute.DiagnosticService))
 {
     // diagnosticAnalyzerProviderService and hostDiagnosticUpdateSource can only be null in test harness. Otherwise, it should never be null.
 }
        private DiagnosticAnalyzerInfoCache(
            Lazy <ImmutableArray <AnalyzerReference> > hostAnalyzerReferences, Lazy <ImmutableArray <HostDiagnosticAnalyzerPackage> > hostAnalyzerPackages, AbstractHostDiagnosticUpdateSource?hostDiagnosticUpdateSource)
        {
            _hostDiagnosticAnalyzerPackages = hostAnalyzerPackages;
            _hostDiagnosticUpdateSource     = hostDiagnosticUpdateSource;

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

            _compilerDiagnosticAnalyzerMap           = ImmutableDictionary <string, DiagnosticAnalyzer> .Empty;
            _compilerDiagnosticAnalyzerDescriptorMap = ImmutableDictionary <DiagnosticAnalyzer, HashSet <string> > .Empty;
            _hostDiagnosticAnalyzerPackageNameMap    = ImmutableDictionary <DiagnosticAnalyzer, string> .Empty;
            _descriptorCache = new ConditionalWeakTable <DiagnosticAnalyzer, IReadOnlyCollection <DiagnosticDescriptor> >();
        }
        protected DiagnosticAnalyzerService(
            DiagnosticAnalyzerInfoCache analyzerInfoCache,
            HostDiagnosticAnalyzers hostAnalyzers,
            AbstractHostDiagnosticUpdateSource?hostDiagnosticUpdateSource,
            IDiagnosticUpdateSourceRegistrationService registrationService,
            IAsynchronousOperationListener?listener = null)
        {
            AnalyzerInfoCache           = analyzerInfoCache;
            HostAnalyzers               = hostAnalyzers;
            _hostDiagnosticUpdateSource = hostDiagnosticUpdateSource;

            _map = new ConditionalWeakTable <Workspace, DiagnosticIncrementalAnalyzer>();
            _createIncrementalAnalyzer = CreateIncrementalAnalyzerCallback;

            Listener  = listener ?? AsynchronousOperationListenerProvider.NullListener;
            _eventMap = new EventMap();

            // use diagnostic event task scheduler so that we never flood async events queue with million of events.
            // queue itself can handle huge number of events but we are seeing OOM due to captured data in pending events.
            _eventQueue = new TaskQueue(Listener, s_eventScheduler);

            registrationService.Register(this);
        }
 public DiagnosticAnalyzerInfoCache(Lazy <ImmutableArray <HostDiagnosticAnalyzerPackage> > hostAnalyzerPackages, IAnalyzerAssemblyLoader?hostAnalyzerAssemblyLoader, AbstractHostDiagnosticUpdateSource?hostDiagnosticUpdateSource, PrimaryWorkspace primaryWorkspace)
     : this(new Lazy <ImmutableArray <AnalyzerReference> >(() => CreateAnalyzerReferencesFromPackages(hostAnalyzerPackages.Value, new HostAnalyzerReferenceDiagnosticReporter(hostDiagnosticUpdateSource, primaryWorkspace), hostAnalyzerAssemblyLoader), isThreadSafe : true),
            hostAnalyzerPackages, hostDiagnosticUpdateSource)
 {
 }
 public HostAnalyzerReferenceDiagnosticReporter(AbstractHostDiagnosticUpdateSource?hostUpdateSource, PrimaryWorkspace primaryWorkspace)
 {
     _hostUpdateSource = hostUpdateSource;
     _primaryWorkspace = primaryWorkspace;
 }
Beispiel #9
0
        internal static void OnAnalyzerExceptionForSupportedDiagnostics(DiagnosticAnalyzer analyzer, Exception exception, AbstractHostDiagnosticUpdateSource?hostDiagnosticUpdateSource)
        {
            if (exception is OperationCanceledException)
            {
                return;
            }

            var diagnostic = CreateAnalyzerExceptionDiagnostic(analyzer, exception);

            OnAnalyzerException_NoTelemetryLogging(analyzer, diagnostic, hostDiagnosticUpdateSource, projectId: null);
        }