private bool CatchAnalyzerException(Exception e, DiagnosticAnalyzer analyzer, bool testOnly_DonotCatchAnalyzerExceptions) { DiagnosticAnalyzerLogger.LogAnalyzerCrashCount(analyzer, e, _logAggregator); if (testOnly_DonotCatchAnalyzerExceptions) { return(false); } if (AnalyzerHelper.IsBuiltInAnalyzer(analyzer)) { return(FatalError.ReportWithoutCrashUnlessCanceled(e)); } return(true); }
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); }
private bool CatchAnalyzerException(Exception e, DiagnosticAnalyzer analyzer, bool testOnly_DonotCatchAnalyzerExceptions) { DiagnosticAnalyzerLogger.LogAnalyzerCrashCount(analyzer, e, this.logAggregator); if (testOnly_DonotCatchAnalyzerExceptions) { return(false); } // TODO: move it to AnalyzerHelper later. if (!DiagnosticAnalyzerService.ShouldHandleAnalyzer(analyzer) || IsCompilerAnalyzer(analyzer)) { return(FatalError.ReportWithoutCrashUnlessCanceled(e)); } return(true); }
private async Task GetCompilationDiagnosticsAsync(DiagnosticAnalyzer analyzer, List <Diagnostic> diagnostics, Action <Project, DiagnosticAnalyzer, CancellationToken> forceAnalyzeAllDocuments) { Contract.ThrowIfFalse(this.project.SupportsCompilation); var analyzerActionsAndDiagnostics = GetSessionAnalyzerActionsAndDiagnostics(analyzer); var analyzerActions = analyzerActionsAndDiagnostics.Item1; var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false); diagnostics.AddRange(CompilationWithAnalyzers.GetEffectiveDiagnostics(analyzerActionsAndDiagnostics.Item2, compilation)); DiagnosticAnalyzerLogger.UpdateAnalyzerTypeCount(analyzer, analyzerActions, (DiagnosticLogAggregator)logAggregator); if (analyzerActions == null || (analyzerActions.CompilationStartActionsCount == 0 && analyzerActions.CompilationEndActionsCount == 0)) { return; } using (var pooledObject = SharedPools.Default <List <Diagnostic> >().GetPooledObject()) { var localDiagnostics = pooledObject.Object; // Get all the analyzer actions, including the per-compilation actions. var allAnalyzerActions = await GetAnalyzerActionsAsync(analyzer, localDiagnostics.Add).ConfigureAwait(false); if (analyzerActions.CompilationEndActionsCount < allAnalyzerActions.CompilationEndActionsCount && forceAnalyzeAllDocuments != null) { if (allAnalyzerActions.CodeBlockEndActionsCount > analyzerActions.CodeBlockEndActionsCount || allAnalyzerActions.CodeBlockStartActionsCount > analyzerActions.CodeBlockStartActionsCount || allAnalyzerActions.SemanticModelActionsCount > analyzerActions.SemanticModelActionsCount || allAnalyzerActions.SymbolActionsCount > analyzerActions.SymbolActionsCount || allAnalyzerActions.SyntaxNodeActionsCount > analyzerActions.SyntaxNodeActionsCount || allAnalyzerActions.SyntaxTreeActionsCount > analyzerActions.SyntaxTreeActionsCount) { // Analyzer registered a compilation end action and at least one other analyzer action during it's compilation start action. // We need to ensure that we have force analyzed all documents in this project for this analyzer before executing the end actions. forceAnalyzeAllDocuments(project, analyzer, cancellationToken); } } // CompilationEnd actions. AnalyzerDriverHelper.ExecuteCompilationEndActions(allAnalyzerActions, compilation, analyzerOptions, localDiagnostics.Add, CatchAnalyzerException, cancellationToken); diagnostics.AddRange(CompilationWithAnalyzers.GetEffectiveDiagnostics(localDiagnostics, compilation)); } }
public async Task <AnalyzerActions> GetAnalyzerActionsAsync(DiagnosticAnalyzer analyzer, Action <Diagnostic> addDiagnostic) { var analyzerActions = GetSessionAnalyzerActions(analyzer); DiagnosticAnalyzerLogger.UpdateAnalyzerTypeCount(analyzer, analyzerActions, (DiagnosticLogAggregator)logAggregator); if (analyzerActions != null) { if (this.project.SupportsCompilation && analyzerActions.CompilationStartActionsCount > 0) { var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false); var analyzerCompilationActions = GetPerCompilationAnalyzerActions(analyzer, analyzerActions, compilation, addDiagnostic); if (analyzerCompilationActions != null) { analyzerActions = analyzerActions.Append(analyzerCompilationActions); DiagnosticAnalyzerLogger.UpdateAnalyzerTypeCount(analyzer, analyzerActions, (DiagnosticLogAggregator)logAggregator); } } } return(analyzerActions); }
// 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); }