static async Task <ImmutableDictionary <Document, ImmutableArray <Diagnostic> > > GetDocumentDiagnosticsToFixWorkerAsync(FixAllContext fixAllContext)
 {
     return(await FixAllContextHelper.GetDocumentDiagnosticsToFixAsync(
                fixAllContext,
                progressTrackerOpt : null,
                (d, c) => DocumentExtensions.IsGeneratedCode(d, c)).ConfigureAwait(false));
 }
                    > GetDocumentDiagnosticsToFixWorkerAsync(FixAllContext fixAllContext)
                {
                    if (
                        fixAllContext.State.DiagnosticProvider
                        is FixAllState.FixMultipleDiagnosticProvider fixMultipleDiagnosticProvider
                        )
                    {
                        return(fixMultipleDiagnosticProvider.DocumentDiagnosticsMap);
                    }

                    using (
                        Logger.LogBlock(
                            FunctionId.CodeFixes_FixAllOccurrencesComputation_Document_Diagnostics,
                            FixAllLogger.CreateCorrelationLogMessage(
                                fixAllContext.State.CorrelationId
                                ),
                            fixAllContext.CancellationToken
                            )
                        )
                    {
                        return(await FixAllContextHelper
                               .GetDocumentDiagnosticsToFixAsync(fixAllContext)
                               .ConfigureAwait(false));
                    }
                }
            private static async Task <ImmutableDictionary <Document, ImmutableArray <Diagnostic> > > GetDocumentDiagnosticsToFixAsync(FixAllContext fixAllContext)
            {
                var result = await FixAllContextHelper.GetDocumentDiagnosticsToFixAsync(fixAllContext).ConfigureAwait(false);

                // Filter out any documents that we don't have any diagnostics for.
                return(result.Where(kvp => !kvp.Value.IsDefaultOrEmpty).ToImmutableDictionary());
            }
        private async Task <Solution> GetSolutionFixesAsync(FixAllContext fixAllContext, ImmutableArray <Document> documents)
        {
            var documentDiagnosticsToFix = await FixAllContextHelper.GetDocumentDiagnosticsToFixAsync(fixAllContext).ConfigureAwait(false);

            using var _1 = PooledHashSet <Document> .GetInstance(out var documentsToFix);

            using var _2 = PooledDictionary <DocumentId, Task <SyntaxNode?> > .GetInstance(out var documentIdToNewNode);

            // Determine the set of documents to actually fix.  We can also use this to update the progress bar with
            // the amount of remaining work to perform.  We'll update the progress bar as we perform each fix in
            // FixAllInDocumentAsync.

            foreach (var document in documents)
            {
                // Don't bother examining any documents that aren't in the list of docs that
                // actually have diagnostics.
                if (!documentDiagnosticsToFix.TryGetValue(document, out var diagnostics))
                {
                    continue;
                }

                documentsToFix.Add(document);
            }

            var progressTracker = fixAllContext.GetProgressTracker();

            progressTracker.Description = WorkspaceExtensionsResources.Applying_fix_all;
            progressTracker.AddItems(documentsToFix.Count);

            foreach (var document in documentsToFix)
            {
                // Upper loop ensures that this indexing will always succeed.
                var diagnostics = documentDiagnosticsToFix[document];
                documentIdToNewNode.Add(document.Id, FixAllInDocumentAsync(fixAllContext, progressTracker, document, diagnostics));
            }

            // Allow the processing of all the documents to happen concurrently.
            await Task.WhenAll(documentIdToNewNode.Values).ConfigureAwait(false);

            var solution = fixAllContext.Solution;

            foreach (var(docId, syntaxNodeTask) in documentIdToNewNode)
            {
                var newDocumentRoot = await syntaxNodeTask.ConfigureAwait(false);

                if (newDocumentRoot == null)
                {
                    continue;
                }

                solution = solution.WithDocumentSyntaxRoot(docId, newDocumentRoot);
            }

            return(solution);
        }
 internal virtual async Task <ImmutableDictionary <Document, ImmutableArray <Diagnostic> > > GetDocumentDiagnosticsToFixWorkerAsync(
     FixAllContext fixAllContext)
 {
     using (Logger.LogBlock(
                FunctionId.CodeFixes_FixAllOccurrencesComputation_Document_Diagnostics,
                FixAllLogger.CreateCorrelationLogMessage(fixAllContext.State.CorrelationId),
                fixAllContext.CancellationToken))
     {
         return(await FixAllContextHelper.GetDocumentDiagnosticsToFixAsync(
                    fixAllContext,
                    fixAllContext.ProgressTracker,
                    (document, cancellationToken) => document.IsGeneratedCode(cancellationToken)).ConfigureAwait(false));
     }
 }
