public override void VisitTag(AXmlTag tag) { if (tag.IsComment) { StringBuilder sb = new StringBuilder(); foreach (AXmlText text in tag.Children.OfType <AXmlText>()) { sb.Append(text.Value); } string value = sb.ToString(); foreach (string commentTag in lexerTags) { if (value.Contains(commentTag)) { CompilationUnit.TagComments.Add(new TagComment(value, CreateRegion(tag.StartOffset, tag.EndOffset))); break; } } } base.VisitTag(tag); }
/// <summary> Visit AXmlTag </summary> public virtual void VisitTag(AXmlTag tag) { foreach (AXmlObject child in tag.Children) { child.AcceptVisitor(this); } }
ResolveResult ResolveTag(AXmlTag tag, CancellationToken cancellationToken) { if (!tag.IsStartOrEmptyTag && !tag.IsEndTag) { return(ErrorResolveResult.UnknownError); } return(ResolveElement(tag.Ancestors.OfType <AXmlElement>().First(), cancellationToken)); }
public override void VisitTag(AXmlTag tag) { if (textSource.GetText(tag.StartOffset, tag.OpeningBracket.Length) != tag.OpeningBracket) { throw new InvalidOperationException(); } if (textSource.GetText(tag.NameSegment) != tag.Name) { throw new InvalidOperationException(); } if (textSource.GetText(tag.EndOffset - tag.ClosingBracket.Length, tag.ClosingBracket.Length) != tag.ClosingBracket) { throw new InvalidOperationException(); } base.VisitTag(tag); }
public override void VisitElement(AXmlElement element) { AXmlTag tag = element.Children.FirstOrDefault() as AXmlTag; if (tag != null && tag.IsStartOrEmptyTag) { NodeWrapper node = new NodeWrapper() { ElementName = element.LocalName, StartOffset = element.StartOffset, EndOffset = element.EndOffset, Name = element.GetAttributeValue("Name") ?? element.GetAttributeValue(CompletionDataHelper.XamlNamespace, "Name"), Children = new List <NodeWrapper>() }; if (CompilationUnit.TreeRootNode == null) { CompilationUnit.TreeRootNode = node; nodeStack.Push(CompilationUnit.TreeRootNode); } else { if (nodeStack.Count > 0) { nodeStack.Peek().Children.Add(node); } if (!tag.IsEmptyTag) { nodeStack.Push(node); } } } base.VisitElement(element); if (tag != null && tag.IsStartTag) { nodeStack.PopOrDefault(); } }
public void ActiveOnOffset(int textOffset) { SetCaretOffset(textOffset); AXmlObject xmlObj = xDoc.GetChildAtOffset(textOffset); backgroundRenderer.HighlightColor = Color.FromArgb(0x40, 0, 0, 0xFF); ActiveObject = xmlObj; _activeIndex = -1; //초기값.. if (xmlObj is AXmlText) { if (xmlObj.Parent != null && xmlObj.Parent is AXmlTag) { AXmlTag tag = xmlObj.Parent as AXmlTag; if (tag.OpeningBracket.Equals("<!--"))//comment { ActiveComment = tag; ActiveElement = null; _activeIndex = GetIndex(tag, true); } else { ActiveComment = null; } } else { ActiveComment = null; } } else if (xmlObj is AXmlTag) { AXmlTag tag = xmlObj as AXmlTag; if (tag.OpeningBracket.Equals("<!--"))//comment { ActiveComment = tag; ActiveElement = null; _activeIndex = GetIndex(tag, true); } else { ActiveComment = null; } } else { ActiveComment = null; } if (ActiveComment == null) { ActiveElement = AXmlFinder.FindOwnerElement(xmlObj, true); if (ActiveElement != null) { _activeIndex = GetIndex(ActiveElement, true); } } if (xmlObj is AXmlAttribute) { ActiveAttribute = xmlObj as AXmlAttribute; } else if ((xmlObj is AXmlElement) == false && (xmlObj is AXmlTag)) { ActiveAttribute = null; } else { ActiveAttribute = null; } if (ActiveComment != null) { backgroundRenderer.HighlightObjects = new AXmlObject[] { ActiveComment } }
public static XamlContext ResolveContext(FileName fileName, ITextSource fileContent, int offset) { XamlFullParseInformation info = SD.ParserService.Parse(fileName, fileContent) as XamlFullParseInformation; if (info == null) { throw new Exception("need full parse info!"); } AXmlDocument document = info.Document; AXmlObject currentData = document.GetChildAtOffset(offset); string attributeName = string.Empty, attributeValue = string.Empty; AttributeValue value = null; bool isRoot = false; bool wasAXmlElement = false; int offsetFromValueStart = -1; List <AXmlElement> ancestors = new List <AXmlElement>(); Dictionary <string, XamlNamespace> xmlns = new Dictionary <string, XamlNamespace>(); List <string> ignored = new List <string>(); string xamlNamespacePrefix = string.Empty; var item = currentData; AXmlElement root = null; while (item != document) { if (item is AXmlElement) { AXmlElement element = item as AXmlElement; ancestors.Add(element); foreach (var attr in element.Attributes) { if (attr.IsNamespaceDeclaration) { string prefix = (attr.Name == "xmlns") ? "" : attr.LocalName; if (!xmlns.ContainsKey(prefix)) { xmlns.Add(prefix, new XamlNamespace(attr.Value)); } } if (attr.LocalName == "Ignorable" && attr.Namespace == XamlConst.MarkupCompatibilityNamespace) { ignored.AddRange(attr.Value.Split(' ', '\t')); } if (string.IsNullOrEmpty(xamlNamespacePrefix) && attr.Value == XamlConst.XamlNamespace) { xamlNamespacePrefix = attr.LocalName; } } if (element.Parent is AXmlDocument) { root = element; if (!wasAXmlElement) { isRoot = true; } } wasAXmlElement = true; } item = item.Parent; } XamlContextDescription description = XamlContextDescription.None; AXmlElement active = null; AXmlElement parent = null; if (currentData is AXmlAttribute) { AXmlAttribute a = currentData as AXmlAttribute; int valueStartOffset = a.ValueSegment.Offset + 1; attributeName = a.Name; attributeValue = a.Value; value = MarkupExtensionParser.ParseValue(attributeValue); if (offset >= valueStartOffset && (offset < a.EndOffset || // if length is < 2 one quote is missing (a.ValueSegment.Length <= 1 && offset <= a.EndOffset))) { offsetFromValueStart = offset - valueStartOffset; description = XamlContextDescription.InAttributeValue; if (value != null && !value.IsString) { description = XamlContextDescription.InMarkupExtension; } if (attributeValue.StartsWith("{}", StringComparison.Ordinal) && attributeValue.Length > 2) { description = XamlContextDescription.InAttributeValue; } } else { description = XamlContextDescription.InTag; } active = a.ParentElement; } else if (currentData is AXmlTag) { AXmlTag tag = currentData as AXmlTag; if (tag.IsStartOrEmptyTag || tag.IsEndTag) { if (tag.NameSegment.EndOffset < offset) { description = XamlContextDescription.InTag; } else { description = XamlContextDescription.AtTag; } } else if (tag.IsComment) { description = XamlContextDescription.InComment; } else if (tag.IsCData) { description = XamlContextDescription.InCData; } active = tag.Parent as AXmlElement; } if (active != ancestors.FirstOrDefault()) { parent = ancestors.FirstOrDefault(); } else { parent = ancestors.Skip(1).FirstOrDefault(); } if (active == null) { active = parent; } var xAttribute = currentData as AXmlAttribute; var context = new XamlContext() { Description = description, ActiveElement = active, ParentElement = parent, RootElement = root, Ancestors = ancestors.AsReadOnly(), Attribute = xAttribute, InRoot = isRoot, AttributeValue = value, RawAttributeValue = attributeValue, ValueStartOffset = offsetFromValueStart, XmlnsDefinitions = xmlns, ParseInformation = info, IgnoredXmlns = ignored.AsReadOnly(), XamlNamespacePrefix = xamlNamespacePrefix }; return(context); }