diff --git a/src/EditorFeatures/Core/Implementation/CodeFixes/CodeFixService.cs b/src/EditorFeatures/Core/Implementation/CodeFixes/CodeFixService.cs index 425a7b4fa3b5940ac33a4dd25a0507fc06a3efbc..b3aa16a9e519d5f53a0cc30b4890d6af572eda85 100644 --- a/src/EditorFeatures/Core/Implementation/CodeFixes/CodeFixService.cs +++ b/src/EditorFeatures/Core/Implementation/CodeFixes/CodeFixService.cs @@ -301,7 +301,9 @@ public async Task> GetFixesAsync(Document documen } result = result ?? new List(); - var codeFix = new CodeFixCollection(fixer, span, fixes, fixAllProvider, fixAllContext, supportedScopes); + var codeFix = new CodeFixCollection( + fixer, span, fixes, fixAllProvider, fixAllContext, + supportedScopes, diagnostics.First()); result.Add(codeFix); } diff --git a/src/EditorFeatures/Core/Implementation/Suggestions/CodeFixSuggestedAction.cs b/src/EditorFeatures/Core/Implementation/Suggestions/CodeFixSuggestedAction.cs index 019527efbb77c85161d33707b84571cd81089cd8..29015a830f2342c18430d6e20c6db6dfad317e06 100644 --- a/src/EditorFeatures/Core/Implementation/Suggestions/CodeFixSuggestedAction.cs +++ b/src/EditorFeatures/Core/Implementation/Suggestions/CodeFixSuggestedAction.cs @@ -49,6 +49,7 @@ internal class CodeFixSuggestedAction : SuggestedActionWithFlavors, ITelemetryDi FixAllProvider fixAllProvider, FixAllCodeActionContext fixAllCodeActionContext, IEnumerable supportedScopes, + Diagnostic firstDiagnostic, Workspace workspace, ITextBuffer subjectBuffer, ICodeActionEditHandlerService editHandler, @@ -71,8 +72,8 @@ internal class CodeFixSuggestedAction : SuggestedActionWithFlavors, ITelemetryDi var fixAllContext = GetContextForScopeAndActionId(fixAllCodeActionContext, scope, action.EquivalenceKey); var fixAllAction = new FixAllCodeAction(fixAllContext, fixAllProvider, showPreviewChangesDialog: true); var fixAllSuggestedAction = new FixAllSuggestedAction( - workspace, subjectBuffer, editHandler, waitIndicator, fixAllAction, fixAllProvider, - fixAllCodeActionContext.OriginalDiagnostics.First(), operationListener); + workspace, subjectBuffer, editHandler, waitIndicator, fixAllAction, + fixAllProvider, firstDiagnostic, operationListener); fixAllSuggestedActions.Add(fixAllSuggestedAction); } diff --git a/src/EditorFeatures/Core/Implementation/Suggestions/SuggestedActionsSourceProvider.cs b/src/EditorFeatures/Core/Implementation/Suggestions/SuggestedActionsSourceProvider.cs index dded14631fa98975afeaa4f4b5baa487c516a1d8..9a91272527da7125430dadd519974cbb234bcc4d 100644 --- a/src/EditorFeatures/Core/Implementation/Suggestions/SuggestedActionsSourceProvider.cs +++ b/src/EditorFeatures/Core/Implementation/Suggestions/SuggestedActionsSourceProvider.cs @@ -285,7 +285,8 @@ private List FilterOnUIThread(List collect : applicableFixes.Count == collection.Fixes.Length ? collection : new CodeFixCollection(collection.Provider, collection.TextSpan, applicableFixes, - collection.FixAllProvider, collection.FixAllContext, collection.SupportedScopes); + collection.FixAllProvider, collection.FixAllContext, + collection.SupportedScopes, collection.FirstDiagnostic); } private bool IsApplicable(CodeAction action, Workspace workspace) @@ -349,8 +350,10 @@ private IEnumerable OrganizeFixes(Workspace workspace, IEnum Func getFixAllSuggestedActionSet = codeAction => CodeFixSuggestedAction.GetFixAllSuggestedActionSet( - codeAction, fixCount, fixCollection.FixAllProvider, fixCollection.FixAllContext, fixCollection.SupportedScopes, - workspace, _subjectBuffer, _owner._editHandler, _owner._waitIndicator, _owner._listener); + codeAction, fixCount, fixCollection.FixAllProvider, + fixCollection.FixAllContext, fixCollection.SupportedScopes, + fixCollection.FirstDiagnostic, workspace, _subjectBuffer, + _owner._editHandler, _owner._waitIndicator, _owner._listener); foreach (var fix in fixes) { diff --git a/src/EditorFeatures/Test/Diagnostics/AbstractUserDiagnosticTest.cs b/src/EditorFeatures/Test/Diagnostics/AbstractUserDiagnosticTest.cs index fadd00ed137473862a364d12cc7eb1359c7cc9c3..309a104bac172f3ce59ff07c73d77cb1a3baecd5 100644 --- a/src/EditorFeatures/Test/Diagnostics/AbstractUserDiagnosticTest.cs +++ b/src/EditorFeatures/Test/Diagnostics/AbstractUserDiagnosticTest.cs @@ -144,7 +144,7 @@ protected Document GetDocumentAndAnnotatedSpan(TestWorkspace workspace, out stri { var codeFix = new CodeFixCollection( fixer, diagnostic.Location.SourceSpan, fixes, - fixAllProvider: null, fixAllContext: null, supportedScopes: null); + fixAllProvider: null, fixAllContext: null, supportedScopes: null, firstDiagnostic: null); result.Add(Tuple.Create(diagnostic, codeFix)); } } @@ -165,7 +165,7 @@ protected Document GetDocumentAndAnnotatedSpan(TestWorkspace workspace, out stri var diagnosticSpan = diagnostic.Location.IsInSource ? diagnostic.Location.SourceSpan : default(TextSpan); var codeFix = new CodeFixCollection( fixAllProvider, diagnosticSpan, ImmutableArray.Create(new CodeFix(document.Project, fixAllFix, diagnostic)), - fixAllProvider: null, fixAllContext: null, supportedScopes: null); + fixAllProvider: null, fixAllContext: null, supportedScopes: null, firstDiagnostic: null); result.Add(Tuple.Create(diagnostic, codeFix)); } } diff --git a/src/EditorFeatures/Test2/Diagnostics/AbstractCrossLanguageUserDiagnosticTest.vb b/src/EditorFeatures/Test2/Diagnostics/AbstractCrossLanguageUserDiagnosticTest.vb index b77a175e8e8cca21792fa32663c4cdd91c2ce8fa..86cb5ddd5077c8d68e4a2bfad65b68076f3642f9 100644 --- a/src/EditorFeatures/Test2/Diagnostics/AbstractCrossLanguageUserDiagnosticTest.vb +++ b/src/EditorFeatures/Test2/Diagnostics/AbstractCrossLanguageUserDiagnosticTest.vb @@ -114,7 +114,8 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics If fixes.Any() Then result.Add(Tuple.Create(diagnostic, New CodeFixCollection( fixer, diagnostic.Location.SourceSpan, fixes, - fixAllProvider:=Nothing, fixAllContext:=Nothing, supportedScopes:=Nothing))) + fixAllProvider:=Nothing, fixAllContext:=Nothing, + supportedScopes:=Nothing, firstDiagnostic:=Nothing))) End If Next diff --git a/src/Features/Core/Portable/CodeFixes/CodeFixCollection.cs b/src/Features/Core/Portable/CodeFixes/CodeFixCollection.cs index 3d76fdd04ead311b9d15b6089a07a85441abce0e..60e5012c78c5f39f3e09badc8e2da9385bd4e852 100644 --- a/src/Features/Core/Portable/CodeFixes/CodeFixCollection.cs +++ b/src/Features/Core/Portable/CodeFixes/CodeFixCollection.cs @@ -23,6 +23,7 @@ internal class CodeFixCollection public FixAllProvider FixAllProvider { get; } public FixAllCodeActionContext FixAllContext { get; } public IEnumerable SupportedScopes { get; } + public Diagnostic FirstDiagnostic { get; } public CodeFixCollection( object provider, @@ -30,8 +31,9 @@ internal class CodeFixCollection IEnumerable fixes, FixAllProvider fixAllProvider, FixAllCodeActionContext fixAllContext, - IEnumerable supportedScopes) : - this(provider, span, fixes.ToImmutableArray(), fixAllProvider, fixAllContext, supportedScopes) + IEnumerable supportedScopes, + Diagnostic firstDiagnostic) : + this(provider, span, fixes.ToImmutableArray(), fixAllProvider, fixAllContext, supportedScopes, firstDiagnostic) { } @@ -41,7 +43,8 @@ internal class CodeFixCollection ImmutableArray fixes, FixAllProvider fixAllProvider, FixAllCodeActionContext fixAllContext, - IEnumerable supportedScopes) + IEnumerable supportedScopes, + Diagnostic firstDiagnostic) { this.Provider = provider; this.TextSpan = span; @@ -49,6 +52,7 @@ internal class CodeFixCollection this.FixAllProvider = fixAllProvider; this.FixAllContext = fixAllContext; this.SupportedScopes = supportedScopes; + this.FirstDiagnostic = firstDiagnostic; } } } diff --git a/src/Features/Core/Portable/CodeFixes/FixAllOccurrences/FixAllCodeActionContext.cs b/src/Features/Core/Portable/CodeFixes/FixAllOccurrences/FixAllCodeActionContext.cs index 0cffb71f82963c61257cd3ffb9e347c1609020d2..fc3e58e14a6b0020aa7dd432b018054c62c437c2 100644 --- a/src/Features/Core/Portable/CodeFixes/FixAllOccurrences/FixAllCodeActionContext.cs +++ b/src/Features/Core/Portable/CodeFixes/FixAllOccurrences/FixAllCodeActionContext.cs @@ -81,13 +81,13 @@ private static IEnumerable GetFixAllDiagnosticIds(FixAllProviderInfo fix .Select(d => d.Id); } +#if false + public IEnumerable OriginalDiagnostics { get { return _originalFixDiagnostics; } } -#if false - public FixAllProvider FixAllProvider { get { return _fixAllProviderInfo.FixAllProvider; }