Exemple #1
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, SyntaxNode node)
        {
            if (context.IsAnyRefactoringEnabled(
                    RefactoringIdentifiers.WrapInRegion,
                    RefactoringIdentifiers.WrapInIfDirective))
            {
                //XPERF:
                TextLineCollectionSelection selectedLines = await SelectedLinesRefactoring.GetSelectedLinesAsync(context).ConfigureAwait(false);

                if (selectedLines != null)
                {
                    if (context.IsRefactoringEnabled(RefactoringIdentifiers.WrapInRegion))
                    {
                        context.RegisterRefactoring(
                            "Wrap in region",
                            ct => WrapInRegionRefactoring.Instance.RefactorAsync(context.Document, selectedLines, ct));
                    }

                    if (context.IsRefactoringEnabled(RefactoringIdentifiers.WrapInIfDirective))
                    {
                        context.RegisterRefactoring(
                            "Wrap in #if",
                            ct => WrapInIfDirectiveRefactoring.Instance.RefactorAsync(context.Document, selectedLines, ct));
                    }
                }
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.RemoveEmptyLines) &&
                await RemoveEmptyLinesRefactoring.CanRefactorAsync(context, node).ConfigureAwait(false))
            {
                context.RegisterRefactoring(
                    "Remove empty lines",
                    ct => RemoveEmptyLinesRefactoring.RefactorAsync(context.Document, context.Span, ct));
            }
        }
Exemple #2
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, SyntaxNode node)
        {
            if (context.IsAnyRefactoringEnabled(
                    RefactoringIdentifiers.WrapInRegion,
                    RefactoringIdentifiers.WrapInIfDirective))
            {
                SelectedTextLineCollection lines = await SelectedLinesRefactoring.GetSelectedLinesAsync(context, node).ConfigureAwait(false);

                if (lines?.Any() == true)
                {
                    if (context.IsRefactoringEnabled(RefactoringIdentifiers.WrapInRegion))
                    {
                        context.RegisterRefactoring(
                            "Wrap in region",
                            cancellationToken =>
                        {
                            var refactoring = new WrapInRegionRefactoring();

                            return(refactoring.RefactorAsync(context.Document, lines, cancellationToken));
                        });
                    }

                    if (context.IsRefactoringEnabled(RefactoringIdentifiers.WrapInIfDirective))
                    {
                        context.RegisterRefactoring(
                            "Wrap in #if",
                            cancellationToken =>
                        {
                            var refactoring = new WrapInIfDirectiveRefactoring();

                            return(refactoring.RefactorAsync(context.Document, lines, cancellationToken));
                        });
                    }
                }
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.RemoveEmptyLines) &&
                await RemoveEmptyLinesRefactoring.CanRefactorAsync(context, node).ConfigureAwait(false))
            {
                context.RegisterRefactoring(
                    "Remove empty lines",
                    cancellationToken =>
                {
                    return(RemoveEmptyLinesRefactoring.RefactorAsync(
                               context.Document,
                               node,
                               context.Span,
                               cancellationToken));
                });
            }
        }