Skip to content

Commit e3cf188

Browse files
Simplify the CodeFix type (#80236)
2 parents 6b2240f + c6577e7 commit e3cf188

File tree

13 files changed

+70
-89
lines changed

13 files changed

+70
-89
lines changed

src/EditorFeatures/Core/Suggestions/SuggestedActions/SuggestedActionWithNestedFlavors.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ await copilotService.IsAvailableAsync(cancellationToken).ConfigureAwait(false) i
171171

172172
// after this point, this method should only return at GetPreviewPane. otherwise, DifferenceViewer will leak
173173
// since there is no one to close the viewer
174-
var preferredDocumentId = this.SubjectBuffer.AsTextContainer().GetOpenDocumentInCurrentContext()?.Id;
175-
var preferredProjectId = preferredDocumentId?.ProjectId;
174+
var preferredDocumentId = this.OriginalDocument.Id;
175+
var preferredProjectId = preferredDocumentId.ProjectId;
176176

177177
var extensionManager = this.OriginalSolution.Services.GetRequiredService<IExtensionManager>();
178178
var previewContents = await extensionManager.PerformFunctionAsync(Provider, async cancellationToken =>
@@ -197,7 +197,7 @@ await copilotService.IsAvailableAsync(cancellationToken).ConfigureAwait(false) i
197197
// GetPreviewPane() needs to run on the UI thread.
198198
this.ThreadingContext.ThrowIfNotOnUIThread();
199199

200-
var diagnosticData = _diagnostic is null ? null : CodeFix.GetDiagnosticData(this.OriginalDocument.Project, _diagnostic);
200+
var diagnosticData = DiagnosticData.Create(_diagnostic, this.OriginalDocument.Project);
201201
return previewPaneService.GetPreviewPane(diagnosticData, previewContents!);
202202
}
203203

src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractUserDiagnosticTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ protected static Document GetDocumentAndSelectSpan(EditorTestWorkspace workspace
157157
document,
158158
diagnostic.Location.SourceSpan,
159159
[diagnostic],
160-
(a, d) => fixes.Add(new CodeFix(document.Project, a, d)),
160+
(a, d) => fixes.Add(new CodeFix(a, d)),
161161
CancellationToken.None);
162162

163163
await fixer.RegisterCodeFixesAsync(context);

src/EditorFeatures/Test2/Diagnostics/AbstractCrossLanguageUserDiagnosticTests.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics
165165

166166
For Each diagnostic In diagnostics
167167
Dim fixes = New List(Of CodeFix)
168-
Dim context = New CodeFixContext(document, diagnostic, Sub(a, d) fixes.Add(New CodeFix(document.Project, a, d)), CancellationToken.None)
168+
Dim context = New CodeFixContext(document, diagnostic, Sub(a, d) fixes.Add(New CodeFix(a, d)), CancellationToken.None)
169169
providerAndFixer.Item2.RegisterCodeFixesAsync(context).Wait()
170170
If fixes.Any() Then
171171
result.Add(Tuple.Create(diagnostic, New CodeFixCollection(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ void Method()
492492
var allFixes = (await fixService.GetFixesAsync(document, span, CancellationToken.None))
493493
.SelectMany(fixCollection => fixCollection.Fixes);
494494

495-
var cs0219Fixes = allFixes.Where(fix => fix.PrimaryDiagnostic.Id == "CS0219").ToArray();
495+
var cs0219Fixes = allFixes.Where(fix => fix.Diagnostics.First().Id == "CS0219").ToArray();
496496

497497
// Ensure that there are no duplicate suppression fixes.
498498
Assert.Equal(1, cs0219Fixes.Length);
@@ -502,7 +502,7 @@ void Method()
502502
// Ensure that there *is* a fix for the other warning and that it has a *different*
503503
// equivalence key so that it *doesn't* get de-duplicated
504504
Assert.Equal(1, diagnostics.Where(d => d.Id == "CS0168").Count());
505-
var cs0168Fixes = allFixes.Where(fix => fix.PrimaryDiagnostic.Id == "CS0168");
505+
var cs0168Fixes = allFixes.Where(fix => fix.Diagnostics.First().Id == "CS0168");
506506
var cs0168EquivalenceKey = cs0168Fixes.Single().Action.EquivalenceKey;
507507
Assert.NotNull(cs0168EquivalenceKey);
508508
Assert.NotEqual(cs0219EquivalenceKey, cs0168EquivalenceKey);

src/Features/Core/Portable/CodeFixes/Configuration/ConfigureCodeStyle/ConfigureCodeStyleOptionCodeFixProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private static ImmutableArray<CodeFix> GetConfigurations(Project project, IEnume
9191
? new TopLevelConfigureCodeStyleOptionCodeAction(diagnostic, nestedActions.ToImmutable())
9292
: nestedActions.Single();
9393

94-
result.Add(new CodeFix(project, resultCodeAction, diagnostic));
94+
result.Add(new CodeFix(resultCodeAction, [diagnostic]));
9595
}
9696
}
9797

src/Features/Core/Portable/CodeFixes/Configuration/ConfigureSeverity/ConfigureSeverityLevelCodeFixProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private static ImmutableArray<CodeFix> GetConfigurations(Project project, IEnume
6868
}
6969

7070
var codeAction = new TopLevelConfigureSeverityCodeAction(diagnostic, nestedActions.ToImmutableAndFree());
71-
result.Add(new CodeFix(project, codeAction, diagnostic));
71+
result.Add(new CodeFix(codeAction, [diagnostic]));
7272

7373
// Bulk configuration is only supported for analyzer diagnostics.
7474
if (!SuppressionHelpers.IsCompilerDiagnostic(diagnostic))
@@ -111,7 +111,7 @@ void AddBulkConfigurationCodeFixes(ImmutableArray<Diagnostic> diagnostics, strin
111111
}
112112

113113
var codeAction = new TopLevelBulkConfigureSeverityCodeAction(nestedActions.ToImmutableAndFree(), category);
114-
result.Add(new CodeFix(project, codeAction, diagnostics));
114+
result.Add(new CodeFix(codeAction, diagnostics));
115115
}
116116
}
117117
}

