Example #1
0
        private static void HighlightByArgument(
            HighlightingsConsumer consumer,
            ICSharpArgument selectedArgument,
            ICSharpArgument templateArgument,
            MessageTemplate messageTemplate)
        {
            var argumentIndex        = selectedArgument.IndexOf() - templateArgument.IndexOf() - 1;
            var namedProperties      = messageTemplate.NamedProperties;
            var positionalProperties = messageTemplate.PositionalProperties;

            if (namedProperties != null && argumentIndex < namedProperties.Length)
            {
                var property = namedProperties[argumentIndex];
                consumer.ConsumeHighlighting(
                    HighlightingAttributeIds.USAGE_OF_ELEMENT_UNDER_CURSOR,
                    templateArgument.GetTokenDocumentRange(property));
            }
            else if (positionalProperties != null)
            {
                foreach (var property in positionalProperties)
                {
                    if (!property.TryGetPositionalValue(out int position))
                    {
                        continue;
                    }

                    if (position != argumentIndex)
                    {
                        continue;
                    }

                    consumer.ConsumeHighlighting(
                        HighlightingAttributeIds.USAGE_OF_ELEMENT_UNDER_CURSOR,
                        templateArgument.GetTokenDocumentRange(property));
                }
            }

            consumer.ConsumeHighlighting(
                HighlightingAttributeIds.USAGE_OF_ELEMENT_UNDER_CURSOR,
                selectedArgument.GetDocumentRange());
        }
Example #2
0
        private static void HighlightByNamedPlaceholder(
            HighlightingsConsumer consumer,
            IPsiView psiView,
            ICSharpArgument templateArgument,
            MessageTemplate messageTemplate,
            TreeNodeCollection <ICSharpArgument> arguments)
        {
            if (messageTemplate.NamedProperties != null)
            {
                var(selectedToken, index) = GetSelectedToken(psiView, templateArgument, messageTemplate.NamedProperties);
                if (selectedToken == null)
                {
                    return;
                }

                var argumentIndex = templateArgument.IndexOf() + index + 1;
                if (arguments.Count <= argumentIndex)
                {
                    return;
                }

                consumer.ConsumeHighlighting(
                    HighlightingAttributeIds.USAGE_OF_ELEMENT_UNDER_CURSOR,
                    templateArgument.GetTokenDocumentRange(selectedToken));
                consumer.ConsumeHighlighting(
                    HighlightingAttributeIds.USAGE_OF_ELEMENT_UNDER_CURSOR,
                    arguments[argumentIndex].GetDocumentRange());
            }
            else if (messageTemplate.PositionalProperties != null)
            {
                var(selectedToken, _) = GetSelectedToken(psiView, templateArgument, messageTemplate.PositionalProperties);
                if (selectedToken == null)
                {
                    return;
                }

                if (!selectedToken.TryGetPositionalValue(out int position))
                {
                    return;
                }

                foreach (var property in messageTemplate.PositionalProperties)
                {
                    if (!property.TryGetPositionalValue(out int propertyPosition))
                    {
                        continue;
                    }

                    if (propertyPosition != position)
                    {
                        continue;
                    }

                    consumer.ConsumeHighlighting(
                        HighlightingAttributeIds.USAGE_OF_ELEMENT_UNDER_CURSOR,
                        templateArgument.GetTokenDocumentRange(property));
                }

                var argumentIndex = templateArgument.IndexOf() + position + 1;
                if (arguments.Count <= argumentIndex)
                {
                    return;
                }

                consumer.ConsumeHighlighting(
                    HighlightingAttributeIds.USAGE_OF_ELEMENT_UNDER_CURSOR,
                    arguments[argumentIndex].GetDocumentRange());
            }
        }