Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ void Method()
var diagnostics = await diagnosticService.GetDiagnosticsForSpanAsync(document, span);
Assert.Equal(2, diagnostics.Where(d => d.Id == "CS0219").Count());

var allFixes = (await fixService.GetFixesAsync(document, span, CodeActionOptions.DefaultProvider, isBlocking: false, CancellationToken.None))
var allFixes = (await fixService.GetFixesAsync(document, span, CodeActionOptions.DefaultProvider, CancellationToken.None))
.SelectMany(fixCollection => fixCollection.Fixes);

var cs0219Fixes = allFixes.Where(fix => fix.PrimaryDiagnostic.Id == "CS0219").ToArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ await InvokeBelowInputPriorityAsync(() =>
state.Target.SubjectBuffer.SupportsCodeFixes())
{
var result = await state.Target.Owner._codeFixService.GetMostSevereFixAsync(
document, range.Span.ToTextSpan(), priority, fallbackOptions, isBlocking: false, cancellationToken).ConfigureAwait(false);
document, range.Span.ToTextSpan(), priority, fallbackOptions, cancellationToken).ConfigureAwait(false);

if (result.HasFix)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ Task<ImmutableArray<UnifiedSuggestedActionSet>> GetCodeFixesAsync()

return UnifiedSuggestedActionsSource.GetFilterAndOrderCodeFixesAsync(
workspace, owner._codeFixService, document, range.Span.ToTextSpan(),
priority, options, isBlocking: false, addOperationScope, cancellationToken).AsTask();
priority, options, addOperationScope, cancellationToken).AsTask();
}

Task<ImmutableArray<UnifiedSuggestedActionSet>> GetRefactoringsAsync()
Expand Down
22 changes: 11 additions & 11 deletions src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public async Task TestGetFirstDiagnosticWithFixAsync()
var project = workspace.CurrentSolution.Projects.Single().AddAnalyzerReference(reference);
var document = project.Documents.Single();
var unused = await fixService.GetMostSevereFixAsync(
document, TextSpan.FromBounds(0, 0), CodeActionRequestPriority.None, CodeActionOptions.DefaultProvider, isBlocking: false, CancellationToken.None);
document, TextSpan.FromBounds(0, 0), CodeActionRequestPriority.None, CodeActionOptions.DefaultProvider, CancellationToken.None);

var fixer1 = (MockFixer)fixers.Single().Value;
var fixer2 = (MockFixer)reference.Fixers.Single();
Expand All @@ -90,7 +90,7 @@ public async Task TestGetFixesAsyncWithDuplicateDiagnostics()
GetDocumentAndExtensionManager(tuple.analyzerService, workspace, out var document, out var extensionManager, analyzerReference);

// Verify that we do not crash when computing fixes.
_ = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0), CodeActionOptions.DefaultProvider, isBlocking: false, CancellationToken.None);
_ = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0), CodeActionOptions.DefaultProvider, CancellationToken.None);

// Verify that code fix is invoked with both the diagnostics in the context,
// i.e. duplicate diagnostics are not silently discarded by the CodeFixService.
Expand All @@ -116,7 +116,7 @@ public async Task TestGetFixesAsyncHasNoDuplicateConfigurationActions()
GetDocumentAndExtensionManager(tuple.analyzerService, workspace, out var document, out var extensionManager, analyzerReference);

// Verify registered configuration code actions do not have duplicates.
var fixCollections = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0), CodeActionOptions.DefaultProvider, isBlocking: false, CancellationToken.None);
var fixCollections = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0), CodeActionOptions.DefaultProvider, CancellationToken.None);
var codeActions = fixCollections.SelectMany(c => c.Fixes.Select(f => f.Action)).ToImmutableArray();
Assert.Equal(7, codeActions.Length);
var uniqueTitles = new HashSet<string>();
Expand Down Expand Up @@ -148,14 +148,14 @@ public async Task TestGetFixesAsyncForFixableAndNonFixableAnalyzersAsync()

// Verify only analyzerWithFix is executed when GetFixesAsync is invoked with 'CodeActionRequestPriority.Normal'.
_ = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0),
priority: CodeActionRequestPriority.Normal, CodeActionOptions.DefaultProvider, isBlocking: false,
priority: CodeActionRequestPriority.Normal, CodeActionOptions.DefaultProvider,
addOperationScope: _ => null, cancellationToken: CancellationToken.None);
Assert.True(analyzerWithFix.ReceivedCallback);
Assert.False(analyzerWithoutFix.ReceivedCallback);