示例#6
0
        private async Task <Document> GetDocumentFixesAsync(FixAllContext fixAllContext)
        {
            var documentDiagnosticsToFix = await FixAllContextHelper.GetDocumentDiagnosticsToFixAsync(fixAllContext, progressTrackerOpt : null).ConfigureAwait(false);

            if (!documentDiagnosticsToFix.TryGetValue(fixAllContext.Document, out var diagnostics))
            {
                return(fixAllContext.Document);
            }

            var newRoot = await FixAllInDocumentAsync(fixAllContext, fixAllContext.Document, diagnostics).ConfigureAwait(false);

            if (newRoot == null)
            {
                return(fixAllContext.Document);
            }

            return(fixAllContext.Document.WithSyntaxRoot(newRoot));
        }
示例#7
0
                static async Task <ImmutableDictionary <Document, ImmutableArray <Diagnostic> > > GetDocumentDiagnosticsToFixWorkerAsync(FixAllContext fixAllContext)
                {
                    if (fixAllContext.State.DiagnosticProvider is FixAllState.FixMultipleDiagnosticProvider fixMultipleDiagnosticProvider)
                    {
                        return(fixMultipleDiagnosticProvider.DocumentDiagnosticsMap);
                    }

                    using (Logger.LogBlock(
                               FunctionId.CodeFixes_FixAllOccurrencesComputation_Document_Diagnostics,
                               FixAllLogger.CreateCorrelationLogMessage(fixAllContext.State.CorrelationId),
                               fixAllContext.CancellationToken))
                    {
                        return(await FixAllContextHelper.GetDocumentDiagnosticsToFixAsync(
                                   fixAllContext,
                                   fixAllContext.ProgressTracker,
                                   (d, c) => DocumentExtensions.IsGeneratedCode(d, c)).ConfigureAwait(false));
                    }
                }
        private async Task <Document> GetDocumentFixesAsync(FixAllContext fixAllContext)
        {
            RoslynDebug.AssertNotNull(fixAllContext.Document);

            var documentDiagnosticsToFix = await FixAllContextHelper.GetDocumentDiagnosticsToFixAsync(fixAllContext).ConfigureAwait(false);

            if (!documentDiagnosticsToFix.TryGetValue(fixAllContext.Document, out var diagnostics))
            {
                return(fixAllContext.Document);
            }

            var newRoot = await FixAllInDocumentAsync(fixAllContext, fixAllContext.Document, diagnostics).ConfigureAwait(false);

            if (newRoot == null)
            {
                return(fixAllContext.Document);
            }

            return(fixAllContext.Document.WithSyntaxRoot(newRoot));
        }
示例#9
0
        private async Task <Solution> GetSolutionFixesAsync(FixAllContext fixAllContext, ImmutableArray <Document> documents)
        {
            var documentDiagnosticsToFix = await FixAllContextHelper.GetDocumentDiagnosticsToFixAsync(fixAllContext, progressTrackerOpt : null).ConfigureAwait(false);

            using var _ = PooledDictionary <DocumentId, Task <SyntaxNode?> > .GetInstance(out var documentIdToNewNode);

            foreach (var document in documents)
            {
                // Don't bother examining any documents that aren't in the list of docs that
                // actually have diagnostics.
                if (!documentDiagnosticsToFix.TryGetValue(document, out var diagnostics))
                {
                    continue;
                }

                documentIdToNewNode.Add(document.Id, FixAllInDocumentAsync(fixAllContext, document, diagnostics));
            }

            // Allow the processing of all the documents to happen concurrently.
            await Task.WhenAll(documentIdToNewNode.Values).ConfigureAwait(false);

            var solution = fixAllContext.Solution;

            foreach (var(docId, syntaxNodeTask) in documentIdToNewNode)
            {
                var newDocumentRoot = await syntaxNodeTask.ConfigureAwait(false);

                if (newDocumentRoot == null)
                {
                    continue;
                }

                solution = solution.WithDocumentSyntaxRoot(docId, newDocumentRoot);
            }

            return(solution);
        }
示例#10
0
 /// <summary>
 /// Determines all the diagnostics we should be fixing for the given <paramref name="fixAllContext"/>.
 /// </summary>
 private static async Task <ImmutableDictionary <Document, ImmutableArray <Diagnostic> > > DetermineDiagnosticsAsync(FixAllContext fixAllContext, IProgressTracker progressTracker)
 {
     using var _ = progressTracker.ItemCompletedScope();
     return(await FixAllContextHelper.GetDocumentDiagnosticsToFixAsync(fixAllContext).ConfigureAwait(false));
 }