public void AddDocument(AdditionalDocument additionalDocument) { currentReport.AddAdditionalDocument(additionalDocument); }
private async Task <ImmutableArray <Diagnostic> > GetAdditionalDocumentDiagnosticsAsync(AdditionalDocument document, DiagnosticAnalyzer analyzer, bool isCompilerAnalyzer, CancellationToken cancellationToken) { // PERF: Compute diagnostics for all analyzers with a single invocation into CompilationWithAnalyzers. // This is critical for better analyzer execution performance. RoslynDebug.Assert(_compilationWithAnalyzers != null); RoslynDebug.Assert(_compilationBasedAnalyzersInAnalysisScope.Contains(analyzer)); if (isCompilerAnalyzer) { return(ImmutableArray <Diagnostic> .Empty); } if (_lazyAdditionalDocumentDiagnostics == null) { var filePath = document.FilePath ?? document.Name; var additionalFile = _compilationWithAnalyzers.AnalysisOptions.Options?.AdditionalFiles.FirstOrDefault(a => PathUtilities.Comparer.Equals(a.Path, filePath)); ImmutableDictionary <DiagnosticAnalyzer, ImmutableArray <Diagnostic> > diagnosticsMap; if (additionalFile == null) { diagnosticsMap = ImmutableDictionary <DiagnosticAnalyzer, ImmutableArray <Diagnostic> > .Empty; } else { // TODO: Move this invocation to OOP var analysisResult = await _compilationWithAnalyzers.GetAnalysisResultAsync(additionalFile, _compilationBasedAnalyzersInAnalysisScope, cancellationToken).ConfigureAwait(false); diagnosticsMap = analysisResult.AdditionalFileDiagnostics.TryGetValue(additionalFile, out var value) ? value : ImmutableDictionary <DiagnosticAnalyzer, ImmutableArray <Diagnostic> > .Empty; } Interlocked.CompareExchange(ref _lazyAdditionalDocumentDiagnostics, diagnosticsMap, null); } return(_lazyAdditionalDocumentDiagnostics.TryGetValue(analyzer, out var diagnostics) ? diagnostics : ImmutableArray <Diagnostic> .Empty); }