Ejemplo n.º 1
0
        private FixAllState(
            FixAllProvider fixAllProvider,
            Document document,
            Project project,
            CodeFixProvider codeFixProvider,
            FixAllScope scope,
            string codeActionEquivalenceKey,
            IEnumerable <string> diagnosticIds,
            FixAllContext.DiagnosticProvider fixAllDiagnosticProvider)
        {
            Contract.ThrowIfNull(project);
            if (diagnosticIds == null)
            {
                throw new ArgumentNullException(nameof(diagnosticIds));
            }

            if (diagnosticIds.Any(d => d == null))
            {
                throw new ArgumentException(WorkspacesResources.Supplied_diagnostic_cannot_be_null, nameof(diagnosticIds));
            }

            this.FixAllProvider           = fixAllProvider;
            this.Document                 = document;
            this.Project                  = project;
            this.CodeFixProvider          = codeFixProvider ?? throw new ArgumentNullException(nameof(codeFixProvider));
            this.Scope                    = scope;
            this.CodeActionEquivalenceKey = codeActionEquivalenceKey;
            this.DiagnosticIds            = ImmutableHashSet.CreateRange(diagnosticIds);
            this.DiagnosticProvider       = fixAllDiagnosticProvider ?? throw new ArgumentNullException(nameof(fixAllDiagnosticProvider));
        }
        private async Task<CodeAction> GetFixAllCodeActionAsync(FixAllProvider fixAllProvider, FixAllContext fixAllContext)
        {
            using (Logger.LogBlock(FunctionId.CodeFixes_FixAllOccurrencesComputation, fixAllContext.CancellationToken))
            {
                CodeAction action = null;
                try
                {
                    action = await fixAllProvider.GetFixAsync(fixAllContext).ConfigureAwait(false);
                }
                catch (OperationCanceledException)
                {
                    FixAllLogger.LogComputationResult(completed: false);
                }
                finally
                {
                    if (action != null)
                    {
                        FixAllLogger.LogComputationResult(completed: true);
                    }
                    else
                    {
                        FixAllLogger.LogComputationResult(completed: false, timedOut: true);
                    }
                }

                return action;
            }
        }
Ejemplo n.º 3
0
 private FixAllProviderInfo(
     FixAllProvider fixAllProvider,
     ImmutableArray <FixAllScope> supportedScopes)
 {
     FixAllProvider  = fixAllProvider;
     SupportedScopes = supportedScopes;
 }
Ejemplo n.º 4
0
 private FixAllProviderInfo(
     FixAllProvider fixAllProvider,
     IEnumerable<FixAllScope> supportedScopes)
 {
     this.FixAllProvider = fixAllProvider;
     this.SupportedScopes = supportedScopes;
 }
Ejemplo n.º 5
0
 private FixAllProviderInfo(
     FixAllProvider fixAllProvider,
     IEnumerable <FixAllScope> supportedScopes)
 {
     this.FixAllProvider  = fixAllProvider;
     this.SupportedScopes = supportedScopes;
 }
Ejemplo n.º 6
0
        private FixAllState(
            FixAllProvider fixAllProvider,
            Document document,
            Project project,
            CodeFixProvider codeFixProvider,
            FixAllScope scope,
            string codeActionEquivalenceKey,
            IEnumerable<string> diagnosticIds,
            FixAllContext.DiagnosticProvider fixAllDiagnosticProvider)
        {
            Contract.ThrowIfNull(project);
            if (diagnosticIds == null)
            {
                throw new ArgumentNullException(nameof(diagnosticIds));
            }

            if (diagnosticIds.Any(d => d == null))
            {
                throw new ArgumentException(WorkspacesResources.Supplied_diagnostic_cannot_be_null, nameof(diagnosticIds));
            }

            this.FixAllProvider = fixAllProvider;
            this.Document = document;
            this.Project = project;
            this.CodeFixProvider = codeFixProvider ?? throw new ArgumentNullException(nameof(codeFixProvider));
            this.Scope = scope;
            this.CodeActionEquivalenceKey = codeActionEquivalenceKey;
            this.DiagnosticIds = ImmutableHashSet.CreateRange(diagnosticIds);
            this.DiagnosticProvider = fixAllDiagnosticProvider ?? throw new ArgumentNullException(nameof(fixAllDiagnosticProvider));
        }
Ejemplo n.º 7
0
 private FixAllProviderInfo(
     FixAllProvider fixAllProvider,
     ImmutableArray<FixAllScope> supportedScopes)
 {
     FixAllProvider = fixAllProvider;
     SupportedScopes = supportedScopes;
 }
