コード例 #1
0
            private SuggestedActionSet?ConvertToSuggestedActionSet(UnifiedSuggestedActionSet?unifiedSuggestedActionSet, SuggestedActionsSourceProvider owner, ITextBuffer subjectBuffer)
            {
                // May be null in cases involving CodeFixSuggestedActions since FixAllFlavors may be null.
                if (unifiedSuggestedActionSet == null)
                {
                    return(null);
                }

                return(new SuggestedActionSet(
                           unifiedSuggestedActionSet.CategoryName,
                           unifiedSuggestedActionSet.Actions.SelectAsArray(set => ConvertToSuggestedAction(set)),
                           unifiedSuggestedActionSet.Title,
                           ConvertToSuggestedActionSetPriority(unifiedSuggestedActionSet.Priority),
                           unifiedSuggestedActionSet.ApplicableToSpan?.ToSpan()));

                // Local functions
                ISuggestedAction ConvertToSuggestedAction(IUnifiedSuggestedAction unifiedSuggestedAction)
                => unifiedSuggestedAction switch
                {
                    UnifiedCodeFixSuggestedAction codeFixAction => new CodeFixSuggestedAction(
                        ThreadingContext, owner, codeFixAction.Workspace, subjectBuffer,
                        codeFixAction.CodeFix, codeFixAction.Provider, codeFixAction.OriginalCodeAction,
                        ConvertToSuggestedActionSet(codeFixAction.FixAllFlavors, owner, subjectBuffer)),
                    UnifiedCodeRefactoringSuggestedAction codeRefactoringAction => new CodeRefactoringSuggestedAction(
                        ThreadingContext, owner, codeRefactoringAction.Workspace, subjectBuffer,
                        codeRefactoringAction.CodeRefactoringProvider, codeRefactoringAction.OriginalCodeAction),
                    UnifiedFixAllSuggestedAction fixAllAction => new FixAllSuggestedAction(
                        ThreadingContext, owner, fixAllAction.Workspace, subjectBuffer,
                        fixAllAction.FixAllState, fixAllAction.Diagnostic, fixAllAction.OriginalCodeAction),
                    UnifiedSuggestedActionWithNestedActions nestedAction => new SuggestedActionWithNestedActions(
                        ThreadingContext, owner, nestedAction.Workspace, subjectBuffer,
                        nestedAction.Provider ?? this, nestedAction.OriginalCodeAction,
                        nestedAction.NestedActionSets.SelectAsArray((s, arg) => ConvertToSuggestedActionSet(s, arg.owner, arg.subjectBuffer), (owner, subjectBuffer))),
                    _ => throw ExceptionUtilities.Unreachable
                };
コード例 #2
0
            private SuggestedActionSet?ConvertToSuggestedActionSet(UnifiedSuggestedActionSet?unifiedSuggestedActionSet)
            {
                // May be null in cases involving CodeFixSuggestedActions since FixAllFlavors may be null.
                if (unifiedSuggestedActionSet == null)
                {
                    return(null);
                }

                using var _ = ArrayBuilder <ISuggestedAction> .GetInstance(out var suggestedActions);

                foreach (var action in unifiedSuggestedActionSet.Actions)
                {
                    suggestedActions.Add(ConvertToSuggestedAction(action));
                }

                return(new SuggestedActionSet(
                           categoryName: unifiedSuggestedActionSet.CategoryName,
                           actions: suggestedActions,
                           title: unifiedSuggestedActionSet.Title,
                           priority: ConvertToSuggestedActionSetPriority(unifiedSuggestedActionSet.Priority),
                           applicableToSpan: unifiedSuggestedActionSet.ApplicableToSpan?.ToSpan()));

                // Local functions
                ISuggestedAction ConvertToSuggestedAction(IUnifiedSuggestedAction unifiedSuggestedAction)
                => unifiedSuggestedAction switch
                {
                    UnifiedCodeFixSuggestedAction codeFixAction => new CodeFixSuggestedAction(
                        ThreadingContext, _owner, codeFixAction.Workspace, _subjectBuffer,
                        codeFixAction.CodeFix, codeFixAction.Provider, codeFixAction.OriginalCodeAction,
                        ConvertToSuggestedActionSet(codeFixAction.FixAllFlavors)),
                    UnifiedCodeRefactoringSuggestedAction codeRefactoringAction => new CodeRefactoringSuggestedAction(
                        ThreadingContext, _owner, codeRefactoringAction.Workspace, _subjectBuffer,
                        codeRefactoringAction.CodeRefactoringProvider, codeRefactoringAction.OriginalCodeAction),
                    UnifiedFixAllSuggestedAction fixAllAction => new FixAllSuggestedAction(
                        ThreadingContext, _owner, fixAllAction.Workspace, _subjectBuffer,
                        fixAllAction.FixAllState, fixAllAction.Diagnostic, fixAllAction.OriginalCodeAction),
                    UnifiedSuggestedActionWithNestedActions nestedAction => new SuggestedActionWithNestedActions(
                        ThreadingContext, _owner, nestedAction.Workspace, _subjectBuffer,
                        nestedAction.Provider ?? this, nestedAction.OriginalCodeAction,
                        nestedAction.NestedActionSets.SelectAsArray(s => ConvertToSuggestedActionSet(s))),
                    _ => throw ExceptionUtilities.Unreachable
                };