// Verify both analyzerWithFix and analyzerWithoutFix are executed when GetFixesAsync is invoked with 'CodeActionRequestPriority.Lowest'.
_ = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0),
priority: CodeActionRequestPriority.Lowest, CodeActionOptions.DefaultProvider, isBlocking: false,
priority: CodeActionRequestPriority.Lowest, CodeActionOptions.DefaultProvider,
addOperationScope: _ => null, cancellationToken: CancellationToken.None);
Assert.True(analyzerWithFix.ReceivedCallback);
Assert.True(analyzerWithoutFix.ReceivedCallback);
Expand Down Expand Up @@ -184,7 +184,7 @@ public async Task TestGetFixesAsyncForDocumentDiagnosticAnalyzerAsync()

// Verify both analyzers are executed when GetFixesAsync is invoked with 'CodeActionRequestPriority.Normal'.
_ = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0),
priority: CodeActionRequestPriority.Normal, CodeActionOptions.DefaultProvider, isBlocking: false,
priority: CodeActionRequestPriority.Normal, CodeActionOptions.DefaultProvider,
addOperationScope: _ => null, cancellationToken: CancellationToken.None);
Assert.True(documentDiagnosticAnalyzer.ReceivedCallback);
}
Expand Down Expand Up @@ -268,7 +268,7 @@ private static async Task<ImmutableArray<CodeFixCollection>> GetAddedFixesAsync(
var reference = new MockAnalyzerReference(codefix, ImmutableArray.Create(diagnosticAnalyzer));
var project = workspace.CurrentSolution.Projects.Single().AddAnalyzerReference(reference);
document = project.Documents.Single();
var fixes = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0), CodeActionOptions.DefaultProvider, isBlocking: false, CancellationToken.None);
var fixes = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0), CodeActionOptions.DefaultProvider, CancellationToken.None);

if (exception)
{
Expand All @@ -293,7 +293,7 @@ private static async Task GetFirstDiagnosticWithFixWithExceptionValidationAsync(

GetDocumentAndExtensionManager(tuple.analyzerService, workspace, out var document, out var extensionManager);
var unused = await tuple.codeFixService.GetMostSevereFixAsync(
document, TextSpan.FromBounds(0, 0), CodeActionRequestPriority.None, CodeActionOptions.DefaultProvider, isBlocking: false, CancellationToken.None);
document, TextSpan.FromBounds(0, 0), CodeActionRequestPriority.None, CodeActionOptions.DefaultProvider, CancellationToken.None);
Assert.True(extensionManager.IsDisabled(codefix));
Assert.False(extensionManager.IsIgnored(codefix));
Assert.True(errorReported);
Expand Down Expand Up @@ -712,7 +712,7 @@ private static async Task<ImmutableArray<CodeFixCollection>> GetNuGetAndVsixCode

var document = project.Documents.Single();

return await fixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0), CodeActionOptions.DefaultProvider, isBlocking: false, CancellationToken.None);
return await fixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0), CodeActionOptions.DefaultProvider, CancellationToken.None);
}

private sealed class NuGetCodeFixProvider : AbstractNuGetOrVsixCodeFixProvider
Expand Down Expand Up @@ -813,7 +813,7 @@ public async Task TestAdditionalDocumentCodeFixAsync()
var tuple = ServiceSetup(fixers, additionalDocument: new TestHostDocument("Additional Document", filePath: "test.txt"));
using var workspace = tuple.workspace;
GetDocumentAndExtensionManager(tuple.analyzerService, workspace, out var txtDocument, out var extensionManager, analyzerReference, documentKind: TextDocumentKind.AdditionalDocument);
var txtDocumentCodeFixes = await tuple.codeFixService.GetFixesAsync(txtDocument, TextSpan.FromBounds(0, 1), CodeActionOptions.DefaultProvider, isBlocking: false, CancellationToken.None);
var txtDocumentCodeFixes = await tuple.codeFixService.GetFixesAsync(txtDocument, TextSpan.FromBounds(0, 1), CodeActionOptions.DefaultProvider, CancellationToken.None);
Assert.Equal(2, txtDocumentCodeFixes.Length);
var txtDocumentCodeFixTitles = txtDocumentCodeFixes.Select(s => s.Fixes.Single().Action.Title).ToImmutableArray();
Assert.Contains(fixer1.Title, txtDocumentCodeFixTitles);
Expand All @@ -830,7 +830,7 @@ public async Task TestAdditionalDocumentCodeFixAsync()
tuple = ServiceSetup(fixers, additionalDocument: new TestHostDocument("Additional Document", filePath: "test.log"));
using var workspace2 = tuple.workspace;
GetDocumentAndExtensionManager(tuple.analyzerService, workspace2, out var logDocument, out extensionManager, analyzerReference, documentKind: TextDocumentKind.AdditionalDocument);
var logDocumentCodeFixes = await tuple.codeFixService.GetFixesAsync(logDocument, TextSpan.FromBounds(0, 1), CodeActionOptions.DefaultProvider, isBlocking: false, CancellationToken.None);
var logDocumentCodeFixes = await tuple.codeFixService.GetFixesAsync(logDocument, TextSpan.FromBounds(0, 1), CodeActionOptions.DefaultProvider, CancellationToken.None);
var logDocumentCodeFix = Assert.Single(logDocumentCodeFixes);
var logDocumentCodeFixTitle = logDocumentCodeFix.Fixes.Single().Action.Title;
Assert.Equal(fixer2.Title, logDocumentCodeFixTitle);
Expand Down
5 changes: 0 additions & 5 deletions src/EditorFeatures/Test2/CodeFixes/CodeFixServiceTests.vb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.CodeFixes.UnitTests
document,
(Await document.GetSyntaxRootAsync()).FullSpan,
CodeActionOptions.DefaultProvider,
isBlocking:=False,
CancellationToken.None)