Ejemplo n.º 8
0
 public SuppressionFixerFixAllProviderInfo(
     FixAllProvider fixAllProvider,
     ISuppressionFixProvider suppressionFixer,
     ImmutableArray <FixAllScope> supportedScopes)
     : base(fixAllProvider, supportedScopes)
 {
     _canBeSuppressedOrUnsuppressed = suppressionFixer.CanBeSuppressedOrUnsuppressed;
 }
Ejemplo n.º 9
0
 public SuppressionFixerFixAllProviderInfo(
     FixAllProvider fixAllProvider,
     ISuppressionFixProvider suppressionFixer,
     IEnumerable <FixAllScope> supportedScopes)
     : base(fixAllProvider, supportedScopes)
 {
     this._canBeSuppressedOrTriaged = suppressionFixer.CanBeSuppressed;
 }
Ejemplo n.º 10
0
 public SuppressionFixerFixAllProviderInfo(
     FixAllProvider fixAllProvider,
     IConfigurationFixProvider suppressionFixer,
     ImmutableArray <FixAllScope> supportedScopes)
     : base(fixAllProvider, supportedScopes)
 {
     _canBeSuppressedOrUnsuppressed = suppressionFixer.IsFixableDiagnostic;
 }
Ejemplo n.º 11
0
 public CodeFixerFixAllProviderInfo(
     FixAllProvider fixAllProvider,
     IEnumerable <string> supportedDiagnosticIds,
     IEnumerable <FixAllScope> supportedScopes)
     : base(fixAllProvider, supportedScopes)
 {
     this._supportedDiagnosticIds = supportedDiagnosticIds;
 }
Ejemplo n.º 12
0
 private FixAllProviderInfo(
     FixAllProvider fixAllProvider,
     IEnumerable <string> supportedDiagnosticIds,
     IEnumerable <FixAllScope> supportedScopes)
 {
     this.FixAllProvider         = fixAllProvider;
     this.SupportedDiagnosticIds = supportedDiagnosticIds;
     this.SupportedScopes        = supportedScopes;
 }
Ejemplo n.º 13
0
 private FixAllProviderInfo(
     FixAllProvider fixAllProvider,
     IEnumerable<string> supportedDiagnosticIds,
     IEnumerable<FixAllScope> supportedScopes)
 {
     this.FixAllProvider = fixAllProvider;
     this.SupportedDiagnosticIds = supportedDiagnosticIds;
     this.SupportedScopes = supportedScopes;
 }
        public async Task<IEnumerable<CodeActionOperation>> GetFixAllOperationsAsync(FixAllProvider fixAllProvider, FixAllContext fixAllContext, bool showPreviewChangesDialog)
        {
            var codeAction = await GetFixAllCodeActionAsync(fixAllProvider, fixAllContext).ConfigureAwait(false);
            if (codeAction == null)
            {
                return null;
            }

            return await GetFixAllOperationsAsync(codeAction, fixAllContext, showPreviewChangesDialog).ConfigureAwait(false);
        }
        public async Task<Solution> GetFixAllChangedSolutionAsync(FixAllProvider fixAllProvider, FixAllContext fixAllContext)
        {
            var codeAction = await GetFixAllCodeActionAsync(fixAllProvider, fixAllContext).ConfigureAwait(false);
            if (codeAction == null)
            {
                return fixAllContext.Solution;
            }

            fixAllContext.CancellationToken.ThrowIfCancellationRequested();
            return await codeAction.GetChangedSolutionInternalAsync(cancellationToken: fixAllContext.CancellationToken).ConfigureAwait(false);
        }
Ejemplo n.º 16
0
 public CodeFixCollection(
     object provider,
     TextSpan span,
     IEnumerable <CodeFix> fixes,
     FixAllProvider fixAllProvider,
     FixAllContext fixAllContext,
     IEnumerable <FixAllScope> supportedScopes,
     Diagnostic firstDiagnostic) :
     this(provider, span, fixes.ToImmutableArray(), fixAllProvider, fixAllContext, supportedScopes, firstDiagnostic)
 {
 }
Ejemplo n.º 17
0
 private FixMultipleSuggestedAction GetSuggestedAction(
     FixMultipleContext fixMultipleContext,
     Workspace workspace,
     FixAllProvider fixAllProvider,
     string title,
     string waitDialogMessage,
     bool showPreviewChangesDialog,
     CancellationToken cancellationToken)
 {
     var fixMultipleCodeAction = new FixMultipleCodeAction(fixMultipleContext, fixAllProvider, title, waitDialogMessage, showPreviewChangesDialog);
     return new FixMultipleSuggestedAction(_listener, workspace, _editHandler, _waitIndicator, fixMultipleCodeAction, fixAllProvider);
 }
