private async Task <IEnumerable <Diagnostic> > GetDiagnosticsAsync(
            Project project,
            Document document,
            TextSpan?filterSpan,
            bool getDocumentDiagnostics,
            bool getProjectDiagnostics
            )
        {
            var documentDiagnostics = SpecializedCollections.EmptyEnumerable <Diagnostic>();
            var projectDiagnostics  = SpecializedCollections.EmptyEnumerable <Diagnostic>();

            if (getDocumentDiagnostics)
            {
                var dxs = await _diagnosticAnalyzerService.GetDiagnosticsAsync(
                    project.Solution,
                    project.Id,
                    document.Id,
                    _includeSuppressedDiagnostics
                    );

                documentDiagnostics = await CodeAnalysis.Diagnostics.Extensions.ToDiagnosticsAsync(
                    filterSpan is null
                    ?dxs.Where(d => d.HasTextSpan)
                    : dxs.Where(
                        d => d.HasTextSpan && d.GetTextSpan().IntersectsWith(filterSpan.Value)
                        ),
                    project,
                    CancellationToken.None
                    );
            }

            if (getProjectDiagnostics)
            {
                var dxs = await _diagnosticAnalyzerService.GetDiagnosticsAsync(
                    project.Solution,
                    project.Id,
                    includeSuppressedDiagnostics : _includeSuppressedDiagnostics
                    );

                projectDiagnostics = await CodeAnalysis.Diagnostics.Extensions.ToDiagnosticsAsync(
                    dxs.Where(d => !d.HasTextSpan),
                    project,
                    CancellationToken.None
                    );
            }

            var allDiagnostics = documentDiagnostics.Concat(projectDiagnostics);

            if (!_includeSuppressedDiagnostics)
            {
                Assert.True(!allDiagnostics.Any(d => d.IsSuppressed));
            }

            return(allDiagnostics);
        }