private async Task <bool> TryGetProjectDiagnosticsAsync( StateSet stateSet, DiagnosticsGetterAsync diagnosticGetterAsync, List <DiagnosticData> list, CancellationToken cancellationToken) { if (!stateSet.Analyzer.SupportsProjectDiagnosticAnalysis()) { return(true); } // make sure we get state even when none of our analyzer has ran yet. // but this shouldn't create analyzer that doesn't belong to this project (language) var state = stateSet.GetProjectState(_document.Project.Id); // see whether we can use existing info var result = await state.GetAnalysisDataAsync(_document, avoidLoadingData : true, cancellationToken : cancellationToken).ConfigureAwait(false); var version = await GetDiagnosticVersionAsync(_document.Project, cancellationToken).ConfigureAwait(false); if (result.Version == version) { var existingData = GetResult(result, AnalysisKind.NonLocal, _document.Id); if (existingData.IsEmpty) { return(true); } list.AddRange(existingData.Where(ShouldInclude)); return(true); } cancellationToken.ThrowIfCancellationRequested(); // check whether we want up-to-date document wide diagnostics var supportsSemanticInSpan = stateSet.Analyzer.SupportsSpanBasedSemanticDiagnosticAnalysis(); if (!BlockForData(AnalysisKind.NonLocal, supportsSemanticInSpan)) { return(false); } var dx = await diagnosticGetterAsync(stateSet.Analyzer, cancellationToken).ConfigureAwait(false); if (dx != null) { // no state yet list.AddRange(dx.Where(ShouldInclude)); } return(true); }
private async Task <bool> TryGetDocumentDiagnosticsAsync( StateSet stateSet, AnalysisKind kind, DiagnosticsGetterAsync diagnosticGetterAsync, List <DiagnosticData> list, CancellationToken cancellationToken) { if (!_owner.AnalyzerService.SupportAnalysisKind(stateSet.Analyzer, stateSet.Language, kind)) { return(true); } // make sure we get state even when none of our analyzer has ran yet. // but this shouldn't create analyzer that doesn't belong to this project (language) var state = stateSet.GetOrCreateActiveFileState(_document.Id); // see whether we can use existing info var existingData = state.GetAnalysisData(kind); var version = await GetDiagnosticVersionAsync(_document.Project, cancellationToken).ConfigureAwait(false); if (existingData.Version == version) { if (existingData.Items.IsEmpty) { return(true); } list.AddRange(existingData.Items.Where(ShouldInclude)); return(true); } cancellationToken.ThrowIfCancellationRequested(); // check whether we want up-to-date document wide diagnostics var supportsSemanticInSpan = stateSet.Analyzer.SupportsSpanBasedSemanticDiagnosticAnalysis(); if (!BlockForData(kind, supportsSemanticInSpan)) { return(false); } var dx = await diagnosticGetterAsync(stateSet.Analyzer, cancellationToken).ConfigureAwait(false); if (dx != null) { // no state yet list.AddRange(dx.Where(ShouldInclude)); } return(true); }