Ejemplo n.º 18
0
        internal FixMultipleSuggestedAction(
            Workspace workspace,
            ICodeActionEditHandlerService editHandler,
            FixMultipleCodeAction codeAction,
            FixAllProvider provider,
            ITextBuffer subjectBufferOpt = null)
            : base(workspace, subjectBufferOpt, editHandler, codeAction, provider, originalFixedDiagnostic: codeAction.GetTriggerDiagnostic())
        {
            _triggerDocumentOpt = codeAction.FixAllContext.Document;

            _telemetryId = GetTelemetryId(codeAction.FixAllContext.DiagnosticIds);
        }
 private CodeFixEquivalenceGroup(
     string equivalenceKey,
     Solution solution,
     FixAllProvider fixAllProvider,
     CodeFixProvider codeFixProvider,
     ImmutableArray<Diagnostic> diagnosticsToFix)
 {
     this.CodeFixEquivalenceKey = equivalenceKey;
     this.Solution = solution;
     this.FixAllProvider = fixAllProvider;
     this.CodeFixProvider = codeFixProvider;
     this.DiagnosticsToFix = diagnosticsToFix;
 }
Ejemplo n.º 20
0
        public async Task<IEnumerable<CodeActionOperation>> GetFixAllOperationsAsync(FixAllProvider fixAllProvider, FixAllContext fixAllContext, string fixAllTitle, string waitDialogMessage, bool showPreviewChangesDialog)
        {
            // Compute fix all occurrences code fix for the given fix all context.
            // Bring up a cancellable wait dialog.
            bool userCancelled;
            var codeAction = GetFixAllCodeAction(fixAllProvider, fixAllContext, fixAllTitle, waitDialogMessage, out userCancelled);
            if (codeAction == null)
            {
                return null;
            }

            return await GetFixAllOperationsAsync(codeAction, fixAllContext, fixAllTitle, showPreviewChangesDialog).ConfigureAwait(false);
        }
Ejemplo n.º 21
0
 private void ComputeAndApplyFix(
     FixMultipleContext fixMultipleContext,
     Workspace workspace,
     FixAllProvider fixAllProvider,
     string waitDialogAndPreviewChangesTitle,
     string waitDialogMessage,
     bool showPreviewChangesDialog,
     CancellationToken cancellationToken)
 {
     var fixMultipleCodeAction = new FixMultipleCodeAction(fixMultipleContext, fixAllProvider, title: waitDialogAndPreviewChangesTitle, previewChangesDialogTitle: waitDialogAndPreviewChangesTitle, computingFixWaitDialogMessage: waitDialogMessage, showPreviewChangesDialog: showPreviewChangesDialog);
     var fixMultipleSuggestedAction = new FixMultipleSuggestedAction(workspace, _editHandler, fixMultipleCodeAction, fixAllProvider);
     fixMultipleSuggestedAction.Invoke(cancellationToken);
 }
Ejemplo n.º 22
0
        public async Task<Solution> GetFixAllChangedSolutionAsync(FixAllProvider fixAllProvider, FixAllContext fixAllContext, string fixAllTitle, string waitDialogMessage)
        {
            // Compute fix all occurrences code fix for the given fix all context.
            // Bring up a cancellable wait dialog.
            bool userCancelled;
            var codeAction = GetFixAllCodeAction(fixAllProvider, fixAllContext, fixAllTitle, waitDialogMessage, out userCancelled);
            if (codeAction == null)
            {
                return userCancelled ? null : fixAllContext.Solution;
            }

            fixAllContext.CancellationToken.ThrowIfCancellationRequested();
            return await codeAction.GetChangedSolutionInternalAsync(cancellationToken: fixAllContext.CancellationToken).ConfigureAwait(false);
        }
Ejemplo n.º 23
0
 public void ComputeAndApplyFix(
     ImmutableDictionary<Project, ImmutableArray<Diagnostic>> diagnosticsToFix,
     Workspace workspace,
     CodeFixProvider fixProvider,
     FixAllProvider fixAllProvider,
     string equivalenceKey,
     string waitDialogAndPreviewChangesTitle,
     string waitDialogMessage,
     bool showPreviewChangesDialog,
     CancellationToken cancellationToken)
 {
     var fixMultipleContext = FixMultipleContext.Create(diagnosticsToFix, fixProvider, equivalenceKey, cancellationToken);
     ComputeAndApplyFix(fixMultipleContext, workspace, fixAllProvider, waitDialogAndPreviewChangesTitle, waitDialogMessage, showPreviewChangesDialog, cancellationToken);
 }
