private async Task <IReadOnlyList <VSInternalDiagnosticReport> > RemapDocumentDiagnosticsAsync(
            IReadOnlyList <VSInternalDiagnosticReport> unmappedDiagnosticReports,
            Uri razorDocumentUri,
            CancellationToken cancellationToken)
        {
            if (unmappedDiagnosticReports.Any() != true)
            {
                return(unmappedDiagnosticReports);
            }

            var mappedDiagnosticReports = new List <VSInternalDiagnosticReport>(unmappedDiagnosticReports.Count);

            foreach (var diagnosticReport in unmappedDiagnosticReports)
            {
                // Check if there are any diagnostics in this report
                if (diagnosticReport?.Diagnostics?.Any() != true)
                {
                    _logger.LogInformation("Diagnostic report contained no diagnostics.");
                    if (diagnosticReport is not null)
                    {
                        mappedDiagnosticReports.Add(diagnosticReport);
                    }

                    continue;
                }

                _logger.LogInformation($"Requesting processing of {diagnosticReport.Diagnostics.Length} diagnostics.");

                var processedDiagnostics = await _diagnosticsProvider.TranslateAsync(
                    RazorLanguageKind.CSharp,
                    razorDocumentUri,
                    diagnosticReport.Diagnostics,
                    cancellationToken
                    ).ConfigureAwait(false);

                if (processedDiagnostics is null || !_documentManager.TryGetDocument(razorDocumentUri, out var documentSnapshot) ||
                    documentSnapshot.Version != processedDiagnostics.HostDocumentVersion)
                {
                    _logger.LogInformation($"Document version mismatch, discarding {diagnosticReport.Diagnostics.Length} diagnostics.");

                    // We choose to discard diagnostics in this case & report nothing changed.
                    diagnosticReport.Diagnostics = null;
                    mappedDiagnosticReports.Add(diagnosticReport);
                    continue;
                }

                _logger.LogInformation($"Returning {processedDiagnostics.Diagnostics.Length} diagnostics.");
                diagnosticReport.Diagnostics = processedDiagnostics.Diagnostics;

                mappedDiagnosticReports.Add(diagnosticReport);
            }

            return(mappedDiagnosticReports.ToArray());
        }
        private async Task <DiagnosticReport[]> RemapDocumentDiagnosticsAsync(
            DiagnosticReport[] unmappedDiagnosticReports,
            Uri razorDocumentUri,
            CancellationToken cancellationToken)
        {
            if (unmappedDiagnosticReports?.Any() != true)
            {
                return(unmappedDiagnosticReports);
            }

            var mappedDiagnosticReports = new List <DiagnosticReport>(unmappedDiagnosticReports.Length);

            foreach (var diagnosticReport in unmappedDiagnosticReports)
            {
                // Check if there are any diagnostics in this report
                if (diagnosticReport?.Diagnostics?.Any() != true)
                {
                    mappedDiagnosticReports.Add(diagnosticReport);
                    continue;
                }

                var processedDiagnostics = await _diagnosticsProvider.TranslateAsync(
                    RazorLanguageKind.CSharp,
                    razorDocumentUri,
                    diagnosticReport.Diagnostics,
                    cancellationToken
                    ).ConfigureAwait(false);

                if (!_documentManager.TryGetDocument(razorDocumentUri, out var documentSnapshot) ||
                    documentSnapshot.Version != processedDiagnostics.HostDocumentVersion)
                {
                    // We choose to discard diagnostics in this case & report nothing changed.
                    diagnosticReport.Diagnostics = null;
                    mappedDiagnosticReports.Add(diagnosticReport);
                    continue;
                }

                diagnosticReport.Diagnostics = processedDiagnostics.Diagnostics;

                mappedDiagnosticReports.Add(diagnosticReport);
            }

            return(mappedDiagnosticReports.ToArray());
        }