public FixMultipleCodeAction(
     IFixAllState fixAllState,
     string title,
     string computingFixWaitDialogMessage)
     : base(fixAllState, showPreviewChangesDialog: false)
 {
     _title = title;
     _computingFixWaitDialogMessage = computingFixWaitDialogMessage;
 }
 public UnifiedFixAllCodeRefactoringSuggestedAction(
     Workspace workspace,
     CodeAction codeAction,
     CodeActionPriority codeActionPriority,
     IFixAllState fixAllState)
     : base(workspace, codeAction, codeActionPriority)
 {
     FixAllState = fixAllState;
 }
 public FixAllCodeRefactoringSuggestedAction(
     IThreadingContext threadingContext,
     SuggestedActionsSourceProvider sourceProvider,
     Workspace workspace,
     ITextBuffer subjectBuffer,
     IFixAllState fixAllState,
     CodeAction originalCodeAction)
     : base(threadingContext, sourceProvider, workspace, subjectBuffer, fixAllState,
            originalCodeAction, new FixAllCodeRefactoringCodeAction(fixAllState))
 {
 }
Ejemplo n.º 4
0
 public UnifiedFixAllCodeFixSuggestedAction(
     Workspace workspace,
     CodeAction codeAction,
     CodeActionPriority codeActionPriority,
     IFixAllState fixAllState,
     Diagnostic diagnostic)
     : base(workspace, codeAction, codeActionPriority)
 {
     Diagnostic  = diagnostic;
     FixAllState = fixAllState;
 }
Ejemplo n.º 5
0
        protected override bool IsInternalProvider(IFixAllState fixAllState)
        {
            var exportAttributes = fixAllState.Provider.GetType().GetTypeInfo().GetCustomAttributes(typeof(ExportCodeFixProviderAttribute), false);

            if (exportAttributes?.Any() == true)
            {
                var exportAttribute = (ExportCodeFixProviderAttribute)exportAttributes.First();
                return(!string.IsNullOrEmpty(exportAttribute.Name) &&
                       s_predefinedCodeFixProviderNames.Contains(exportAttribute.Name));
            }

            return(false);
        }
Ejemplo n.º 6
0
 public FixAllCodeFixSuggestedAction(
     IThreadingContext threadingContext,
     SuggestedActionsSourceProvider sourceProvider,
     Workspace workspace,
     ITextBuffer subjectBuffer,
     IFixAllState fixAllState,
     Diagnostic diagnostic,
     CodeAction originalCodeAction)
     : base(threadingContext, sourceProvider, workspace, subjectBuffer, fixAllState,
            originalCodeAction, new FixAllCodeAction(fixAllState))
 {
     Diagnostic = diagnostic;
 }
Ejemplo n.º 7
0
        public static void LogState(IFixAllState fixAllState, bool isInternalProvider)
        {
            FunctionId functionId;
            string     providerKey;

            switch (fixAllState.FixAllKind)
            {
            case FixAllKind.CodeFix:
                functionId  = FunctionId.CodeFixes_FixAllOccurrencesContext;
                providerKey = CodeFixProvider;
                break;

            case FixAllKind.Refactoring:
                functionId  = FunctionId.Refactoring_FixAllOccurrencesContext;
                providerKey = CodeRefactoringProvider;
                break;

            default:
                throw ExceptionUtilities.UnexpectedValue(fixAllState.FixAllKind);
            }

            Logger.Log(functionId, KeyValueLogMessage.Create(m =>
            {
                m[CorrelationId] = fixAllState.CorrelationId;

                if (isInternalProvider)
                {
                    m[providerKey] = fixAllState.Provider.GetType().FullName !;
                    m[CodeActionEquivalenceKey] = fixAllState.CodeActionEquivalenceKey;
                    m[LanguageName]             = fixAllState.Project.Language;
                }
                else
                {
                    m[providerKey] = fixAllState.Provider.GetType().FullName !.GetHashCode().ToString();
                    m[CodeActionEquivalenceKey] = fixAllState.CodeActionEquivalenceKey?.GetHashCode().ToString();
                    m[LanguageName]             = fixAllState.Project.Language.GetHashCode().ToString();
                }

                m[FixAllScope] = fixAllState.Scope.ToString();
                switch (fixAllState.Scope)
                {
                case CodeFixes.FixAllScope.Project:
                    m[DocumentCount] = fixAllState.Project.DocumentIds.Count;
                    break;

                case CodeFixes.FixAllScope.Solution:
                    m[DocumentCount] = fixAllState.Solution.Projects.Sum(p => p.DocumentIds.Count);
                    break;
                }
            }));
        }
