static void AddRedundantAwaitHighlightings( [NotNull] IHighlightingConsumer consumer, [NotNull] ITokenNode asyncKeyword, [NotNull] Action removeAsync, [NotNull] IAwaitExpression awaitExpression, IExpressionStatement statementToBeReplacedWithReturnStatement, [NotNull] ICSharpExpression expressionToReturn, IAttributesOwnerDeclaration attributesOwnerDeclaration, IInvocationExpression configureAwaitInvocationExpression = null) { var configureAwaitNode = configureAwaitInvocationExpression?.InvokedExpression?.LastChild; var highlightConfigureAwait = configureAwaitNode != null && configureAwaitInvocationExpression.ArgumentList != null; var highlighting = new RedundantAwaitHighlighting( $"Redundant 'await' (remove 'async'/'await'{(highlightConfigureAwait ? "/'" + nameof(Task.ConfigureAwait) + "(...)'" : "")})", removeAsync, awaitExpression, statementToBeReplacedWithReturnStatement, expressionToReturn, attributesOwnerDeclaration); consumer.AddHighlighting(highlighting, awaitExpression.AwaitKeyword.GetDocumentRange()); consumer.AddHighlighting(highlighting, asyncKeyword.GetDocumentRange(), isSecondaryHighlighting: true); if (highlightConfigureAwait) { var dotToken = configureAwaitNode.GetPreviousMeaningfulToken(); var leftParenthesisToken = configureAwaitInvocationExpression.ArgumentList.GetPreviousMeaningfulToken(); var rightParenthesisToken = configureAwaitInvocationExpression.ArgumentList.GetNextMeaningfulToken(); consumer.AddHighlighting( highlighting, configureAwaitNode.GetDocumentRange() .JoinLeft(dotToken.GetDocumentRange()) .JoinRight( configureAwaitInvocationExpression.ArgumentList.GetDocumentRange() .JoinLeft(leftParenthesisToken.GetDocumentRange()) .JoinRight(rightParenthesisToken.GetDocumentRange())), isSecondaryHighlighting: true); } }
public RemoveAsyncAwaitFix([NotNull] RedundantAwaitHighlighting highlighting) => this.highlighting = highlighting;