コード例 #1
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, ArgumentListSyntax argumentList)
        {
            SeparatedSyntaxList <ArgumentSyntax> arguments = argumentList.Arguments;

            if (arguments.Count == 0)
            {
                return;
            }

            await AddOrRemoveParameterNameRefactoring.ComputeRefactoringsAsync(context, argumentList).ConfigureAwait(false);

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.DuplicateArgument))
            {
                var refactoring = new DuplicateArgumentRefactoring(argumentList);
                refactoring.ComputeRefactoring(context);
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.FormatArgumentList) &&
                (context.Span.IsEmpty || context.Span.IsBetweenSpans(argumentList)))
            {
                if (argumentList.IsSingleLine())
                {
                    if (arguments.Count > 1)
                    {
                        context.RegisterRefactoring(
                            "Format arguments on separate lines",
                            cancellationToken =>
                        {
                            return(CSharpFormatter.ToMultiLineAsync(
                                       context.Document,
                                       argumentList,
                                       cancellationToken));
                        });
                    }
                }
                else
                {
                    context.RegisterRefactoring(
                        "Format arguments on a single line",
                        cancellationToken =>
                    {
                        return(CSharpFormatter.ToSingleLineAsync(
                                   context.Document,
                                   argumentList,
                                   cancellationToken));
                    });
                }
            }
        }
コード例 #2
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, ArgumentListSyntax argumentList)
        {
            SeparatedSyntaxList <ArgumentSyntax> arguments = argumentList.Arguments;

            if (!arguments.Any())
            {
                return;
            }

            await AddOrRemoveParameterNameRefactoring.ComputeRefactoringsAsync(context, argumentList).ConfigureAwait(false);

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.DuplicateArgument))
            {
                var refactoring = new DuplicateArgumentRefactoring(argumentList);
                refactoring.ComputeRefactoring(context, RefactoringIdentifiers.DuplicateArgument);
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.FormatArgumentList) &&
                (context.Span.IsEmptyAndContainedInSpanOrBetweenSpans(argumentList)))
            {
                if (argumentList.IsSingleLine())
                {
                    if (arguments.Count > 1)
                    {
                        context.RegisterRefactoring(
                            "Format arguments on separate lines",
                            ct => SyntaxFormatter.ToMultiLineAsync(context.Document, argumentList, ct),
                            RefactoringIdentifiers.FormatArgumentList);
                    }
                }
                else if (argumentList.DescendantTrivia(argumentList.Span).All(f => f.IsWhitespaceOrEndOfLineTrivia()))
                {
                    context.RegisterRefactoring(
                        "Format arguments on a single line",
                        ct => SyntaxFormatter.ToSingleLineAsync(context.Document, argumentList, ct),
                        RefactoringIdentifiers.FormatArgumentList);
                }
            }
        }