/// <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,
                ArrayBuilder <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);
                            }
                        }
                    }
                }
            }
Exemple #2
0
            /// <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))
                        {
                            var suggestedAction = new CodeFixSuggestedAction(workspace, _subjectBuffer, _owner._editHandler,
                                                                             fix, 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)
                            {
                                var suggestedAction = new SuppressionSuggestedAction(workspace, _subjectBuffer, _owner._editHandler,
                                                                                     fix, fixCollection.Provider, getFixAllSuggestedActionSet);

                                AddFix(fix, suggestedAction, map, order);
                            }
                        }
                    }
                }
            }