Ejemplo n.º 24
0
 public Solution GetFix(
     ImmutableDictionary<Project, ImmutableArray<Diagnostic>> diagnosticsToFix,
     Workspace workspace,
     CodeFixProvider fixProvider,
     FixAllProvider fixAllProvider,
     string equivalenceKey,
     string waitDialogTitle,
     string waitDialogMessage,
     CancellationToken cancellationToken)
 {
     var fixMultipleContext = FixMultipleContext.Create(diagnosticsToFix, fixProvider, equivalenceKey, cancellationToken);
     var suggestedAction = GetSuggestedAction(fixMultipleContext, workspace, fixAllProvider, waitDialogTitle, waitDialogMessage, showPreviewChangesDialog: false, cancellationToken: cancellationToken);
     return suggestedAction.GetChangedSolution(cancellationToken);
 }
Ejemplo n.º 25
0
        internal FixMultipleSuggestedAction(
            IAsynchronousOperationListener operationListener,
            Workspace workspace,
            ICodeActionEditHandlerService editHandler,
            IWaitIndicator waitIndicator,
            FixMultipleCodeAction codeAction,
            FixAllProvider provider,
            ITextBuffer subjectBufferOpt = null)
            : base(workspace, subjectBufferOpt, editHandler, waitIndicator, codeAction, provider, originalFixedDiagnostic: codeAction.GetTriggerDiagnostic(), operationListener: operationListener)
        {
            _triggerDocumentOpt = codeAction.FixAllState.Document;

            _telemetryId = GetTelemetryId(codeAction.FixAllState.DiagnosticIds);
        }
Ejemplo n.º 26
0
        private CodeAction GetFixAllCodeAction(FixAllProvider fixAllProvider, FixAllContext fixAllContext, string fixAllTitle, string waitDialogMessage, out bool userCancelled)
        {
            userCancelled = false;

            // Compute fix all occurrences code fix for the given fix all context.
            // Bring up a cancellable wait dialog.
            CodeAction codeAction = null;

            using (Logger.LogBlock(FunctionId.CodeFixes_FixAllOccurrencesComputation, fixAllContext.CancellationToken))
            {
                var result = _waitIndicator.Wait(
                    fixAllTitle,
                    waitDialogMessage,
                    allowCancel: true,
                    action: waitContext =>
                    {
                        fixAllContext.CancellationToken.ThrowIfCancellationRequested();
                        using (var linkedCts =
                            CancellationTokenSource.CreateLinkedTokenSource(waitContext.CancellationToken, fixAllContext.CancellationToken))
                        {
                            try
                            {
                                var fixAllContextWithCancellation = fixAllContext.WithCancellationToken(linkedCts.Token);
                                var fixTask = fixAllProvider.GetFixAsync(fixAllContextWithCancellation);
                                if (fixTask != null)
                                {
                                    codeAction = fixTask.WaitAndGetResult(linkedCts.Token);
                                }
                            }
                            catch (OperationCanceledException)
                            {
                                fixAllContext.CancellationToken.ThrowIfCancellationRequested();
                            }
                        }
                    });

                userCancelled = result == WaitIndicatorResult.Canceled;
                var cancelled = userCancelled || codeAction == null;

                if (cancelled)
                {
                    FixAllLogger.LogComputationResult(completed: false, timedOut: result != WaitIndicatorResult.Canceled);
                    return null;
                }
            }

            FixAllLogger.LogComputationResult(completed: true);
            return codeAction;
        }
Ejemplo n.º 27
0
 internal FixAllState(
     FixAllProvider fixAllProvider,
     Project project,
     CodeFixProvider codeFixProvider,
     FixAllScope scope,
     string codeActionEquivalenceKey,
     IEnumerable <string> diagnosticIds,
     FixAllContext.DiagnosticProvider fixAllDiagnosticProvider)
     : this(fixAllProvider, null, project, codeFixProvider, scope, codeActionEquivalenceKey, diagnosticIds, fixAllDiagnosticProvider)
 {
     if (project == null)
     {
         throw new ArgumentNullException(nameof(project));
     }
 }
Ejemplo n.º 28
0
 internal static FixAllState Create(
     FixAllProvider fixAllProvider,
     ImmutableDictionary<Project, ImmutableArray<Diagnostic>> diagnosticsToFix,
     CodeFixProvider codeFixProvider,
     string codeActionEquivalenceKey)
 {
     var triggerProject = diagnosticsToFix.First().Key;
     var diagnosticIds = GetDiagnosticsIds(diagnosticsToFix.Values);
     var diagnosticProvider = new FixMultipleDiagnosticProvider(diagnosticsToFix);
     return new FixAllState(
         fixAllProvider,
         triggerProject, codeFixProvider,
         FixAllScope.Custom, codeActionEquivalenceKey,
         diagnosticIds, diagnosticProvider);
 }
