private void ProcessAttributeValue([NotNull] T4Token valueNode) { if (!(valueNode.Parent is IT4DirectiveAttribute attribute)) { return; } if (attribute.ValueError != null) { AddHighlighting(valueNode.GetHighlightingRange(), new InvalidAttributeValueHighlighting(valueNode, null, attribute.ValueError)); return; } if (!(attribute.Parent is IT4Directive directive)) { return; } DirectiveAttributeInfo attributeInfo = _directiveInfoManager.GetDirectiveByName(directive.GetName())?.GetAttributeByName(attribute.GetName()); if (attributeInfo == null || attributeInfo.IsValid(valueNode.GetText())) { return; } AddHighlighting(valueNode.GetHighlightingRange(), new InvalidAttributeValueHighlighting(valueNode, attributeInfo, "Invalid attribute value")); }
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); }
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"))); }
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 directive = node.GetContainingNode <IT4Directive>(); Assertion.AssertNotNull(directive, "directive != null"); DirectiveInfo directiveInfo = _directiveInfoManager.GetDirectiveByName(directive.GetName()); if (directiveInfo == null) { return(false); } JetHashSet <string> existingNames = directive .GetAttributes() .Select(attr => attr.GetName()) .ToJetHashSet(s => s, StringComparer.OrdinalIgnoreCase); foreach (string attributeName in directiveInfo.SupportedAttributes.Select(attr => attr.Name)) { if (existingNames.Contains(attributeName)) { continue; } var item = new TextLookupItem(attributeName); item.InitializeRanges(ranges, context.BasicContext); collector.Add(item); } return(true); }
private string GetDirectiveText() { IT4Directive directive = GetTreeNode(); string name = directive != null?directive.GetName() : null; if (name == null) { return("???"); } DirectiveInfo directiveInfo = _directiveInfoManager.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.GetAttributes()) { DirectiveAttributeInfo attributeInfo = directiveInfo.GetAttributeByName(attribute.GetName()); if (attributeInfo == null || !attributeInfo.IsDisplayedInCodeStructure) { continue; } builder.Append(' '); builder.Append(attributeInfo.Name); builder.Append("=\""); builder.Append(attribute.GetValue()); builder.Append('"'); } return(builder.ToString()); }
/// <summary>Finds an anchor for a newly created directive inside a list of existing directives.</summary> /// <param name="newDirective">The directive to add.</param> /// <param name="existingDirectives">The existing directives.</param> /// <param name="directiveInfoManager">An instance of <see cref="DirectiveInfoManager"/>.</param> /// <returns>A pair indicating the anchor (can be null) and its relative position.</returns> public static Pair <IT4Directive, BeforeOrAfter> FindAnchor( [NotNull] this IT4Directive newDirective, [NotNull] IT4Directive[] existingDirectives, [NotNull] DirectiveInfoManager directiveInfoManager ) { // no anchor if (existingDirectives.Length == 0) { return(Pair.Of((IT4Directive)null, BeforeOrAfter.Before)); } // directive name should never be null, but you never know string newName = newDirective.GetName(); if (String.IsNullOrEmpty(newName)) { return(Pair.Of(existingDirectives.Last(), BeforeOrAfter.After)); } var lastDirectiveByName = new Dictionary <string, IT4Directive>(StringComparer.OrdinalIgnoreCase); DirectiveInfo directiveInfo = directiveInfoManager.GetDirectiveByName(newName); string newsortValue = GetSortValue(newDirective, directiveInfo, directiveInfoManager); foreach (IT4Directive existingDirective in existingDirectives) { string existingName = existingDirective.GetName(); if (existingName == null) { continue; } lastDirectiveByName[existingName] = existingDirective; // directive of the same type as the new one: // if the new directive comes alphabetically before the existing one, we got out anchor if (String.Equals(existingName, newName, StringComparison.OrdinalIgnoreCase)) { string existingSortValue = GetSortValue(existingDirective, directiveInfo, directiveInfoManager); if (String.Compare(newsortValue, existingSortValue, StringComparison.OrdinalIgnoreCase) < 0) { return(Pair.Of(existingDirective, BeforeOrAfter.Before)); } } } // no anchor being alphabetically after the new directive was found: // the last directive of the same type will be used as an anchor if (lastDirectiveByName.TryGetValue(newName, out IT4Directive lastDirective)) { return(Pair.Of(lastDirective, BeforeOrAfter.After)); } // there was no directive of the same type as the new one // the anchor will be the last directive of the type just before (determined by the position in DirectiveInfo.AllDirectives) if (directiveInfo != null) { int index = directiveInfoManager.AllDirectives.IndexOf(directiveInfo) - 1; while (index >= 0) { if (lastDirectiveByName.TryGetValue(directiveInfoManager.AllDirectives[index].Name, out lastDirective)) { return(Pair.Of(lastDirective, BeforeOrAfter.After)); } --index; } return(Pair.Of(existingDirectives.First(), BeforeOrAfter.Before)); } // we don't know the directive name (shouldn't happen), use the last directive as an anchor return(Pair.Of(existingDirectives.Last(), BeforeOrAfter.After)); }