Пример #1
0
            /// <summary>
            /// If the provided fix all context is non-null and the context's code action Id matches the given code action's Id then,
            /// returns the set of fix all occurrences actions associated with the code action.
            /// </summary>
            internal SuggestedActionSet GetFixAllSuggestedActionSet(
                CodeAction action,
                int actionCount,
                FixAllState fixAllState,
                ImmutableArray <FixAllScope> supportedScopes,
                Diagnostic firstDiagnostic,
                Workspace workspace)
            {
                if (fixAllState == null)
                {
                    return(null);
                }

                if (actionCount > 1 && action.EquivalenceKey == null)
                {
                    return(null);
                }

                var fixAllSuggestedActions = ArrayBuilder <FixAllSuggestedAction> .GetInstance();

                foreach (var scope in supportedScopes)
                {
                    var fixAllStateForScope   = fixAllState.WithScopeAndEquivalenceKey(scope, action.EquivalenceKey);
                    var fixAllSuggestedAction = new FixAllSuggestedAction(
                        _owner, workspace, _subjectBuffer, fixAllStateForScope,
                        firstDiagnostic, action);

                    fixAllSuggestedActions.Add(fixAllSuggestedAction);
                }

                return(new SuggestedActionSet(
                           fixAllSuggestedActions.ToImmutableAndFree(),
                           title: EditorFeaturesResources.Fix_all_occurrences_in));
            }
        static void AddFixMenuItem(TextEditor editor, CodeFixMenu menu, CodeFixMenu fixAllMenu, ref int mnemonic, CodeAction fix, FixAllState fixState, CancellationToken token)
        {
            if (fix is CodeAction.CodeActionWithNestedActions nested)
            {
                // Inline code actions if they are, otherwise add a nested fix menu
                if (nested.IsInlinable)
                {
                    int actionCount = nested.NestedCodeActions.Length;
                    foreach (var nestedFix in nested.NestedCodeActions)
                    {
                        var nestedFixState = actionCount > 1 && nestedFix.EquivalenceKey == null ? null : fixState;

                        AddFixMenuItem(editor, menu, fixAllMenu, ref mnemonic, nestedFix, nestedFixState, token);
                    }
                    return;
                }

                if (nested.NestedCodeActions.Length > 0)
                {
                    AddNestedFixMenu(editor, menu, fixAllMenu, nested, fixState, token);
                }
                return;
            }

            menu.Add(CreateFixMenuEntry(editor, fix, ref mnemonic));

            // TODO: Add support for more than doc when we have global undo.
            fixState = fixState?.WithScopeAndEquivalenceKey(FixAllScope.Document, fix.EquivalenceKey);
            var fixAllMenuEntry = CreateFixAllMenuEntry(editor, fixState, ref mnemonic, token);

            if (fixAllMenuEntry != null)
            {
                fixAllMenu.Add(fixAllMenuEntry);
            }
        }
Пример #3
0
        /// <summary>
        /// If the provided fix all context is non-null and the context's code action Id matches the given code action's Id then,
        /// returns the set of fix all occurrences actions associated with the code action.
        /// </summary>
        internal static SuggestedActionSet GetFixAllSuggestedActionSet(
            CodeAction action,
            int actionCount,
            FixAllState fixAllState,
            IEnumerable <FixAllScope> supportedScopes,
            Diagnostic firstDiagnostic,
            Workspace workspace,
            ITextBuffer subjectBuffer,
            ICodeActionEditHandlerService editHandler,
            IWaitIndicator waitIndicator,
            IAsynchronousOperationListener operationListener)
        {
            if (fixAllState == null)
            {
                return(null);
            }

            if (actionCount > 1 && action.EquivalenceKey == null)
            {
                return(null);
            }

            var fixAllSuggestedActions = ArrayBuilder <FixAllSuggestedAction> .GetInstance();

            foreach (var scope in supportedScopes)
            {
                var fixAllStateForScope   = fixAllState.WithScopeAndEquivalenceKey(scope, action.EquivalenceKey);
                var fixAllAction          = new FixAllCodeAction(fixAllStateForScope, showPreviewChangesDialog: true);
                var fixAllSuggestedAction = new FixAllSuggestedAction(
                    workspace, subjectBuffer, editHandler, waitIndicator, fixAllAction,
                    fixAllStateForScope.FixAllProvider, firstDiagnostic, operationListener);
                fixAllSuggestedActions.Add(fixAllSuggestedAction);
            }

            return(new SuggestedActionSet(
                       fixAllSuggestedActions.ToImmutableAndFree(),
                       title: EditorFeaturesResources.Fix_all_occurrences_in));
        }