Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Jul 2, 2024
1 parent b7bc504 commit 6a4f2d3
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public bool IsFixableDiagnostic(Diagnostic diagnostic)
public FixAllProvider? GetFixAllProvider()
=> null;

public Task<ImmutableArray<CodeFix>> GetFixesAsync(TextDocument document, TextSpan span, IEnumerable<Diagnostic> diagnostics, CodeActionOptionsProvider fallbackOptions, CancellationToken cancellationToken)
public Task<ImmutableArray<CodeFix>> GetFixesAsync(TextDocument document, TextSpan span, IEnumerable<Diagnostic> diagnostics, CancellationToken cancellationToken)
=> Task.FromResult(GetConfigurations(document.Project, diagnostics));

public Task<ImmutableArray<CodeFix>> GetFixesAsync(Project project, IEnumerable<Diagnostic> diagnostics, CodeActionOptionsProvider fallbackOptions, CancellationToken cancellationToken)
public Task<ImmutableArray<CodeFix>> GetFixesAsync(Project project, IEnumerable<Diagnostic> diagnostics, CancellationToken cancellationToken)
=> Task.FromResult(GetConfigurations(project, diagnostics));

private static ImmutableArray<CodeFix> GetConfigurations(Project project, IEnumerable<Diagnostic> diagnostics)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public bool IsFixableDiagnostic(Diagnostic diagnostic)
public FixAllProvider? GetFixAllProvider()
=> null;

public Task<ImmutableArray<CodeFix>> GetFixesAsync(TextDocument document, TextSpan span, IEnumerable<Diagnostic> diagnostics, CodeActionOptionsProvider fallbackOptions, CancellationToken cancellationToken)
public Task<ImmutableArray<CodeFix>> GetFixesAsync(TextDocument document, TextSpan span, IEnumerable<Diagnostic> diagnostics, CancellationToken cancellationToken)
=> Task.FromResult(GetConfigurations(document.Project, diagnostics, cancellationToken));

public Task<ImmutableArray<CodeFix>> GetFixesAsync(Project project, IEnumerable<Diagnostic> diagnostics, CodeActionOptionsProvider fallbackOptions, CancellationToken cancellationToken)
public Task<ImmutableArray<CodeFix>> GetFixesAsync(Project project, IEnumerable<Diagnostic> diagnostics, CancellationToken cancellationToken)
=> Task.FromResult(GetConfigurations(project, diagnostics, cancellationToken));

