private static async Task <Solution> CreateChangedSolutionAsync(AbstractSuppressionCodeFixProvider fixer, Document triggerDocument, ImmutableDictionary <Document, ImmutableArray <Diagnostic> > diagnosticsByDocument, CancellationToken cancellationToken) { var currentSolution = triggerDocument.Project.Solution; foreach (var grouping in diagnosticsByDocument.GroupBy(d => d.Key.Project)) { var oldProject = grouping.Key; var currentProject = currentSolution.GetProject(oldProject.Id); var compilation = await currentProject.GetCompilationAsync(cancellationToken).ConfigureAwait(false); var supressMessageAttribute = compilation.SuppressMessageAttributeType(); if (supressMessageAttribute != null) { var diagnosticsBySymbol = await CreateDiagnosticsBySymbolAsync(fixer, grouping, cancellationToken).ConfigureAwait(false); if (diagnosticsBySymbol.Any()) { var projectCodeAction = new GlobalSuppressMessageFixAllCodeAction(fixer, supressMessageAttribute, diagnosticsBySymbol, currentProject); var newDocument = await projectCodeAction.GetChangedSuppressionDocumentAsync(cancellationToken).ConfigureAwait(false); currentSolution = newDocument.Project.Solution; } } } return(currentSolution); }
private static async Task<Solution> CreateChangedSolutionAsync(AbstractSuppressionCodeFixProvider fixer, Document triggerDocument, ImmutableDictionary<Document, ImmutableArray<Diagnostic>> diagnosticsByDocument, CancellationToken cancellationToken) { var currentSolution = triggerDocument.Project.Solution; foreach (var grouping in diagnosticsByDocument.GroupBy(d => d.Key.Project)) { var oldProject = grouping.Key; var currentProject = currentSolution.GetProject(oldProject.Id); var diagnosticsBySymbol = await CreateDiagnosticsBySymbolAsync(fixer, grouping, cancellationToken).ConfigureAwait(false); if (diagnosticsBySymbol.Any()) { var projectCodeAction = new GlobalSuppressMessageFixAllCodeAction(fixer, diagnosticsBySymbol, currentProject); var newDocument = await projectCodeAction.GetChangedSuppressionDocumentAsync(cancellationToken).ConfigureAwait(false); currentSolution = newDocument.Project.Solution; } } return currentSolution; }
private static BoundLambda GuessBestBoundLambda <T>(ImmutableDictionary <T, BoundLambda> candidates) { switch (candidates.Count) { case 0: return(null); case 1: return(candidates.First().Value); default: // Prefer candidates with fewer diagnostics. IEnumerable <KeyValuePair <T, BoundLambda> > minDiagnosticsGroup = candidates.GroupBy(lambda => lambda.Value.Diagnostics.Length).OrderBy(group => group.Key).First(); // If multiple candidates have the same number of diagnostics, order them by delegate type name. // It's not great, but it should be stable. return(minDiagnosticsGroup .OrderBy(lambda => GetLambdaSortString(lambda.Value.Symbol)) .FirstOrDefault() .Value); } }