Ejemplo n.º 29
0
 internal FixAllState(
     FixAllProvider fixAllProvider,
     Project project,
     CodeFixProvider codeFixProvider,
     FixAllScope scope,
     string codeActionEquivalenceKey,
     IEnumerable<string> diagnosticIds,
     FixAllContext.DiagnosticProvider fixAllDiagnosticProvider)
     : this(fixAllProvider, null, project, codeFixProvider, scope, codeActionEquivalenceKey, diagnosticIds, fixAllDiagnosticProvider)
 {
     if (project == null)
     {
         throw new ArgumentNullException(nameof(project));
     }
 }
 public void ComputeAndApplyFix(
     ImmutableDictionary<Document, ImmutableArray<Diagnostic>> diagnosticsToFix,
     Workspace workspace,
     CodeFixProvider fixProvider,
     FixAllProvider fixAllProvider,
     string equivalenceKey,
     string title,
     string waitDialogMessage,
     bool showPreviewChangesDialog,
     CancellationToken cancellationToken)
 {
     var fixMultipleContext = FixMultipleContext.Create(diagnosticsToFix, fixProvider, equivalenceKey, cancellationToken);
     var suggestedAction = GetSuggestedAction(fixMultipleContext, workspace, fixAllProvider, title, waitDialogMessage, showPreviewChangesDialog, cancellationToken);
     suggestedAction.Invoke(cancellationToken);
 }
Ejemplo n.º 31
0
        private async Task <List <CodeFixCollection> > AppendFixesOrSuppressionsAsync(
            Document document,
            TextSpan span,
            IEnumerable <DiagnosticData> diagnosticsWithSameSpan,
            List <CodeFixCollection> result,
            object fixer,
            Func <Diagnostic, bool> hasFix,
            Func <ImmutableArray <Diagnostic>, Task <IEnumerable <CodeFix> > > getFixes,
            CancellationToken cancellationToken)
        {
            var diagnostics = (await diagnosticsWithSameSpan.OrderByDescending(d => d.Severity).ToDiagnosticsAsync(document.Project, cancellationToken).ConfigureAwait(false)).Where(d => hasFix(d)).ToImmutableArray();

            if (diagnostics.Length <= 0)
            {
                // this can happen for suppression case where all diagnostics can't be suppressed
                return(result);
            }

            var extensionManager = document.Project.Solution.Workspace.Services.GetService <IExtensionManager>();
            var fixes            = await extensionManager.PerformFunctionAsync(fixer, () => getFixes(diagnostics), defaultValue : SpecializedCollections.EmptyEnumerable <CodeFix>()).ConfigureAwait(false);

            if (fixes != null && fixes.Any())
            {
                // If the fix provider supports fix all occurrences, then get the corresponding FixAllProviderInfo and fix all context.
                var fixAllProviderInfo = extensionManager.PerformFunction(fixer, () => ImmutableInterlocked.GetOrAdd(ref _fixAllProviderMap, fixer, FixAllProviderInfo.Create), defaultValue: null);

                FixAllProvider            fixAllProvider  = null;
                FixAllContext             fixAllContext   = null;
                IEnumerable <FixAllScope> supportedScopes = null;
                if (fixAllProviderInfo != null)
                {
                    var codeFixProvider = (fixer as CodeFixProvider) ?? new WrapperCodeFixProvider((ISuppressionFixProvider)fixer, diagnostics.Select(d => d.Id));
                    fixAllProvider = fixAllProviderInfo.FixAllProvider;
                    fixAllContext  = FixAllContext.Create(
                        document, fixAllProviderInfo, codeFixProvider, diagnostics,
                        this.GetDocumentDiagnosticsAsync, this.GetProjectDiagnosticsAsync, cancellationToken);
                    supportedScopes = fixAllProviderInfo.SupportedScopes;
                }

                result = result ?? new List <CodeFixCollection>();
                var codeFix = new CodeFixCollection(
                    fixer, span, fixes, fixAllProvider, fixAllContext,
                    supportedScopes, diagnostics.First());
                result.Add(codeFix);
            }

            return(result);
        }
        public Solution GetFix(
            ImmutableDictionary<Document, ImmutableArray<Diagnostic>> diagnosticsToFix,
            Workspace workspace,
            CodeFixProvider fixProvider,
            FixAllProvider fixAllProvider,
            string equivalenceKey,
            string waitDialogTitle,
            string waitDialogMessage,
            CancellationToken cancellationToken)
        {
            var fixMultipleState = FixAllState.Create(fixAllProvider, diagnosticsToFix, fixProvider, equivalenceKey);
            var triggerDiagnostic = diagnosticsToFix.First().Value.First();

            var suggestedAction = GetSuggestedAction(fixMultipleState, triggerDiagnostic, workspace, waitDialogTitle, waitDialogMessage, showPreviewChangesDialog: false, cancellationToken: cancellationToken);
            return suggestedAction.GetChangedSolution(cancellationToken);
        }