Ejemplo n.º 8
0
 protected AbstractFixAllSuggestedAction(
     IThreadingContext threadingContext,
     SuggestedActionsSourceProvider sourceProvider,
     Workspace workspace,
     ITextBuffer subjectBuffer,
     IFixAllState fixAllState,
     CodeAction originalCodeAction,
     AbstractFixAllCodeAction fixAllCodeAction)
     : base(threadingContext, sourceProvider, workspace, subjectBuffer,
            fixAllState.FixAllProvider, fixAllCodeAction)
 {
     OriginalCodeAction = originalCodeAction;
     FixAllState        = fixAllState;
 }
        private static async Task <ImmutableArray <CodeActionOperation> > GetFixAllOperationsAsync(
            CodeAction codeAction, bool showPreviewChangesDialog,
            IFixAllState fixAllState, CancellationToken cancellationToken)
        {
            // We have computed the fix all occurrences code fix.
            // Now fetch the new solution with applied fix and bring up the Preview changes dialog.

            var workspace = fixAllState.Project.Solution.Workspace;

            cancellationToken.ThrowIfCancellationRequested();
            var operations = await codeAction.GetOperationsAsync(cancellationToken).ConfigureAwait(false);

            if (operations == null)
            {
                return(ImmutableArray <CodeActionOperation> .Empty);
            }

            cancellationToken.ThrowIfCancellationRequested();
            var newSolution = await codeAction.GetChangedSolutionInternalAsync(cancellationToken : cancellationToken).ConfigureAwait(false);

            if (showPreviewChangesDialog)
            {
                newSolution = PreviewChanges(
                    fixAllState.Project.Solution,
                    newSolution,
                    FeaturesResources.Fix_all_occurrences,
                    codeAction.Title,
                    fixAllState.FixAllKind,
                    fixAllState.Project.Language,
                    workspace,
                    fixAllState.CorrelationId,
                    cancellationToken);
                if (newSolution == null)
                {
                    return(ImmutableArray <CodeActionOperation> .Empty);
                }
            }

            // Get a code action, with apply changes operation replaced with the newSolution.
            return(GetNewFixAllOperations(operations, newSolution, cancellationToken));
        }
Ejemplo n.º 10
0
 protected override IFixAllContext CreateFixAllContext(IFixAllState fixAllState, IProgressTracker progressTracker, CancellationToken cancellationToken)
 => new FixAllContext((FixAllState)fixAllState, progressTracker, cancellationToken);
Ejemplo n.º 11
0
 protected AbstractFixAllCodeFixCodeAction(
     IFixAllState fixAllState, bool showPreviewChangesDialog)
     : base(fixAllState, showPreviewChangesDialog)
 {
 }
 /// <summary>
 /// Creates a new <see cref="IFixAllContext"/> with the given parameters.
 /// </summary>
 protected abstract IFixAllContext CreateFixAllContext(IFixAllState fixAllState, IProgressTracker progressTracker, CancellationToken cancellationToken);
 /// <summary>
 /// Determine if the <see cref="IFixAllState.Provider"/> is an internal first-party provider or not.
 /// </summary>
 protected abstract bool IsInternalProvider(IFixAllState fixAllState);
 protected AbstractFixAllCodeAction(
     IFixAllState fixAllState, bool showPreviewChangesDialog)
 {
     FixAllState = fixAllState;
     _showPreviewChangesDialog = showPreviewChangesDialog;
 }
 public FixAllCodeAction(IFixAllState fixAllState)
     : base(fixAllState, showPreviewChangesDialog: true)
 {
 }
 protected override bool IsInternalProvider(IFixAllState fixAllState)
 => true;     // FixAll for refactorings is currently only supported for internal code refactoring providers.