Skip to content

Commit d1752da

Browse files
authored
Merge pull request #67570 from mavasani/RemoveIsBlocking
Remove IsBlocking flag from CodeFixService
2 parents 2860053 + 6fb082d commit d1752da

File tree

9 files changed

+26
-34
lines changed

9 files changed

+26
-34
lines changed

src/EditorFeatures/CSharpTest/Diagnostics/Suppression/SuppressionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ void Method()
463463
var diagnostics = await diagnosticService.GetDiagnosticsForSpanAsync(document, span);
464464
Assert.Equal(2, diagnostics.Where(d => d.Id == "CS0219").Count());
465465

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

469469
var cs0219Fixes = allFixes.Where(fix => fix.PrimaryDiagnostic.Id == "CS0219").ToArray();

src/EditorFeatures/Core.Wpf/Suggestions/SuggestedActionsSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ await InvokeBelowInputPriorityAsync(() =>
235235
state.Target.SubjectBuffer.SupportsCodeFixes())
236236
{
237237
var result = await state.Target.Owner._codeFixService.GetMostSevereFixAsync(
238-
document, range.Span.ToTextSpan(), priority, fallbackOptions, isBlocking: false, cancellationToken).ConfigureAwait(false);
238+
document, range.Span.ToTextSpan(), priority, fallbackOptions, cancellationToken).ConfigureAwait(false);
239239

240240
if (result.HasFix)
241241
{

src/EditorFeatures/Core.Wpf/Suggestions/SuggestedActionsSource_Async.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ Task<ImmutableArray<UnifiedSuggestedActionSet>> GetCodeFixesAsync()
218218

219219
return UnifiedSuggestedActionsSource.GetFilterAndOrderCodeFixesAsync(
220220
workspace, owner._codeFixService, document, range.Span.ToTextSpan(),
221-
priority, options, isBlocking: false, addOperationScope, cancellationToken).AsTask();
221+
priority, options, addOperationScope, cancellationToken).AsTask();
222222
}
223223

224224
Task<ImmutableArray<UnifiedSuggestedActionSet>> GetRefactoringsAsync()

src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public async Task TestGetFirstDiagnosticWithFixAsync()
6363
var project = workspace.CurrentSolution.Projects.Single().AddAnalyzerReference(reference);
6464
var document = project.Documents.Single();
6565
var unused = await fixService.GetMostSevereFixAsync(
66-
document, TextSpan.FromBounds(0, 0), CodeActionRequestPriority.None, CodeActionOptions.DefaultProvider, isBlocking: false, CancellationToken.None);
66+
document, TextSpan.FromBounds(0, 0), CodeActionRequestPriority.None, CodeActionOptions.DefaultProvider, CancellationToken.None);
6767

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

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

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

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

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

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

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

273273
if (exception)
274274
{
@@ -293,7 +293,7 @@ private static async Task GetFirstDiagnosticWithFixWithExceptionValidationAsync(
293293

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

713713
var document = project.Documents.Single();
714714

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

718718
private sealed class NuGetCodeFixProvider : AbstractNuGetOrVsixCodeFixProvider
@@ -813,7 +813,7 @@ public async Task TestAdditionalDocumentCodeFixAsync()
813813
var tuple = ServiceSetup(fixers, additionalDocument: new TestHostDocument("Additional Document", filePath: "test.txt"));
814814
using var workspace = tuple.workspace;
815815
GetDocumentAndExtensionManager(tuple.analyzerService, workspace, out var txtDocument, out var extensionManager, analyzerReference, documentKind: TextDocumentKind.AdditionalDocument);
816-
var txtDocumentCodeFixes = await tuple.codeFixService.GetFixesAsync(txtDocument, TextSpan.FromBounds(0, 1), CodeActionOptions.DefaultProvider, isBlocking: false, CancellationToken.None);
816+
var txtDocumentCodeFixes = await tuple.codeFixService.GetFixesAsync(txtDocument, TextSpan.FromBounds(0, 1), CodeActionOptions.DefaultProvider, CancellationToken.None);
817817
Assert.Equal(2, txtDocumentCodeFixes.Length);
818818
var txtDocumentCodeFixTitles = txtDocumentCodeFixes.Select(s => s.Fixes.Single().Action.Title).ToImmutableArray();
819819
Assert.Contains(fixer1.Title, txtDocumentCodeFixTitles);
@@ -830,7 +830,7 @@ public async Task TestAdditionalDocumentCodeFixAsync()
830830
tuple = ServiceSetup(fixers, additionalDocument: new TestHostDocument("Additional Document", filePath: "test.log"));
831831
using var workspace2 = tuple.workspace;
832832
GetDocumentAndExtensionManager(tuple.analyzerService, workspace2, out var logDocument, out extensionManager, analyzerReference, documentKind: TextDocumentKind.AdditionalDocument);
833-
var logDocumentCodeFixes = await tuple.codeFixService.GetFixesAsync(logDocument, TextSpan.FromBounds(0, 1), CodeActionOptions.DefaultProvider, isBlocking: false, CancellationToken.None);
833+
var logDocumentCodeFixes = await tuple.codeFixService.GetFixesAsync(logDocument, TextSpan.FromBounds(0, 1), CodeActionOptions.DefaultProvider, CancellationToken.None);
834834
var logDocumentCodeFix = Assert.Single(logDocumentCodeFixes);
835835
var logDocumentCodeFixTitle = logDocumentCodeFix.Fixes.Single().Action.Title;
836836
Assert.Equal(fixer2.Title, logDocumentCodeFixTitle);

src/EditorFeatures/Test2/CodeFixes/CodeFixServiceTests.vb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.CodeFixes.UnitTests
7878
document,
7979
(Await document.GetSyntaxRootAsync()).FullSpan,
8080
CodeActionOptions.DefaultProvider,
81-
isBlocking:=False,
8281
CancellationToken.None)
8382

8483
Assert.Equal(0, fixes.Count())
@@ -95,7 +94,6 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.CodeFixes.UnitTests
9594
document,
9695
(Await document.GetSyntaxRootAsync()).FullSpan,
9796
CodeActionOptions.DefaultProvider,
98-
isBlocking:=False,
9997
CancellationToken.None)
10098
Assert.Equal(1, fixes.Count())
10199

