コード例 #1
0
        private async Task <ImmutableArray <TextChange> > GetCodeCleanupAndFormatChangesAsync(
            Document document, ICodeCleanupService codeCleanupService,
            IProgressTracker progressTracker, CancellationToken cancellationToken)
        {
            var newDoc = await codeCleanupService.CleanupAsync(
                document, progressTracker, cancellationToken).ConfigureAwait(false);

            var changes = await newDoc.GetTextChangesAsync(document, cancellationToken).ConfigureAwait(false);

            return(changes.ToImmutableArrayOrEmpty());
        }
コード例 #2
0
        private void CodeCleanupOrFormat(
            FormatDocumentCommandArgs args, Document document, ICodeCleanupService codeCleanupService,
            IProgressTracker progressTracker, CancellationToken cancellationToken)
        {
            var workspace = document.Project.Solution.Workspace;
            var isFeatureTurnedOnThroughABTest = TurnOnCodeCleanupForGroupBIfInABTest(document, workspace);
            var performAdditionalCodeCleanupDuringFormatting = workspace.Options.GetOption(CodeCleanupOptions.PerformAdditionalCodeCleanupDuringFormatting, document.Project.Language);

            // if feature is turned on through AB test, we need to show the Gold bar even if they set NeverShowCodeCleanupInfoBarAgain == true before
            if (isFeatureTurnedOnThroughABTest ||
                !workspace.Options.GetOption(CodeCleanupOptions.NeverShowCodeCleanupInfoBarAgain, document.Project.Language))
            {
                // Show different gold bar text depends on PerformAdditionalCodeCleanupDuringFormatting value
                ShowGoldBarForCodeCleanupConfiguration(document, performAdditionalCodeCleanupDuringFormatting);
            }

            if (performAdditionalCodeCleanupDuringFormatting)
            {
                // Start with a single progress item, which is the one to actually apply
                // the changes.
                progressTracker.AddItems(1);

                // Code cleanup
                var oldDoc = document;

                var codeCleanupChanges = GetCodeCleanupAndFormatChangesAsync(
                    document, codeCleanupService, progressTracker, cancellationToken).WaitAndGetResult(cancellationToken);

                if (codeCleanupChanges != null && codeCleanupChanges.Length > 0)
                {
                    progressTracker.Description = EditorFeaturesResources.Applying_changes;
                    ApplyChanges(oldDoc, codeCleanupChanges.ToList(), selectionOpt: null, cancellationToken);
                }

                progressTracker.ItemCompleted();
            }
            else
            {
                Format(args.TextView, document, selectionOpt: null, cancellationToken);
            }
        }
コード例 #3
0
        private async Task <IEnumerable <TextChange> > GetCodeCleanupAndFormatChangesAsync(Document document, ICodeCleanupService codeCleanupService, CancellationToken cancellationToken)
        {
            var newDoc = await codeCleanupService.CleanupAsync(document, cancellationToken).ConfigureAwait(false);

            return(await newDoc.GetTextChangesAsync(document, cancellationToken).ConfigureAwait(false));
        }