public override async Task ComputeRefactoringsAsync(CodeRefactoringContext context) { SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken); ArgumentListSyntax argumentList = root .FindNode(context.Span, getInnermostNodeForTie: true)? .FirstAncestorOrSelf<ArgumentListSyntax>(); if (argumentList == null) return; if (argumentList.Arguments.Count == 0) return; if (!context.Span.IsEmpty) ArgumentRefactoring.AddOrRemoveArgumentName(context, argumentList); if (argumentList.IsSingleline()) { if (argumentList.Arguments.Count > 1) { context.RegisterRefactoring( "Format each argument on separate line", cancellationToken => FormatEachArgumentOnNewLineAsync(context.Document, argumentList, cancellationToken)); } } else { context.RegisterRefactoring( "Format all arguments on a single line", cancellationToken => FormatAllArgumentsOnSingleLineAsync(context.Document, argumentList, cancellationToken)); } SwapArgumentsRefactoring.Refactor(context, argumentList); }
public override SyntaxNode VisitArgument(ArgumentSyntax node) { if (Array.IndexOf(_arguments, node) != -1) { return(ArgumentRefactoring.AddParameterName(node, _semanticModel)); } return(base.VisitArgument(node)); }