Skip to content

Commit

Permalink
Merge pull request #1566 from kurobon-jp/feature/AnalyzerTimeout
Browse files Browse the repository at this point in the history
Fixed analyzer timeout issue.
  • Loading branch information
filipw authored Jul 23, 2019
2 parents c88a425 + 227b1fb commit e869b97
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
Expand Down Expand Up @@ -235,12 +235,16 @@ private async Task AnalyzeDocument(Project project, ImmutableArray<DiagnosticAna
}
else if (allAnalyzers.Any()) // Analyzers cannot be called with empty analyzer list.
{
var semanticDiagnosticsWithAnalyzers = await compiled
.WithAnalyzers(allAnalyzers, workspaceAnalyzerOptions)
var compilationWithAnalyzers = compiled.WithAnalyzers(allAnalyzers, new CompilationWithAnalyzersOptions(workspaceAnalyzerOptions,
onAnalyzerException: OnAnalyzerException,
concurrentAnalysis: false,
logAnalyzerExecutionTime: false,
reportSuppressedDiagnostics: false));

var semanticDiagnosticsWithAnalyzers = await compilationWithAnalyzers
.GetAnalyzerSemanticDiagnosticsAsync(documentSemanticModel, filterSpan: null, perDocumentTimeout.Token);

var syntaxDiagnosticsWithAnalyzers = await compiled
.WithAnalyzers(allAnalyzers, workspaceAnalyzerOptions)
var syntaxDiagnosticsWithAnalyzers = await compilationWithAnalyzers
.GetAnalyzerSyntaxDiagnosticsAsync(documentSemanticModel.SyntaxTree, perDocumentTimeout.Token);

diagnostics = semanticDiagnosticsWithAnalyzers
Expand All @@ -261,6 +265,14 @@ private async Task AnalyzeDocument(Project project, ImmutableArray<DiagnosticAna
}
}

private void OnAnalyzerException(Exception ex, DiagnosticAnalyzer analyzer, Diagnostic diagnostic)
{
_logger.LogDebug($"Exception in diagnostic analyzer." +
$"\n analyzer: {analyzer}" +
$"\n diagnostic: {diagnostic}" +
$"\n exception: {ex.Message}");
}

private void UpdateCurrentDiagnostics(Project project, Document document, ImmutableArray<Diagnostic> diagnosticsWithAnalyzers)
{
_currentDiagnosticResults[document.Id] = (project.Name, diagnosticsWithAnalyzers);
Expand Down

0 comments on commit e869b97

Please sign in to comment.