Ejemplo n.º 33
0
        public async Task<IEnumerable<CodeActionOperation>> GetFixAllOperationsAsync(FixAllProvider fixAllProvider, FixAllContext fixAllContext)
        {
            // Compute fix all occurrences code fix for the given fix all context.
            // Bring up a cancellable wait dialog.
            CodeAction codeAction = null;

            using (Logger.LogBlock(FunctionId.CodeFixes_FixAllOccurrencesComputation, fixAllContext.CancellationToken))
            {
                var result = _waitIndicator.Wait(
                    EditorFeaturesResources.FixAllOccurrences,
                    EditorFeaturesResources.ComputingFixAllOccurrences,
                    allowCancel: true,
                    action: waitContext =>
                    {
                        fixAllContext.CancellationToken.ThrowIfCancellationRequested();
                        using (var linkedCts =
                            CancellationTokenSource.CreateLinkedTokenSource(waitContext.CancellationToken, fixAllContext.CancellationToken))
                        {
                            try
                            {
                                var fixAllContextWithCancellation = fixAllContext.WithCancellationToken(linkedCts.Token);
                                var fixTask = fixAllProvider.GetFixAsync(fixAllContextWithCancellation);
                                if (fixTask != null)
                                {
                                    codeAction = fixTask.WaitAndGetResult(linkedCts.Token);
                                }
                            }
                            catch (OperationCanceledException)
                            {
                                fixAllContext.CancellationToken.ThrowIfCancellationRequested();
                            }
                        }
                    });

                var cancelled = result == WaitIndicatorResult.Canceled || codeAction == null;

                if (cancelled)
                {
                    FixAllLogger.LogComputationResult(completed: false, timedOut: result != WaitIndicatorResult.Canceled);
                    return null;
                }
            }

            FixAllLogger.LogComputationResult(completed: true);
            return await GetFixAllOperationsAsync(codeAction, fixAllContext).ConfigureAwait(false);
        }
Ejemplo n.º 34
0
 public CodeFixCollection(
     object provider,
     TextSpan span,
     ImmutableArray <CodeFix> fixes,
     FixAllProvider fixAllProvider,
     FixAllContext fixAllContext,
     IEnumerable <FixAllScope> supportedScopes,
     Diagnostic firstDiagnostic)
 {
     this.Provider        = provider;
     this.TextSpan        = span;
     this.Fixes           = fixes;
     this.FixAllProvider  = fixAllProvider;
     this.FixAllContext   = fixAllContext;
     this.SupportedScopes = supportedScopes;
     this.FirstDiagnostic = firstDiagnostic;
 }
 private CodeFixEquivalenceGroup(
     string equivalenceKey,
     Solution solution,
     FixAllProvider fixAllProvider,
     CodeFixProvider codeFixProvider,
     ImmutableDictionary<ProjectId, ImmutableDictionary<string, ImmutableArray<Diagnostic>>> documentDiagnosticsToFix,
     ImmutableDictionary<ProjectId, ImmutableArray<Diagnostic>> projectDiagnosticsToFix)
 {
     this.CodeFixEquivalenceKey = equivalenceKey;
     this.Solution = solution;
     this.FixAllProvider = fixAllProvider;
     this.CodeFixProvider = codeFixProvider;
     this.DocumentDiagnosticsToFix = documentDiagnosticsToFix;
     this.ProjectDiagnosticsToFix = projectDiagnosticsToFix;
     this.NumberOfDiagnostics = documentDiagnosticsToFix.SelectMany(x => x.Value.Select(y => y.Value).SelectMany(y => y)).Count()
         + projectDiagnosticsToFix.SelectMany(x => x.Value).Count();
 }
        public Solution GetFix(
            ImmutableDictionary<Project, ImmutableArray<Diagnostic>> diagnosticsToFix,
            Workspace workspace,
            CodeFixProvider fixProvider,
            FixAllProvider fixAllProvider,
            string equivalenceKey,
            string waitDialogTitle,
            string waitDialogMessage,
            CancellationToken cancellationToken)
        {
            var fixMultipleState = FixAllState.Create(
                fixAllProvider, diagnosticsToFix, fixProvider, equivalenceKey);

            return GetFixedSolution(
                fixMultipleState, workspace, waitDialogTitle, 
                waitDialogMessage, cancellationToken);
        }
