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(
                    GeneralHighlightingAttributeIds.USAGE_OF_ELEMENT_UNDER_CURSOR,
                    templateArgument.GetTokenInformation(property).DocumentRange);
            }
            else if (positionalProperties != null)
            {
                foreach (var property in positionalProperties)
                {
                    if (!property.TryGetPositionalValue(out int position))
                    {
                        continue;
                    }

                    if (position != argumentIndex)
                    {
                        continue;
                    }

                    consumer.ConsumeHighlighting(
                        GeneralHighlightingAttributeIds.USAGE_OF_ELEMENT_UNDER_CURSOR,
                        templateArgument.GetTokenInformation(property).DocumentRange);
                }
            }

            consumer.ConsumeHighlighting(
                GeneralHighlightingAttributeIds.USAGE_OF_ELEMENT_UNDER_CURSOR,
                selectedArgument.GetDocumentRange());
        }
示例#2
0
        private static void HighlightTemplate(
            IHighlightingConsumer consumer,
            ICSharpArgument templateArgument,
            MessageTemplate messageTemplate)
        {
            foreach (var token in messageTemplate.Tokens)
            {
                if (!(token is PropertyToken))
                {
                    continue;
                }

                consumer.AddHighlighting(
                    new StringEscapeCharacterHighlighting(
                        templateArgument.GetTokenInformation(token).DocumentRange,
                        DefaultLanguageAttributeIds.FORMAT_STRING_ITEM));
            }
        }
        private static (PropertyToken token, int index) GetSelectedToken(
            IPsiView psiView,
            ICSharpArgument templateArgument,
            PropertyToken[] properties)
        {
            var selectedTreeRange = psiView.GetSelectedTreeRange(templateArgument);

            var propertyIndex = 0;

            foreach (var property in properties)
            {
                var documentRange = templateArgument.GetTokenInformation(property).DocumentRange;

                if (documentRange.StartOffset.Offset <= selectedTreeRange.StartOffset.Offset &&
                    documentRange.EndOffset.Offset >= selectedTreeRange.EndOffset.Offset)
                {
                    return(property, propertyIndex);
                }

                propertyIndex++;
            }

            return(null, -1);
        }
        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(
                    GeneralHighlightingAttributeIds.USAGE_OF_ELEMENT_UNDER_CURSOR,
                    templateArgument.GetTokenInformation(selectedToken).DocumentRange);
                consumer.ConsumeHighlighting(
                    GeneralHighlightingAttributeIds.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(
                        GeneralHighlightingAttributeIds.USAGE_OF_ELEMENT_UNDER_CURSOR,
                        templateArgument.GetTokenInformation(property).DocumentRange);
                }

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

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