private static ImmutableArray<CodeFix> GetConfigurations(Project project, IEnumerable<Diagnostic> diagnostics, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private static async Task<Document> BatchPragmaFixesAsync(
properties: diagnostic.Properties,
isSuppressed: diagnostic.IsSuppressed);

var newSuppressionFixes = await suppressionFixProvider.GetFixesAsync(currentDocument, currentDiagnosticSpan, [diagnostic], fallbackOptions, cancellationToken).ConfigureAwait(false);
var newSuppressionFixes = await suppressionFixProvider.GetFixesAsync(currentDocument, currentDiagnosticSpan, fallbackOptions, cancellationToken).ConfigureAwait(false);
var newSuppressionFix = newSuppressionFixes.SingleOrDefault();
if (newSuppressionFix != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected override async Task AddDocumentFixesAsync(
{
var span = diagnostic.Location.SourceSpan;
var removeSuppressionFixes = await _suppressionFixProvider.GetFixesAsync(
document, span, [diagnostic], fixAllState.CodeActionOptionsProvider, cancellationToken).ConfigureAwait(false);
document, span, fixAllState.CodeActionOptionsProvider, cancellationToken).ConfigureAwait(false);
var removeSuppressionFix = removeSuppressionFixes.SingleOrDefault();
if (removeSuppressionFix != null)
{
Expand Down Expand Up @@ -89,7 +89,7 @@ protected override async Task AddProjectFixesAsync(
foreach (var diagnostic in diagnostics.Where(d => !d.Location.IsInSource && d.IsSuppressed))
{
var removeSuppressionFixes = await _suppressionFixProvider.GetFixesAsync(
project, [diagnostic], fixAllState.CodeActionOptionsProvider, cancellationToken).ConfigureAwait(false);
project, [diagnostic], cancellationToken).ConfigureAwait(false);
if (removeSuppressionFixes.SingleOrDefault()?.Action is RemoveSuppressionCodeAction removeSuppressionCodeAction)
{
if (fixAllState.IsFixMultiple)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,24 +139,24 @@ private SyntaxToken GetAdjustedTokenForPragmaRestore(SyntaxToken token, SyntaxNo
}

public Task<ImmutableArray<CodeFix>> GetFixesAsync(
TextDocument textDocument, TextSpan span, IEnumerable<Diagnostic> diagnostics, CodeActionOptionsProvider fallbackOptions, CancellationToken cancellationToken)
TextDocument textDocument, TextSpan span, IEnumerable<Diagnostic> diagnostics, CancellationToken cancellationToken)
{
if (textDocument is not Document document)
return Task.FromResult(ImmutableArray<CodeFix>.Empty);

return GetSuppressionsAsync(document, span, diagnostics, fallbackOptions, skipSuppressMessage: false, skipUnsuppress: false, cancellationToken: cancellationToken);
return GetSuppressionsAsync(document, span, diagnostics, skipSuppressMessage: false, skipUnsuppress: false, cancellationToken: cancellationToken);
}

internal async Task<ImmutableArray<PragmaWarningCodeAction>> GetPragmaSuppressionsAsync(Document document, TextSpan span, IEnumerable<Diagnostic> diagnostics, CodeActionOptionsProvider fallbackOptions, CancellationToken cancellationToken)
internal async Task<ImmutableArray<PragmaWarningCodeAction>> GetPragmaSuppressionsAsync(Document document, TextSpan span, IEnumerable<Diagnostic> diagnostics, CancellationToken cancellationToken)
{
var codeFixes = await GetSuppressionsAsync(document, span, diagnostics, fallbackOptions, skipSuppressMessage: true, skipUnsuppress: true, cancellationToken: cancellationToken).ConfigureAwait(false);
var codeFixes = await GetSuppressionsAsync(document, span, diagnostics, skipSuppressMessage: true, skipUnsuppress: true, cancellationToken: cancellationToken).ConfigureAwait(false);
return codeFixes.SelectMany(fix => fix.Action.NestedActions)
.OfType<PragmaWarningCodeAction>()
.ToImmutableArray();
}

private async Task<ImmutableArray<CodeFix>> GetSuppressionsAsync(
Document document, TextSpan span, IEnumerable<Diagnostic> diagnostics, CodeActionOptionsProvider fallbackOptions, bool skipSuppressMessage, bool skipUnsuppress, CancellationToken cancellationToken)
Document document, TextSpan span, IEnumerable<Diagnostic> diagnostics, bool skipSuppressMessage, bool skipUnsuppress, CancellationToken cancellationToken)
{
var suppressionTargetInfo = await GetSuppressionTargetInfoAsync(document, span, cancellationToken).ConfigureAwait(false);
if (suppressionTargetInfo == null)
Expand All @@ -165,11 +165,11 @@ private async Task<ImmutableArray<CodeFix>> GetSuppressionsAsync(
}

return await GetSuppressionsAsync(
document, document.Project, diagnostics, suppressionTargetInfo, fallbackOptions, skipSuppressMessage, skipUnsuppress, cancellationToken).ConfigureAwait(false);
document, document.Project, diagnostics, suppressionTargetInfo, skipSuppressMessage, skipUnsuppress, cancellationToken).ConfigureAwait(false);
}

public async Task<ImmutableArray<CodeFix>> GetFixesAsync(
Project project, IEnumerable<Diagnostic> diagnostics, CodeActionOptionsProvider fallbackOptions, CancellationToken cancellationToken)
Project project, IEnumerable<Diagnostic> diagnostics, CancellationToken cancellationToken)
{
if (!project.SupportsCompilation)
{
Expand All @@ -180,12 +180,12 @@ public async Task<ImmutableArray<CodeFix>> GetFixesAsync(
var suppressionTargetInfo = new SuppressionTargetInfo() { TargetSymbol = compilation.Assembly };
return await GetSuppressionsAsync(
documentOpt: null, project, diagnostics, suppressionTargetInfo,
fallbackOptions, skipSuppressMessage: false, skipUnsuppress: false,
skipSuppressMessage: false, skipUnsuppress: false,
cancellationToken).ConfigureAwait(false);
}

private async Task<ImmutableArray<CodeFix>> GetSuppressionsAsync(
Document documentOpt, Project project, IEnumerable<Diagnostic> diagnostics, SuppressionTargetInfo suppressionTargetInfo, CodeActionOptionsProvider fallbackOptions, bool skipSuppressMessage, bool skipUnsuppress, CancellationToken cancellationToken)
Document documentOpt, Project project, IEnumerable<Diagnostic> diagnostics, SuppressionTargetInfo suppressionTargetInfo, bool skipSuppressMessage, bool skipUnsuppress, CancellationToken cancellationToken)
{
// We only care about diagnostics that can be suppressed/unsuppressed.
diagnostics = diagnostics.Where(IsFixableDiagnostic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
var documentDiagnostics = diagnostics.Where(d => d.Location.IsInSource).ToImmutableArray();
if (!documentDiagnostics.IsEmpty)
{
var suppressionFixes = await _suppressionFixProvider.GetFixesAsync(context.Document, context.Span, documentDiagnostics, context.Options, context.CancellationToken).ConfigureAwait(false);
var suppressionFixes = await _suppressionFixProvider.GetFixesAsync(context.Document, context.Span, documentDiagnostics, context.CancellationToken).ConfigureAwait(false);
RegisterSuppressionFixes(context, suppressionFixes);
}

var projectDiagnostics = diagnostics.Where(d => !d.Location.IsInSource).ToImmutableArray();
if (!projectDiagnostics.IsEmpty)
{
var suppressionFixes = await _suppressionFixProvider.GetFixesAsync(context.Document.Project, projectDiagnostics, context.Options, context.CancellationToken).ConfigureAwait(false);
var suppressionFixes = await _suppressionFixProvider.GetFixesAsync(context.Document.Project, projectDiagnostics, context.CancellationToken).ConfigureAwait(false);
RegisterSuppressionFixes(context, suppressionFixes);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ await GenerateStructIntoContainingNamespaceAsync(
documentToEditorMap, fallbackOptions, cancellationToken).ConfigureAwait(false);

var updatedSolution = await ApplyChangesAsync(
document, documentToEditorMap, fallbackOptions, cancellationToken).ConfigureAwait(false);
document, documentToEditorMap, cancellationToken).ConfigureAwait(false);

return updatedSolution;
}
Expand Down Expand Up @@ -583,7 +583,7 @@ private static async Task GenerateStructIntoContainingNamespaceAsync(
}

private static async Task<Solution> ApplyChangesAsync(
Document startingDocument, Dictionary<Document, SyntaxEditor> documentToEditorMap, CodeCleanupOptionsProvider fallbackOptions, CancellationToken cancellationToken)
Document startingDocument, Dictionary<Document, SyntaxEditor> documentToEditorMap, CancellationToken cancellationToken)
{
var currentSolution = startingDocument.Project.Solution;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected async Task TestPragmaOrAttributeAsync(
continue;
}

var fixes = fixer.GetFixesAsync(document, diagnostic.Location.SourceSpan, [diagnostic], CodeActionOptions.DefaultProvider, CancellationToken.None).GetAwaiter().GetResult();
var fixes = fixer.GetFixesAsync(document, diagnostic.Location.SourceSpan, [diagnostic], CancellationToken.None).GetAwaiter().GetResult();
if (fixes == null || fixes.Count() <= 0)
{
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static async ValueTask<OmniSharpSyntaxFormattingOptionsWrapper> FromDocum
.Add(FormattingOptions2.NewLine.Definition.ConfigName, FormattingOptions2.NewLine.Definition.Serializer.Serialize(fallbackLineFormattingOptions.NewLine)))));

return new OmniSharpSyntaxFormattingOptionsWrapper(
optionsWithFallback.GetSyntaxFormattingOptions(document.Project.Services, fallbackOptions: null));
optionsWithFallback.GetSyntaxFormattingOptions(document.Project.Services));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ private async IAsyncEnumerable<CodeFixCollection> StreamConfigurationFixesAsync(
hasFix: d => provider.IsFixableDiagnostic(d),
getFixes: async dxs =>
{
var fixes = await provider.GetFixesAsync(document, diagnosticsSpan, dxs, fallbackOptions, cancellationToken).ConfigureAwait(false);
var fixes = await provider.GetFixesAsync(document, diagnosticsSpan, dxs, cancellationToken).ConfigureAwait(false);
return fixes.WhereAsArray(f => registeredConfigurationFixTitles.Add(f.Action.Title));
},
fallbackOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ internal interface IConfigurationFixProvider
/// Gets one or more add suppression, remove suppression, or configuration fixes for the specified diagnostics represented as a list of <see cref="CodeAction"/>'s.
/// </summary>
/// <returns>A list of zero or more potential <see cref="CodeFix"/>'es. It is also safe to return null if there are none.</returns>
Task<ImmutableArray<CodeFix>> GetFixesAsync(TextDocument document, TextSpan span, IEnumerable<Diagnostic> diagnostics, CodeActionOptionsProvider fallbackOptions, CancellationToken cancellationToken);
Task<ImmutableArray<CodeFix>> GetFixesAsync(TextDocument document, TextSpan span, IEnumerable<Diagnostic> diagnostics, CancellationToken cancellationToken);

/// <summary>
/// Gets one or more add suppression, remove suppression, or configuration fixes for the specified no-location diagnostics represented as a list of <see cref="CodeAction"/>'s.
/// </summary>
/// <returns>A list of zero or more potential <see cref="CodeFix"/>'es. It is also safe to return null if there are none.</returns>
Task<ImmutableArray<CodeFix>> GetFixesAsync(Project project, IEnumerable<Diagnostic> diagnostics, CodeActionOptionsProvider fallbackOptions, CancellationToken cancellationToken);
Task<ImmutableArray<CodeFix>> GetFixesAsync(Project project, IEnumerable<Diagnostic> diagnostics, CancellationToken cancellationToken);

/// <summary>
/// Gets an optional <see cref="FixAllProvider"/> that can fix all/multiple occurrences of diagnostics fixed by this fix provider.
Expand Down
2 changes: 1 addition & 1 deletion src/Workspaces/Core/Portable/Formatting/Formatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static async Task<Document> FormatAsync(Document document, IEnumerable<Te

internal static async Task<Document> FormatAsync(Document document, IEnumerable<TextSpan>? spans, SyntaxFormattingOptions? options, ImmutableArray<AbstractFormattingRule> rules, CancellationToken cancellationToken)
{
options ??= await document.GetSyntaxFormattingOptionsAsync(fallbackOptions: null, cancellationToken).ConfigureAwait(false);
options ??= await document.GetSyntaxFormattingOptionsAsync(cancellationToken).ConfigureAwait(false);
var root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var services = document.Project.Solution.Services;
return document.WithSyntaxRoot(Format(root, spans, services, options, rules, cancellationToken));
Expand Down

0 comments on commit 6a4f2d3

Please sign in to comment.