Example #1
0
        protected override void TryHighlightToRight(MatchingHighlightingsConsumer consumer, ITokenNode selectedToken, TreeOffset treeOffset)
        {
            var selectedTokenType = selectedToken.GetTokenType();

            if (IsLeftBracket(selectedTokenType))
            {
                ITokenNode matchedNode;
                if (FindMatchingRightBracket(selectedToken, out matchedNode))
                {
                    var singleChar = IsSingleCharToken(matchedNode);
                    consumer.ConsumeMatchingBracesHighlighting(selectedToken.GetDocumentRange(), matchedNode.GetDocumentRange(), singleChar);
                }
                else
                {
                    consumer.ConsumeHighlighting(HighlightingAttributeIds.UNMATCHED_BRACE, selectedToken.GetDocumentStartOffset().ExtendRight(1));

                    if (matchedNode != null)
                    {
                        consumer.ConsumeHighlighting(HighlightingAttributeIds.UNMATCHED_BRACE, matchedNode.GetDocumentEndOffset().ExtendLeft(1));
                    }
                }
            }
            else if (selectedTokenType == ShaderLabTokenType.STRING_LITERAL)
            {
                if (treeOffset == selectedToken.GetTreeTextRange().StartOffset)
                {
                    consumer.ConsumeMatchingBracesHighlighting(
                        selectedToken.GetDocumentStartOffset().ExtendRight(1), selectedToken.GetDocumentEndOffset().ExtendLeft(1));
                }
            }
        }
Example #2
0
        protected override void TryHighlightToLeft(MatchingHighlightingsConsumer consumer, ITokenNode selectedToken, TreeOffset treeOffset)
        {
            TokenNodeType tokenType = selectedToken.GetTokenType();

            if (this.IsRightBracket(tokenType))
            {
                ITokenNode matchedToken;
                if (this.FindMatchingLeftBracket(selectedToken, out matchedToken))
                {
                    consumer.ConsumeMatchingBracesHighlighting(matchedToken.GetDocumentRange(), selectedToken.GetDocumentRange());
                    this.myLBraceDocumentRangeForIbh = matchedToken.GetDocumentRange();
                    this.myRBraceDocumentRangeForIbh = selectedToken.GetDocumentRange();
                    this.myHintTextGetter            = textControl => this.GetHintText(textControl, matchedToken);
                }
                else
                {
                    consumer.ConsumeHighlighting(
                        "ReSharper Unmatched Brace", selectedToken.GetDocumentRange().EndOffsetRange().ExtendLeft(1));
                    if (matchedToken == null)
                    {
                        return;
                    }

                    consumer.ConsumeHighlighting(
                        "ReSharper Unmatched Brace", matchedToken.GetDocumentRange().StartOffsetRange().ExtendRight(1));
                }
            }
            else
            {
                if (tokenType != NTriplesTokenType.STRING_LITERAL)
                {
                    return;
                }
                if (selectedToken.GetText()[0] == 64)
                {
                    if (!(treeOffset == selectedToken.GetTreeTextRange().EndOffset))
                    {
                        return;
                    }

                    consumer.ConsumeMatchingBracesHighlighting(
                        selectedToken.GetDocumentRange().StartOffsetRange().ExtendRight(1).Shift(1),
                        selectedToken.GetDocumentRange().EndOffsetRange().ExtendLeft(1));
                }
                else
                {
                    if (treeOffset != selectedToken.GetTreeTextRange().EndOffset)
                    {
                        return;
                    }

                    consumer.ConsumeMatchingBracesHighlighting(
                        selectedToken.GetDocumentRange().StartOffsetRange().ExtendRight(1),
                        selectedToken.GetDocumentRange().EndOffsetRange().ExtendLeft(1));
                }
            }
        }
        static void AddRedundantAwaitHighlightings(
            [NotNull] IHighlightingConsumer consumer,
            [NotNull] ITokenNode asyncKeyword,
            [NotNull] Action removeAsync,
            [NotNull] IAwaitExpression awaitExpression,
            [CanBeNull] IExpressionStatement statementToBeReplacedWithReturnStatement,
            [NotNull] ICSharpExpression expressionToReturn,
            [CanBeNull] IAttributesOwnerDeclaration attributesOwnerDeclaration,
            [CanBeNull] IInvocationExpression configureAwaitInvocationExpression = null)
        {
            var configureAwaitNode = configureAwaitInvocationExpression?.InvokedExpression?.LastChild;

            var highlightConfigureAwait = configureAwaitNode != null && configureAwaitInvocationExpression.ArgumentList != null;

            var highlighting = new RedundantAwaitSuggestion(
                $"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);
            }
        }
Example #4
0
 public override DocumentRange CalculateRange() => modifierTokenNode.GetDocumentRange();
 public override DocumentRange CalculateRange() => asyncKeyword.GetDocumentRange();
        protected override void TryHighlightToRight(MatchingHighlightingsConsumer consumer, ITokenNode selectedToken, TreeOffset treeOffset)
        {
            TokenNodeType tokenType = selectedToken.GetTokenType();
            if (this.IsLeftBracket(tokenType))
            {
                ITokenNode matchedToken;
                if (this.FindMatchingRightBracket(selectedToken, out matchedToken))
                {
                    consumer.ConsumeMatchingBracesHighlighting(selectedToken.GetDocumentRange(), matchedToken.GetDocumentRange());
                }
                else
                {
                    consumer.ConsumeHighlighting(
                        "ReSharper Unmatched Brace", selectedToken.GetDocumentRange().StartOffsetRange().ExtendRight(1));
                    if (matchedToken == null)
                    {
                        return;
                    }
                    consumer.ConsumeHighlighting(
                        "ReSharper Unmatched Brace", matchedToken.GetDocumentRange().EndOffsetRange().ExtendLeft(1));
                }
            }
            else
            {
                if (tokenType != NTriplesTokenType.STRING_LITERAL)
                {
                    return;
                }
                if (selectedToken.GetText()[0] == 64)
                {
                    if (treeOffset != selectedToken.GetTreeTextRange().StartOffset.Shift(1))
                    {
                        return;
                    }

                    consumer.ConsumeMatchingBracesHighlighting(
                        selectedToken.GetDocumentRange().StartOffsetRange().ExtendRight(1).Shift(1),
                        selectedToken.GetDocumentRange().EndOffsetRange().ExtendLeft(1));
                }
                else
                {
                    if (treeOffset != selectedToken.GetTreeTextRange().StartOffset)
                    {
                        return;
                    }

                    consumer.ConsumeMatchingBracesHighlighting(
                        selectedToken.GetDocumentRange().StartOffsetRange().ExtendRight(1),
                        selectedToken.GetDocumentRange().EndOffsetRange().ExtendLeft(1));
                }
            }
        }
 /// <summary>Initializes a new instance of the <see cref="StringEmptySuggestion"/> class.</summary>
 /// <param name="solution">The solution.</param>
 /// <param name="node">The node.</param>
 public StringEmptySuggestion(ISolution solution, ITokenNode node)
     : base(NAME, node, node.GetDocumentRange(), "Empty string literals (\"\") should be string.Empty [Agent Johnson]")
 {
     this._solution = solution;
       this._node = node;
 }