Esempio n. 1
0
        public IEnumerable <XamlNameDecomposition> GetTagAncestry(SnapshotPoint point, bool includeSelf)
        {
            ITextSnapshot snapshot      = point.Snapshot;
            SnapshotSpan  containingTag = this.GetContainingTag(point);

            if (!containingTag.IsEmpty)
            {
                XamlNameDecomposition tagName = this.GetPreviousTagName(new SnapshotPoint(snapshot, containingTag.End));
                if (tagName != null)
                {
                    if (includeSelf)
                    {
                        yield return(tagName);
                    }
                    int lowWaterMark = containingTag.Start;
                    while (!(containingTag = this.GetContainingTag(new SnapshotPoint(snapshot, containingTag.Start))).IsEmpty && containingTag.Start < lowWaterMark)
                    {
                        lowWaterMark = containingTag.Start;
                        tagName      = (XamlNameDecomposition)null;
                        foreach (ClassificationPosition classificationPosition in this.Tokens(containingTag))
                        {
                            if ((tagName = this.GetNameAtPosition(new SnapshotPoint(snapshot, classificationPosition.CurrentSpan.Span.Start))) != null)
                            {
                                yield return(tagName);

                                break;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
            private void ValidatePrefixBindingCache(SnapshotSpan prefixLocationSpan)
            {
                if (this.lastCachedVersion != null && this.lastCachedVersion.Equals((object)prefixLocationSpan.Snapshot.Version))
                {
                    return;
                }
                this.cachedPrefixBindings.Clear();
                this.cachedDefaultNamespaceUri = (string)null;
                ITextSnapshot snapshot       = prefixLocationSpan.Snapshot;
                SnapshotSpan  spanToTokenize = this.GetSpanToTokenize(new SnapshotPoint(snapshot, 0));

                foreach (ClassificationPosition classificationPosition in this.ScanForward(new ClassificationPosition()
                {
                    CurrentLine = spanToTokenize,
                    CurrentSpanList = this.GetClassificationSpans(spanToTokenize),
                    CurrentSpanIndex = 0
                }))
                {
                    ClassificationSpan         currentSpan     = classificationPosition.CurrentSpan;
                    IList <ClassificationSpan> currentSpanList = classificationPosition.CurrentSpanList;
                    int currentSpanIndex = classificationPosition.CurrentSpanIndex;
                    if (currentSpan.ClassificationType != XamlAnalyzer.ClassEndTag)
                    {
                        if (currentSpan.ClassificationType == XamlAnalyzer.ClassAttrNameIdentifier && currentSpan.Span.GetText() == "xmlns")
                        {
                            XamlNameDecomposition nameDecomposition = new XamlNameDecomposition(currentSpanList, currentSpanIndex);
                            if (nameDecomposition.PrefixText == "xmlns" && (!nameDecomposition.NameSpan.IsEmpty && currentSpanList.Count > currentSpanIndex + 4 && currentSpanList[currentSpanIndex + 4].ClassificationType == XamlAnalyzer.ClassAttrValue))
                            {
                                string text = currentSpanList[currentSpanIndex + 4].Span.GetText();
                                this.cachedPrefixBindings[nameDecomposition.NameText] = text.Substring(1, text.Length - 2);
                            }
                            else if (nameDecomposition.PrefixSpan.IsEmpty && nameDecomposition.NameText == "xmlns" && (currentSpanList.Count > currentSpanIndex + 2 && currentSpanList[currentSpanIndex + 2].ClassificationType == XamlAnalyzer.ClassAttrValue))
                            {
                                string text = currentSpanList[currentSpanIndex + 2].Span.GetText();
                                this.cachedDefaultNamespaceUri = text.Substring(1, text.Length - 2);
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                this.lastCachedVersion = snapshot.Version;
            }