Ejemplo n.º 1
0
            private async Task <AnalysisData> GetExistingProjectAnalysisDataAsync(Project project, DiagnosticState state, CancellationToken cancellationToken)
            {
                // quick bail out
                if (state.Count == 0)
                {
                    return(null);
                }

                var textVersion  = VersionStamp.Default;
                var dataVersion  = VersionStamp.Default;
                var existingData = await state.TryGetExistingDataAsync(project, cancellationToken).ConfigureAwait(false);

                var builder = ImmutableArray.CreateBuilder <DiagnosticData>();

                if (existingData != null)
                {
                    textVersion = existingData.TextVersion;
                    dataVersion = existingData.DataVersion;

                    builder.AddRange(existingData.Items);
                }

                foreach (var document in project.Documents)
                {
                    existingData = await state.TryGetExistingDataAsync(document, cancellationToken).ConfigureAwait(false);

                    if (existingData == null)
                    {
                        continue;
                    }

                    if (dataVersion != VersionStamp.Default && dataVersion != existingData.DataVersion)
                    {
                        continue;
                    }

                    textVersion = existingData.TextVersion;
                    dataVersion = existingData.DataVersion;

                    builder.AddRange(existingData.Items);
                }

                if (dataVersion == VersionStamp.Default)
                {
                    Contract.Requires(textVersion == VersionStamp.Default);
                    return(null);
                }

                Contract.Requires(textVersion != VersionStamp.Default);
                return(new AnalysisData(textVersion, dataVersion, builder.ToImmutable()));
            }
            private async Task AppendProjectAndDocumentDiagnosticsAsync(DiagnosticState state, object documentOrProject, Func <DiagnosticData, bool> predicate, CancellationToken cancellationToken)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var existingData = await state.TryGetExistingDataAsync(documentOrProject, cancellationToken).ConfigureAwait(false);

                if (existingData == null || existingData.Items.Length == 0)
                {
                    return;
                }

                AppendDiagnostics(existingData.Items.Where(predicate));
            }
            private async Task AppendProjectAndDocumentDiagnosticsAsync(DiagnosticState state, object documentOrProject, Func<DiagnosticData, bool> predicate, CancellationToken cancellationToken)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var existingData = await state.TryGetExistingDataAsync(documentOrProject, cancellationToken).ConfigureAwait(false);
                if (existingData == null || existingData.Items.Length == 0)
                {
                    return;
                }

                AppendDiagnostics(existingData.Items.Where(predicate));
            }
            private async Task<AnalysisData> GetExistingProjectAnalysisDataAsync(Project project, DiagnosticState state, CancellationToken cancellationToken)
            {
                // quick bail out
                if (state.Count == 0)
                {
                    return null;
                }

                var textVersion = VersionStamp.Default;
                var dataVersion = VersionStamp.Default;
                var existingData = await state.TryGetExistingDataAsync(project, cancellationToken).ConfigureAwait(false);

                var builder = ImmutableArray.CreateBuilder<DiagnosticData>();
                if (existingData != null)
                {
                    textVersion = existingData.TextVersion;
                    dataVersion = existingData.DataVersion;

                    builder.AddRange(existingData.Items);
                }

                foreach (var document in project.Documents)
                {
                    existingData = await state.TryGetExistingDataAsync(document, cancellationToken).ConfigureAwait(false);
                    if (existingData == null)
                    {
                        continue;
                    }

                    if (dataVersion != VersionStamp.Default && dataVersion != existingData.DataVersion)
                    {
                        continue;
                    }

                    textVersion = existingData.TextVersion;
                    dataVersion = existingData.DataVersion;

                    builder.AddRange(existingData.Items);
                }

                if (dataVersion == VersionStamp.Default)
                {
                    Contract.Requires(textVersion == VersionStamp.Default);
                    return null;
                }

                return new AnalysisData(textVersion, dataVersion, builder.ToImmutable());
            }