src/Features/Core/Portable/CodeFixes/Service/CodeFixService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ private static async Task<ImmutableArray<CodeFix>> GetCodeFixesAsync(
682682
// name metadata.
683683
action.AddCustomTagAndTelemetryInfo(fixerMetadata, fixer);
684684

685-
fixes.Add(new CodeFix(document.Project, action, applicableDiagnostics));
685+
fixes.Add(new CodeFix(action, applicableDiagnostics));
686686
}
687687
}
688688
},

src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,14 @@ private async Task<ImmutableArray<CodeFix>> GetSuppressionsAsync(
235235
{
236236
var codeAction = new TopLevelSuppressionCodeAction(
237237
diagnostic, nestedActions.ToImmutableAndClear());
238-
result.Add(new CodeFix(project, codeAction, diagnostic));
238+
result.Add(new CodeFix(codeAction, [diagnostic]));
239239
}
240240
}
241241
else if (!skipUnsuppress)
242242
{
243243
var codeAction = await RemoveSuppressionCodeAction.CreateAsync(suppressionTargetInfo, documentOpt, project, diagnostic, this, cancellationToken).ConfigureAwait(false);
244244
if (codeAction != null)
245-
{
246-
result.Add(new CodeFix(project, codeAction, diagnostic));
247-
}
245+
result.Add(new CodeFix(codeAction, [diagnostic]));
248246
}
249247
}
250248

src/Features/Core/Portable/Copilot/ICopilotChangeAnalysisService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,9 @@ static async (span, callback, args, cancellationToken) =>
350350
if (codeFixCollection is
351351
{
352352
Provider: not IConfigurationFixProvider,
353-
Fixes: [var codeFix, ..],
353+
Fixes: [{ Diagnostics: [var primaryDiagnostic, ..] }, ..],
354354
} &&
355-
IsVisibleDiagnostic(codeFix.PrimaryDiagnostic.IsSuppressed, codeFix.PrimaryDiagnostic.Severity) &&
355+
IsVisibleDiagnostic(primaryDiagnostic.IsSuppressed, primaryDiagnostic.Severity) &&
356356
(codeFixCollection.Provider.GetType().Namespace ?? "").StartsWith(RoslynPrefix))
357357
{
358358
callback(codeFixCollection);

src/Features/DiagnosticsTestUtilities/Diagnostics/AbstractUserDiagnosticTest_NoEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ protected static Document GetDocumentAndSelectSpan(TTestWorkspace workspace, out
165165
document,
166166
diagnostic.Location.SourceSpan,
167167
[diagnostic],
168-
(a, d) => fixes.Add(new CodeFix(document.Project, a, d)),
168+
(a, d) => fixes.Add(new CodeFix(a, d)),
169169
CancellationToken.None);
170170

171171
await fixer.RegisterCodeFixesAsync(context);

0 commit comments

Comments
 (0)