Пример #1
0
        protected override bool AddLookupItems(T4CodeCompletionContext context, IItemsCollector collector)
        {
            ITreeNode node = context.BasicContext.File.FindNodeAt(context.BasicContext.SelectedTreeRange);

            Assertion.AssertNotNull(node, "node == null");
            var ranges = context.BasicContext.GetRanges(node);

            collector.AddRanges(ranges);

            var attribute = node.GetContainingNode <IT4DirectiveAttribute>();

            Assertion.AssertNotNull(attribute, "attribute != null");

            var directive = attribute.GetContainingNode <IT4Directive>();

            Assertion.AssertNotNull(directive, "directive != null");

            DirectiveInfo          directiveInfo = _directiveInfoManager.GetDirectiveByName(directive.GetName());
            DirectiveAttributeInfo attributeInfo = directiveInfo?.GetAttributeByName(attribute.GetName());

            if (attributeInfo == null)
            {
                return(false);
            }

            foreach (string intellisenseValue in attributeInfo.IntelliSenseValues)
            {
                var item = new TextLookupItem(intellisenseValue);
                item.InitializeRanges(ranges, context.BasicContext);
                collector.Add(item);
            }

            return(true);
        }
Пример #2
0
        private void ProcessAttributeValue([NotNull] T4Token valueNode)
        {
            var attribute = valueNode.Parent as IT4DirectiveAttribute;

            if (attribute == null)
            {
                return;
            }

            if (attribute.ValueError != null)
            {
                AddHighlighting(new HighlightingInfo(valueNode.GetHighlightingRange(),
                                                     new InvalidAttributeValueHighlighting(valueNode, null, attribute.ValueError)));
                return;
            }

            var directive = attribute.Parent as IT4Directive;

            if (directive == null)
            {
                return;
            }

            DirectiveInfo directiveInfo = _directiveInfoManager.GetDirectiveByName(directive.GetName());

            if (directiveInfo == null)
            {
                return;
            }

            DirectiveAttributeInfo attributeInfo = directiveInfo.GetAttributeByName(attribute.GetName());

            if (attributeInfo == null)
            {
                return;
            }

            if (attributeInfo.IsValid(valueNode.GetText()))
            {
                return;
            }

            AddHighlighting(new HighlightingInfo(valueNode.GetHighlightingRange(),
                                                 new InvalidAttributeValueHighlighting(valueNode, attributeInfo, "Invalid attribute value")));
        }
Пример #3
0
        private string GetDirectiveText()
        {
            IT4Directive directive = GetTreeNode();
            string       name      = directive?.Name?.GetText();

            if (name == null)
            {
                return("???");
            }

            DirectiveInfo directiveInfo = T4DirectiveInfoManager.GetDirectiveByName(name);

            if (directiveInfo == null)
            {
                return(name);
            }

            // display the directive with the attributes that are marked with DisplayInCodeStructure
            var builder = new StringBuilder(name);

            foreach (IT4DirectiveAttribute attribute in directive.AttributesEnumerable)
            {
                DirectiveAttributeInfo attributeInfo = directiveInfo.GetAttributeByName(attribute.Name.GetText());
                if (attributeInfo?.IsDisplayedInCodeStructure != true)
                {
                    continue;
                }

                builder.Append(' ');
                builder.Append(attributeInfo.Name);
                if (attribute.Value != null)
                {
                    builder.Append("=\"");
                    builder.Append(attribute.Value.GetText());
                    builder.Append('"');
                }
            }
            return(builder.ToString());
        }