Ejemplo n.º 37
0
        public Solution GetFix(
            ImmutableDictionary<Document, ImmutableArray<Diagnostic>> diagnosticsToFix,
            Workspace workspace,
            CodeFixProvider fixProvider,
            FixAllProvider fixAllProvider,
            string equivalenceKey,
            string waitDialogTitle,
            string waitDialogMessage,
            CancellationToken cancellationToken)
        {
            var fixMultipleState = FixAllState.Create(fixAllProvider, diagnosticsToFix, fixProvider, equivalenceKey);
            var triggerDiagnostic = diagnosticsToFix.First().Value.First();

            var result = GetFixedSolution(
                fixMultipleState, triggerDiagnostic, workspace,
                waitDialogTitle, waitDialogMessage, cancellationToken);
            return result;
        }
Ejemplo n.º 38
0
        internal static FixAllState Create(
            FixAllProvider fixAllProvider,
            Project project,
            FixAllProviderInfo fixAllProviderInfo,
            CodeFixProvider originalFixProvider,
            IEnumerable <Diagnostic> originalFixDiagnostics,
            Func <Document, ImmutableHashSet <string>, CancellationToken, Task <IEnumerable <Diagnostic> > > getDocumentDiagnosticsAsync,
            Func <Project, bool, ImmutableHashSet <string>, CancellationToken, Task <IEnumerable <Diagnostic> > > getProjectDiagnosticsAsync)
        {
            var diagnosticIds      = GetFixAllDiagnosticIds(fixAllProviderInfo, originalFixDiagnostics).ToImmutableHashSet();
            var diagnosticProvider = new FixAllDiagnosticProvider(diagnosticIds, getDocumentDiagnosticsAsync, getProjectDiagnosticsAsync);

            return(new FixAllState(
                       fixAllProvider: fixAllProvider,
                       project: project,
                       codeFixProvider: originalFixProvider,
                       scope: FixAllScope.Project,
                       codeActionEquivalenceKey: null, diagnosticIds: diagnosticIds,
                       fixAllDiagnosticProvider: diagnosticProvider));
        }
Ejemplo n.º 39
0
        internal FixAllState CreateFixAllState(
            FixAllProvider fixAllProvider,
            Document document,
            FixAllProviderInfo fixAllProviderInfo,
            CodeFixProvider originalFixProvider,
            IEnumerable <Diagnostic> originalFixDiagnostics,
            Func <Document, ImmutableHashSet <string>, CancellationToken, Task <IEnumerable <Diagnostic> > > getDocumentDiagnosticsAsync,
            Func <Project, bool, ImmutableHashSet <string>, CancellationToken, Task <IEnumerable <Diagnostic> > > getProjectDiagnosticsAsync)
        {
            var diagnosticIds = originalFixDiagnostics.Where(fixAllProviderInfo.CanBeFixed)
                                .Select(d => d.Id)
                                .ToImmutableHashSet();
            var diagnosticProvider = new FixAllDiagnosticProvider(this, diagnosticIds);

            return(new FixAllState(
                       fixAllProvider: fixAllProvider,
                       document: document,
                       codeFixProvider: originalFixProvider,
                       scope: FixAllScope.Document,
                       codeActionEquivalenceKey: null,
                       diagnosticIds: diagnosticIds,
                       fixAllDiagnosticProvider: diagnosticProvider));
        }
Ejemplo n.º 40
0
 internal FixAllCodeAction(FixAllContext fixAllContext, FixAllProvider fixAllProvider)
 {
     _fixAllContext = fixAllContext;
     _fixAllProvider = fixAllProvider;
 }
Ejemplo n.º 41
0
 internal static FixAllState Create(
     FixAllProvider fixAllProvider,
     Project project,
     FixAllProviderInfo fixAllProviderInfo,
     CodeFixProvider originalFixProvider,
     IEnumerable<Diagnostic> originalFixDiagnostics,
     Func<Document, ImmutableHashSet<string>, CancellationToken, Task<IEnumerable<Diagnostic>>> getDocumentDiagnosticsAsync,
     Func<Project, bool, ImmutableHashSet<string>, CancellationToken, Task<IEnumerable<Diagnostic>>> getProjectDiagnosticsAsync)
 {
     var diagnosticIds = GetFixAllDiagnosticIds(fixAllProviderInfo, originalFixDiagnostics).ToImmutableHashSet();
     var diagnosticProvider = new FixAllDiagnosticProvider(diagnosticIds, getDocumentDiagnosticsAsync, getProjectDiagnosticsAsync);
     return new FixAllState(
         fixAllProvider: fixAllProvider,
         project: project,
         codeFixProvider: originalFixProvider,
         scope: FixAllScope.Project,
         codeActionEquivalenceKey: null, diagnosticIds: diagnosticIds,
         fixAllDiagnosticProvider: diagnosticProvider);
 }