Assert.Equal(0, fixes.Count())
Expand All @@ -95,7 +94,6 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.CodeFixes.UnitTests
document,
(Await document.GetSyntaxRootAsync()).FullSpan,
CodeActionOptions.DefaultProvider,
isBlocking:=False,
CancellationToken.None)
Assert.Equal(1, fixes.Count())

Expand All @@ -106,7 +104,6 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.CodeFixes.UnitTests
document,
(Await document.GetSyntaxRootAsync()).FullSpan,
CodeActionOptions.DefaultProvider,
isBlocking:=False,
CancellationToken.None)

Assert.Equal(0, fixes.Count())
Expand Down Expand Up @@ -157,7 +154,6 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.CodeFixes.UnitTests
document,
(Await document.GetSyntaxRootAsync()).FullSpan,
CodeActionOptions.DefaultProvider,
isBlocking:=False,
CancellationToken.None)

Assert.Equal(0, fixes.Count())
Expand All @@ -174,7 +170,6 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.CodeFixes.UnitTests
document,
(Await document.GetSyntaxRootAsync()).FullSpan,
CodeActionOptions.DefaultProvider,
isBlocking:=False,
CancellationToken.None)

Assert.Equal(0, fixes.Count())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public CodeFixService(
}

public async Task<FirstFixResult> GetMostSevereFixAsync(
TextDocument document, TextSpan range, CodeActionRequestPriority priority, CodeActionOptionsProvider fallbackOptions, bool isBlocking, CancellationToken cancellationToken)
TextDocument document, TextSpan range, CodeActionRequestPriority priority, CodeActionOptionsProvider fallbackOptions, CancellationToken cancellationToken)
{
var (allDiagnostics, upToDate) = await _diagnosticService.TryGetDiagnosticsForSpanAsync(
document, range, GetShouldIncludeDiagnosticPredicate(document, priority),
Expand Down Expand Up @@ -159,7 +159,6 @@ public async IAsyncEnumerable<CodeFixCollection> StreamFixesAsync(
TextSpan range,
CodeActionRequestPriority priority,
CodeActionOptionsProvider fallbackOptions,
bool isBlocking,
Func<string, IDisposable?> addOperationScope,
[EnumeratorCancellation] CancellationToken cancellationToken)
{
Expand All @@ -175,12 +174,12 @@ public async IAsyncEnumerable<CodeFixCollection> StreamFixesAsync(
// this design's weakness is that each side don't have enough information to narrow down works to do. it
// will most likely always do more works than needed. sometimes way more than it is needed. (compilation)

// We mark blocking requests to GetDiagnosticsForSpanAsync as 'isExplicit = true' to indicate
// We mark requests to GetDiagnosticsForSpanAsync as 'isExplicit = true' to indicate
// user-invoked diagnostic requests, for example, user invoked Ctrl + Dot operation for lightbulb.
var diagnostics = await _diagnosticService.GetDiagnosticsForSpanAsync(
document, range, GetShouldIncludeDiagnosticPredicate(document, priority),
includeCompilerDiagnostics: true, includeSuppressedDiagnostics: includeSuppressionFixes, priority: priority,
addOperationScope: addOperationScope, isExplicit: isBlocking, cancellationToken: cancellationToken).ConfigureAwait(false);
addOperationScope: addOperationScope, isExplicit: true, cancellationToken: cancellationToken).ConfigureAwait(false);

var buildOnlyDiagnosticsService = document.Project.Solution.Services.GetRequiredService<IBuildOnlyDiagnosticsService>();
var buildOnlyDiagnostics = buildOnlyDiagnosticsService.GetBuildOnlyDiagnostics(document.Id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ namespace Microsoft.CodeAnalysis.CodeFixes
{
internal interface ICodeFixService
{
IAsyncEnumerable<CodeFixCollection> StreamFixesAsync(TextDocument document, TextSpan textSpan, CodeActionRequestPriority priority, CodeActionOptionsProvider options, bool isBlocking, Func<string, IDisposable?> addOperationScope, CancellationToken cancellationToken);
IAsyncEnumerable<CodeFixCollection> StreamFixesAsync(TextDocument document, TextSpan textSpan, CodeActionRequestPriority priority, CodeActionOptionsProvider options, Func<string, IDisposable?> addOperationScope, CancellationToken cancellationToken);

/// <summary>
/// Similar to <see cref="StreamFixesAsync"/> except that instead of streaming all results, this ends with the
/// first. This will also attempt to return a fix for an error first, but will fall back to any fix if that
/// does not succeed.
/// </summary>
Task<FirstFixResult> GetMostSevereFixAsync(TextDocument document, TextSpan range, CodeActionRequestPriority priority, CodeActionOptionsProvider fallbackOptions, bool isBlocking, CancellationToken cancellationToken);
Task<FirstFixResult> GetMostSevereFixAsync(TextDocument document, TextSpan range, CodeActionRequestPriority priority, CodeActionOptionsProvider fallbackOptions, CancellationToken cancellationToken);

Task<CodeFixCollection?> GetDocumentFixAllForIdInSpanAsync(TextDocument document, TextSpan textSpan, string diagnosticId, DiagnosticSeverity severity, CodeActionOptionsProvider fallbackOptions, CancellationToken cancellationToken);
Task<TDocument> ApplyCodeFixesForSpecificDiagnosticIdAsync<TDocument>(TDocument document, string diagnosticId, DiagnosticSeverity severity, IProgressTracker progressTracker, CodeActionOptionsProvider fallbackOptions, CancellationToken cancellationToken)
Expand All @@ -33,14 +33,14 @@ Task<TDocument> ApplyCodeFixesForSpecificDiagnosticIdAsync<TDocument>(TDocument

internal static class ICodeFixServiceExtensions
{
public static IAsyncEnumerable<CodeFixCollection> StreamFixesAsync(this ICodeFixService service, TextDocument document, TextSpan range, CodeActionOptionsProvider fallbackOptions, bool isBlocking, CancellationToken cancellationToken)
=> service.StreamFixesAsync(document, range, CodeActionRequestPriority.None, fallbackOptions, isBlocking, addOperationScope: _ => null, cancellationToken);
public static IAsyncEnumerable<CodeFixCollection> StreamFixesAsync(this ICodeFixService service, TextDocument document, TextSpan range, CodeActionOptionsProvider fallbackOptions, CancellationToken cancellationToken)
=> service.StreamFixesAsync(document, range, CodeActionRequestPriority.None, fallbackOptions, addOperationScope: _ => null, cancellationToken);

public static Task<ImmutableArray<CodeFixCollection>> GetFixesAsync(this ICodeFixService service, TextDocument document, TextSpan range, CodeActionOptionsProvider fallbackOptions, bool isBlocking, CancellationToken cancellationToken)
=> service.StreamFixesAsync(document, range, fallbackOptions, isBlocking, cancellationToken).ToImmutableArrayAsync(cancellationToken);
public static Task<ImmutableArray<CodeFixCollection>> GetFixesAsync(this ICodeFixService service, TextDocument document, TextSpan range, CodeActionOptionsProvider fallbackOptions, CancellationToken cancellationToken)
=> service.StreamFixesAsync(document, range, fallbackOptions, cancellationToken).ToImmutableArrayAsync(cancellationToken);

public static Task<ImmutableArray<CodeFixCollection>> GetFixesAsync(this ICodeFixService service, TextDocument document, TextSpan textSpan, CodeActionRequestPriority priority, CodeActionOptionsProvider fallbackOptions, bool isBlocking, Func<string, IDisposable?> addOperationScope, CancellationToken cancellationToken)
=> service.StreamFixesAsync(document, textSpan, priority, fallbackOptions, isBlocking, addOperationScope, cancellationToken).ToImmutableArrayAsync(cancellationToken);
public static Task<ImmutableArray<CodeFixCollection>> GetFixesAsync(this ICodeFixService service, TextDocument document, TextSpan textSpan, CodeActionRequestPriority priority, CodeActionOptionsProvider fallbackOptions, Func<string, IDisposable?> addOperationScope, CancellationToken cancellationToken)
=> service.StreamFixesAsync(document, textSpan, priority, fallbackOptions, addOperationScope, cancellationToken).ToImmutableArrayAsync(cancellationToken);

public static Task<CodeFixCollection?> GetDocumentFixAllForIdInSpanAsync(this ICodeFixService service, TextDocument document, TextSpan range, string diagnosticId, CodeActionOptionsProvider fallbackOptions, CancellationToken cancellationToken)
=> service.GetDocumentFixAllForIdInSpanAsync(document, range, diagnosticId, DiagnosticSeverity.Hidden, fallbackOptions, cancellationToken);
Expand Down
Loading