private void AddCodeActions( Workspace workspace, IDictionary <CodeFixGroupKey, IList <SuggestedAction> > map, ArrayBuilder <CodeFixGroupKey> order, CodeFixCollection fixCollection, Func <CodeAction, SuggestedActionSet> getFixAllSuggestedActionSet, ImmutableArray <CodeFix> codeFixes) { foreach (var fix in codeFixes) { SuggestedAction suggestedAction; if (fix.Action.NestedCodeActions.Length > 0) { var nestedActions = fix.Action.NestedCodeActions.SelectAsArray( nestedAction => new CodeFixSuggestedAction( _owner, workspace, _subjectBuffer, fix, fixCollection.Provider, nestedAction, getFixAllSuggestedActionSet(nestedAction))); var set = new SuggestedActionSet( nestedActions, SuggestedActionSetPriority.Medium, fix.PrimaryDiagnostic.Location.SourceSpan.ToSpan()); suggestedAction = new SuggestedActionWithNestedActions( _owner, workspace, _subjectBuffer, fixCollection.Provider, fix.Action, set); } else { suggestedAction = new CodeFixSuggestedAction( _owner, workspace, _subjectBuffer, fix, fixCollection.Provider, fix.Action, getFixAllSuggestedActionSet(fix.Action)); } AddFix(fix, suggestedAction, map, order); } }
/// <summary> /// Groups fixes by the diagnostic being addressed by each fix. /// </summary> private void GroupFixes(Workspace workspace, IEnumerable <CodeFixCollection> fixCollections, IDictionary <Diagnostic, IList <SuggestedAction> > map, IList <Diagnostic> order, bool hasSuppressionFixes) { foreach (var fixCollection in fixCollections) { var fixes = fixCollection.Fixes; var fixCount = fixes.Length; foreach (var fix in fixes) { // Suppression fixes are handled below. if (!(fix.Action is SuppressionCodeAction)) { var fixAllSuggestedActionSet = CodeFixSuggestedAction.GetFixAllSuggestedActionSet(fix.Action, fixCount, fixCollection.FixAllContext, workspace, _subjectBuffer, _owner._editHandler); var suggestedAction = new CodeFixSuggestedAction(workspace, _subjectBuffer, _owner._editHandler, fix, fixCollection.Provider, fixAllSuggestedActionSet); AddFix(fix, suggestedAction, map, order); } } if (hasSuppressionFixes) { // Add suppression fixes to the end of a given SuggestedActionSet so that they always show up last in a group. foreach (var fix in fixes) { if (fix.Action is SuppressionCodeAction) { var suggestedAction = new SuppressionSuggestedAction(workspace, _subjectBuffer, _owner._editHandler, fix, fixCollection.Provider); AddFix(fix, suggestedAction, map, order); } } } } }
/// <summary> /// Groups fixes by the diagnostic being addressed by each fix. /// </summary> private void GroupFixes(Workspace workspace, IEnumerable <CodeFixCollection> fixCollections, IDictionary <Diagnostic, IList <SuggestedAction> > map, IList <Diagnostic> order, bool hasSuppressionFixes) { foreach (var fixCollection in fixCollections) { var fixes = fixCollection.Fixes; var fixCount = fixes.Length; Func <CodeAction, SuggestedActionSet> getFixAllSuggestedActionSet = codeAction => CodeFixSuggestedAction.GetFixAllSuggestedActionSet(codeAction, fixCount, fixCollection.FixAllContext, workspace, _subjectBuffer, _owner._editHandler); foreach (var fix in fixes) { // Suppression fixes are handled below. if (!(fix.Action is SuppressionCodeAction)) { SuggestedAction suggestedAction; if (fix.Action.HasCodeActions) { var nestedActions = new List <SuggestedAction>(); foreach (var nestedAction in fix.Action.GetCodeActions()) { nestedActions.Add(new CodeFixSuggestedAction(workspace, _subjectBuffer, _owner._editHandler, fix, nestedAction, fixCollection.Provider, getFixAllSuggestedActionSet(nestedAction))); } var diag = fix.Diagnostics[0]; var set = new SuggestedActionSet(nestedActions, SuggestedActionSetPriority.Medium, GetApplicableToSpan(diag)); suggestedAction = new SuggestedAction(workspace, _subjectBuffer, _owner._editHandler, fix.Action, fixCollection.Provider, new[] { set }); } else { suggestedAction = new CodeFixSuggestedAction(workspace, _subjectBuffer, _owner._editHandler, fix, fix.Action, fixCollection.Provider, getFixAllSuggestedActionSet(fix.Action)); } AddFix(fix, suggestedAction, map, order); } } if (hasSuppressionFixes) { // Add suppression fixes to the end of a given SuggestedActionSet so that they always show up last in a group. foreach (var fix in fixes) { if (fix.Action is SuppressionCodeAction) { SuggestedAction suggestedAction; if (fix.Action.HasCodeActions) { suggestedAction = new SuppressionSuggestedAction(workspace, _subjectBuffer, _owner._editHandler, fix, fixCollection.Provider, getFixAllSuggestedActionSet); } else { suggestedAction = new CodeFixSuggestedAction(workspace, _subjectBuffer, _owner._editHandler, fix, fix.Action, fixCollection.Provider, getFixAllSuggestedActionSet(fix.Action)); } AddFix(fix, suggestedAction, map, order); } } } } }
/// <summary> /// Groups fixes by the diagnostic being addressed by each fix. /// </summary> private void GroupFixes( Workspace workspace, IEnumerable <CodeFixCollection> fixCollections, IDictionary <CodeFixGroupKey, IList <SuggestedAction> > map, IList <CodeFixGroupKey> order, bool hasSuppressionFixes) { foreach (var fixCollection in fixCollections) { var fixes = fixCollection.Fixes; var fixCount = fixes.Length; Func <CodeAction, SuggestedActionSet> getFixAllSuggestedActionSet = codeAction => CodeFixSuggestedAction.GetFixAllSuggestedActionSet( codeAction, fixCount, fixCollection.FixAllState, fixCollection.SupportedScopes, fixCollection.FirstDiagnostic, workspace, _subjectBuffer, _owner._editHandler, _owner._waitIndicator, _owner._listener); foreach (var fix in fixes) { // Suppression fixes are handled below. if (!(fix.Action is SuppressionCodeAction)) { SuggestedAction suggestedAction; if (fix.Action.HasCodeActions) { var nestedActions = new List <SuggestedAction>(); foreach (var nestedAction in fix.Action.GetCodeActions()) { nestedActions.Add(new CodeFixSuggestedAction(workspace, _subjectBuffer, _owner._editHandler, _owner._waitIndicator, fix, nestedAction, fixCollection.Provider, getFixAllSuggestedActionSet(nestedAction), _owner._listener)); } var diag = fix.PrimaryDiagnostic; var set = new SuggestedActionSet(nestedActions, SuggestedActionSetPriority.Medium, diag.Location.SourceSpan.ToSpan()); suggestedAction = new SuggestedAction(workspace, _subjectBuffer, _owner._editHandler, _owner._waitIndicator, fix.Action, fixCollection.Provider, _owner._listener, new[] { set }); } else { suggestedAction = new CodeFixSuggestedAction( workspace, _subjectBuffer, _owner._editHandler, _owner._waitIndicator, fix, fix.Action, fixCollection.Provider, getFixAllSuggestedActionSet(fix.Action), _owner._listener); } AddFix(fix, suggestedAction, map, order); } } if (hasSuppressionFixes) { // Add suppression fixes to the end of a given SuggestedActionSet so that they always show up last in a group. foreach (var fix in fixes) { if (fix.Action is SuppressionCodeAction) { SuggestedAction suggestedAction; if (fix.Action.HasCodeActions) { suggestedAction = new SuppressionSuggestedAction( workspace, _subjectBuffer, _owner._editHandler, _owner._waitIndicator, fix, fixCollection.Provider, getFixAllSuggestedActionSet, _owner._listener); } else { suggestedAction = new CodeFixSuggestedAction( workspace, _subjectBuffer, _owner._editHandler, _owner._waitIndicator, fix, fix.Action, fixCollection.Provider, getFixAllSuggestedActionSet(fix.Action), _owner._listener); } AddFix(fix, suggestedAction, map, order); } } } } }