Ejemplo n.º 42
0
 internal static FixAllState Create(
     FixAllProvider fixAllProvider,
     ImmutableDictionary<Project, ImmutableArray<Diagnostic>> diagnosticsToFix,
     CodeFixProvider codeFixProvider,
     string codeActionEquivalenceKey)
 {
     var triggerProject = diagnosticsToFix.First().Key;
     var diagnosticIds = GetDiagnosticsIds(diagnosticsToFix.Values);
     var diagnosticProvider = new FixMultipleDiagnosticProvider(diagnosticsToFix);
     return new FixAllState(
         fixAllProvider,
         triggerProject, codeFixProvider, 
         FixAllScope.Custom, codeActionEquivalenceKey, 
         diagnosticIds, diagnosticProvider);
 }
Ejemplo n.º 43
0
 internal FixAllCodeAction(FixAllContext fixAllContext, FixAllProvider fixAllProvider, bool showPreviewChangesDialog)
 {
     _fixAllContext            = fixAllContext;
     _fixAllProvider           = fixAllProvider;
     _showPreviewChangesDialog = showPreviewChangesDialog;
 }
Ejemplo n.º 44
0
 public CodeFixerFixAllProviderInfo(
     FixAllProvider fixAllProvider,
     IEnumerable<string> supportedDiagnosticIds,
     IEnumerable<FixAllScope> supportedScopes)
     : base(fixAllProvider, supportedScopes)
 {
     _supportedDiagnosticIds = supportedDiagnosticIds;
 }
Ejemplo n.º 45
0
 public SuppressionFixerFixAllProviderInfo(
     FixAllProvider fixAllProvider,
     ISuppressionFixProvider suppressionFixer,
     IEnumerable<FixAllScope> supportedScopes)
     : base(fixAllProvider, supportedScopes)
 {
     _canBeSuppressedOrUnsuppressed = suppressionFixer.CanBeSuppressedOrUnsuppressed;
 }
Ejemplo n.º 46
0
 internal FixAllCodeAction(FixAllContext fixAllContext, FixAllProvider fixAllProvider)
 {
     this.fixAllContext  = fixAllContext;
     this.fixAllProvider = fixAllProvider;
 }
Ejemplo n.º 47
0
        private static FixAllState GetFixAllState(
            FixAllProvider fixAllProvider,
            IEnumerable<Diagnostic> diagnostics,
            DiagnosticAnalyzer provider,
            CodeFixProvider fixer,
            TestDiagnosticAnalyzerDriver testDriver,
            Document document,
            FixAllScope scope,
            string fixAllActionId)
        {
            Assert.NotEmpty(diagnostics);

            if (scope == FixAllScope.Custom)
            {
                // Bulk fixing diagnostics in selected scope.                    
                var diagnosticsToFix = ImmutableDictionary.CreateRange(SpecializedCollections.SingletonEnumerable(KeyValuePair.Create(document, diagnostics.ToImmutableArray())));
                return FixAllState.Create(fixAllProvider, diagnosticsToFix, fixer, fixAllActionId);
            }

            var diagnostic = diagnostics.First();
            Func<Document, ImmutableHashSet<string>, CancellationToken, Task<IEnumerable<Diagnostic>>> getDocumentDiagnosticsAsync =
                async (d, diagIds, c) =>
                {
                    var root = await d.GetSyntaxRootAsync();
                    var diags = await testDriver.GetDocumentDiagnosticsAsync(provider, d, root.FullSpan);
                    diags = diags.Where(diag => diagIds.Contains(diag.Id));
                    return diags;
                };

            Func<Project, bool, ImmutableHashSet<string>, CancellationToken, Task<IEnumerable<Diagnostic>>> getProjectDiagnosticsAsync =
                async (p, includeAllDocumentDiagnostics, diagIds, c) =>
                {
                    var diags = includeAllDocumentDiagnostics
                        ? await testDriver.GetAllDiagnosticsAsync(provider, p)
                        : await testDriver.GetProjectDiagnosticsAsync(provider, p);
                    diags = diags.Where(diag => diagIds.Contains(diag.Id));
                    return diags;
                };

            var diagnosticIds = ImmutableHashSet.Create(diagnostic.Id);
            var fixAllDiagnosticProvider = new FixAllState.FixAllDiagnosticProvider(diagnosticIds, getDocumentDiagnosticsAsync, getProjectDiagnosticsAsync);
            return diagnostic.Location.IsInSource
                ? new FixAllState(fixAllProvider, document, fixer, scope, fixAllActionId, diagnosticIds, fixAllDiagnosticProvider)
                : new FixAllState(fixAllProvider, document.Project, fixer, scope, fixAllActionId, diagnosticIds, fixAllDiagnosticProvider);
        }
Ejemplo n.º 48
0
 internal FixAllCodeAction(FixAllContext fixAllContext, FixAllProvider fixAllProvider)
 {
     _fixAllContext  = fixAllContext;
     _fixAllProvider = fixAllProvider;
 }