private Task ProcessCompilationUnitCompleted(CompilationUnitCompletedEvent completedEvent, CancellationToken cancellationToken) { // When the compiler is finished with a compilation unit, we can run user diagnostics which // might want to ask the compiler for all the diagnostics in the source file, for example // to get information about unnecessary usings. try { // Execute analyzers in parallel. var tasks = ArrayBuilder <Task> .GetInstance(); var semanticModel = completedEvent.SemanticModel; foreach (var analyzerAndActions in _semanticModelActionsMap) { var task = Task.Run(() => { // Execute actions for a given analyzer sequentially. analyzerExecutor.ExecuteSemanticModelActions(analyzerAndActions.Value, semanticModel); }, cancellationToken); tasks.Add(task); } return(Task.WhenAll(tasks.ToArrayAndFree())); } finally { completedEvent.FlushCache(); } }
private Task ProcessCompilationUnitCompleted(CompilationUnitCompletedEvent completedEvent, CancellationToken cancellationToken) { // When the compiler is finished with a compilation unit, we can run user diagnostics which // might want to ask the compiler for all the diagnostics in the source file, for example // to get information about unnecessary usings. try { var tasks = ArrayBuilder <Task> .GetInstance(); var semanticModel = completedEvent.SemanticModel; foreach (var da in semanticModelAnalyzers) { // TODO: is the overhead of creating tasks here too high compared to the cost of running them sequentially? tasks.Add(Task.Run(() => { // Catch Exception from da.AnalyzeSemanticModel ExecuteAndCatchIfThrows(da, addDiagnostic, continueOnError, cancellationToken, () => { cancellationToken.ThrowIfCancellationRequested(); da.AnalyzeSemanticModel(semanticModel, addDiagnostic, this.analyzerOptions, cancellationToken); }); })); } return(Task.WhenAll(tasks.ToImmutableAndFree())); } finally { completedEvent.FlushCache(); } }
private void ProcessCompilationUnitCompleted(CompilationUnitCompletedEvent completedEvent, AnalysisScope analysisScope, AnalysisState analysisStateOpt, CancellationToken cancellationToken) { // When the compiler is finished with a compilation unit, we can run user diagnostics which // might want to ask the compiler for all the diagnostics in the source file, for example // to get information about unnecessary usings. var semanticModel = analysisStateOpt != null ? GetOrCreateCachedSemanticModel(completedEvent.CompilationUnit, completedEvent.Compilation, cancellationToken) : completedEvent.SemanticModel; if (!analysisScope.ShouldAnalyze(semanticModel.SyntaxTree)) { return; } try { foreach (var analyzer in analysisScope.Analyzers) { ImmutableArray<SemanticModelAnalyzerAction> semanticModelActions; if (_semanticModelActionsMap.TryGetValue(analyzer, out semanticModelActions)) { // Execute actions for a given analyzer sequentially. analyzerExecutor.ExecuteSemanticModelActions(semanticModelActions, analyzer, semanticModel, completedEvent, analysisScope, analysisStateOpt); } else { analysisStateOpt?.MarkEventComplete(completedEvent, analyzer); } } } finally { completedEvent.FlushCache(); } }
private Task ProcessCompilationUnitCompleted(CompilationUnitCompletedEvent completedEvent, CancellationToken cancellationToken) { // When the compiler is finished with a compilation unit, we can run user diagnostics which // might want to ask the compiler for all the diagnostics in the source file, for example // to get information about unnecessary usings. try { var tasks = ArrayBuilder<Task>.GetInstance(); var semanticModel = completedEvent.SemanticModel; foreach (var da in semanticModelAnalyzers) { // TODO: is the overhead of creating tasks here too high compared to the cost of running them sequentially? tasks.Add(Task.Run(() => { // Catch Exception from da.AnalyzeSemanticModel ExecuteAndCatchIfThrows(da, addDiagnostic, continueOnAnalyzerException, cancellationToken, () => { cancellationToken.ThrowIfCancellationRequested(); da.AnalyzeSemanticModel(semanticModel, addDiagnostic, this.analyzerOptions, cancellationToken); }); })); } return Task.WhenAll(tasks.ToImmutableAndFree()); } finally { completedEvent.FlushCache(); } }
private async Task ProcessCompilationUnitCompletedAsync(CompilationUnitCompletedEvent completedEvent, CancellationToken cancellationToken) { // When the compiler is finished with a compilation unit, we can run user diagnostics which // might want to ask the compiler for all the diagnostics in the source file, for example // to get information about unnecessary usings. try { // Execute analyzers in parallel. var tasks = ArrayBuilder<Task>.GetInstance(); var semanticModel = completedEvent.SemanticModel; foreach (var analyzerAndActions in _semanticModelActionsMap) { var task = Task.Run(() => { // Execute actions for a given analyzer sequentially. analyzerExecutor.ExecuteSemanticModelActions(analyzerAndActions.Value, semanticModel); }, cancellationToken); tasks.Add(task); } await Task.WhenAll(tasks.ToArrayAndFree()).ConfigureAwait(false); } finally { completedEvent.FlushCache(); } }
private Task ProcessCompilationUnitCompleted(CompilationUnitCompletedEvent completedEvent, CancellationToken cancellationToken) { // When the compiler is finished with a compilation unit, we can run user diagnostics which // might want to ask the compiler for all the diagnostics in the source file, for example // to get information about unnecessary usings. try { // Execute analyzers in parallel. var tasks = ArrayBuilder<Task>.GetInstance(); var semanticModel = completedEvent.SemanticModel; foreach (var analyzerAndActions in _semanticModelActionsMap) { var task = Task.Run(() => { // Execute actions for a given analyzer sequentially. foreach (var semanticModelAction in analyzerAndActions.Value) { Debug.Assert(semanticModelAction.Analyzer == analyzerAndActions.Key); // Catch Exception from semanticModelAction AnalyzerDriverHelper.ExecuteAndCatchIfThrows(semanticModelAction.Analyzer, _addDiagnostic, continueOnAnalyzerException, () => { cancellationToken.ThrowIfCancellationRequested(); var semanticModelContext = new SemanticModelAnalysisContext(semanticModel, this.analyzerOptions, _addDiagnostic, cancellationToken); semanticModelAction.Action(semanticModelContext); }, cancellationToken); } }, cancellationToken); tasks.Add(task); } return Task.WhenAll(tasks.ToArrayAndFree()); } finally { completedEvent.FlushCache(); } }