@@ -106,7 +104,6 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.CodeFixes.UnitTests
106104
document,
107105
(Await document.GetSyntaxRootAsync()).FullSpan,
108106
CodeActionOptions.DefaultProvider,
109-
isBlocking:=False,
110107
CancellationToken.None)
111108

112109
Assert.Equal(0, fixes.Count())
@@ -157,7 +154,6 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.CodeFixes.UnitTests
157154
document,
158155
(Await document.GetSyntaxRootAsync()).FullSpan,
159156
CodeActionOptions.DefaultProvider,
160-
isBlocking:=False,
161157
CancellationToken.None)
162158

163159
Assert.Equal(0, fixes.Count())
@@ -174,7 +170,6 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.CodeFixes.UnitTests
174170
document,
175171
(Await document.GetSyntaxRootAsync()).FullSpan,
176172
CodeActionOptions.DefaultProvider,
177-
isBlocking:=False,
178173
CancellationToken.None)
179174

180175
Assert.Equal(0, fixes.Count())

src/Features/LanguageServer/Protocol/Features/CodeFixes/CodeFixService.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public CodeFixService(
9797
}
9898

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

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

185184
var buildOnlyDiagnosticsService = document.Project.Solution.Services.GetRequiredService<IBuildOnlyDiagnosticsService>();
186185
var buildOnlyDiagnostics = buildOnlyDiagnosticsService.GetBuildOnlyDiagnostics(document.Id);

src/Features/LanguageServer/Protocol/Features/CodeFixes/ICodeFixService.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ namespace Microsoft.CodeAnalysis.CodeFixes
1616
{
1717
internal interface ICodeFixService
1818
{
19-
IAsyncEnumerable<CodeFixCollection> StreamFixesAsync(TextDocument document, TextSpan textSpan, CodeActionRequestPriority priority, CodeActionOptionsProvider options, bool isBlocking, Func<string, IDisposable?> addOperationScope, CancellationToken cancellationToken);
19+
IAsyncEnumerable<CodeFixCollection> StreamFixesAsync(TextDocument document, TextSpan textSpan, CodeActionRequestPriority priority, CodeActionOptionsProvider options, Func<string, IDisposable?> addOperationScope, CancellationToken cancellationToken);
2020

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

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

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

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

42-
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)
43-
=> service.StreamFixesAsync(document, textSpan, priority, fallbackOptions, isBlocking, addOperationScope, cancellationToken).ToImmutableArrayAsync(cancellationToken);
42+
public static Task<ImmutableArray<CodeFixCollection>> GetFixesAsync(this ICodeFixService service, TextDocument document, TextSpan textSpan, CodeActionRequestPriority priority, CodeActionOptionsProvider fallbackOptions, Func<string, IDisposable?> addOperationScope, CancellationToken cancellationToken)
43+
=> service.StreamFixesAsync(document, textSpan, priority, fallbackOptions, addOperationScope, cancellationToken).ToImmutableArrayAsync(cancellationToken);
4444

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

0 commit comments

Comments
 (0)