示例#1
0
        private ClassificationPosition CreateClassificationPosition(SnapshotPoint position)
        {
            SnapshotSpan spanToTokenize = this.statefulClassifier.GetSpanToTokenize(position);

            XamlAnalyzer.LineState         state      = this.statefulClassifier.GetState(spanToTokenize.Snapshot, spanToTokenize.Start);
            IList <ClassificationSpan>     list       = (IList <ClassificationSpan>) new List <ClassificationSpan>();
            IList <XamlAnalyzer.LineState> stateSpans = (IList <XamlAnalyzer.LineState>) new List <XamlAnalyzer.LineState>();

            XamlAnalyzer.LineState endState;
            this.classificationScanner.GetClassificationSpansWorker(spanToTokenize, list, stateSpans, state, out endState);
            int num = OrderedListExtensions.GenericBinarySearch <ClassificationSpan, SnapshotPoint>(list, position, (Func <SnapshotPoint, ClassificationSpan, int>)((pos, span) => pos.Position - span.Span.Start));

            if (num < 0)
            {
                num = ~num - 1;
            }
            return(new ClassificationPosition()
            {
                CurrentLine = spanToTokenize,
                CurrentSpanList = list,
                CurrentSpanIndex = num
            });
        }
示例#2
0
        internal XamlNameDecomposition GetPreviousTagName(SnapshotPoint position)
        {
            SnapshotSpan spanToTokenize = this.statefulClassifier.GetSpanToTokenize(position);

            XamlAnalyzer.LineState         state1     = this.statefulClassifier.GetState(spanToTokenize.Snapshot, spanToTokenize.Start);
            IList <ClassificationSpan>     list       = (IList <ClassificationSpan>) new List <ClassificationSpan>();
            IList <XamlAnalyzer.LineState> stateSpans = (IList <XamlAnalyzer.LineState>) new List <XamlAnalyzer.LineState>();

            XamlAnalyzer.LineState endState;
            this.classificationScanner.GetClassificationSpansWorker(spanToTokenize, list, stateSpans, state1, out endState);
            int num1 = OrderedListExtensions.GenericBinarySearch <ClassificationSpan, SnapshotPoint>(list, position, (Func <SnapshotPoint, ClassificationSpan, int>)((pos, span) => pos.Position - span.Span.Start));

            if (num1 < 0)
            {
                num1 = ~num1;
            }
            int index = num1 - 1;

            XamlAnalyzer.ParseState state2;
            if (index < 0)
            {
                state2 = state1.ParseState;
            }
            else
            {
                state2 = stateSpans[index].ParseState;
                switch (state2)
                {
                case XamlAnalyzer.ParseState.EmptyTagEnd:
                case XamlAnalyzer.ParseState.TagEnd:
                    if (list[index].Span.IntersectsWith(new Span(position.Position, 0)))
                    {
                        state2 = index != 0 ? stateSpans[index - 1].ParseState : stateSpans[index].ParseState;
                        break;
                    }
                    break;
                }
            }
            int num2 = -1;

            if (XamlAnalyzer.IsInsideTag(state2))
            {
                foreach (ClassificationPosition classificationPosition in this.statefulClassifier.ScanBackward(new ClassificationPosition()
                {
                    CurrentLine = spanToTokenize,
                    CurrentSpanList = list,
                    CurrentSpanIndex = index
                }))
                {
                    if (classificationPosition.CurrentSpan.ClassificationType == XamlAnalyzer.ClassStartTag)
                    {
                        num2 = classificationPosition.CurrentSpan.Span.Start;
                        break;
                    }
                    if (classificationPosition.CurrentSpan.ClassificationType != XamlAnalyzer.ClassStartClosingTag)
                    {
                        if (classificationPosition.CurrentSpan.ClassificationType != XamlAnalyzer.ClassEndEmptyTag)
                        {
                            if (classificationPosition.CurrentSpan.ClassificationType == XamlAnalyzer.ClassEndTag)
                            {
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (num2 == -1)
            {
                return((XamlNameDecomposition)null);
            }
            return(this.GetNameAtPosition(new SnapshotPoint(position.Snapshot, num2 + 1)));
        }
示例#3
0
        private SnapshotSpan GetContainingTag(SnapshotPoint position, bool shouldReturnCloseTagSpan, out bool isInCloseTag, bool returnEmptySpanOnContent)
        {
            isInCloseTag = false;
            SnapshotSpan spanToTokenize = this.statefulClassifier.GetSpanToTokenize(position);

            XamlAnalyzer.LineState         state1 = this.statefulClassifier.GetState(spanToTokenize.Snapshot, spanToTokenize.Start);
            IList <ClassificationSpan>     list1  = (IList <ClassificationSpan>) new List <ClassificationSpan>();
            IList <XamlAnalyzer.LineState> list2  = (IList <XamlAnalyzer.LineState>) new List <XamlAnalyzer.LineState>();

            XamlAnalyzer.LineState endState;
            this.classificationScanner.GetClassificationSpansWorker(spanToTokenize, list1, list2, state1, out endState);
            int num1 = OrderedListExtensions.GenericBinarySearch <ClassificationSpan, SnapshotPoint>(list1, position, (Func <SnapshotPoint, ClassificationSpan, int>)((pos, span) => pos.Position - span.Span.Start));

            if (num1 < 0)
            {
                num1 = ~num1;
            }
            int startSpanIndex = num1 - 1;

            XamlAnalyzer.ParseState state2 = startSpanIndex >= 0 ? list2[startSpanIndex].ParseState : state1.ParseState;
            if (XamlAnalyzer.IsInsideClosingTag(list2, startSpanIndex))
            {
                isInCloseTag = true;
                ClassificationPosition startPosition = new ClassificationPosition()
                {
                    CurrentLine      = spanToTokenize,
                    CurrentSpanList  = list1,
                    CurrentSpanIndex = startSpanIndex
                };
                int currentSpanIndex = startPosition.CurrentSpanIndex;
                if (startSpanIndex >= 0 && startPosition.CurrentSpan.ClassificationType != XamlAnalyzer.ClassStartClosingTag)
                {
                    foreach (ClassificationPosition classificationPosition in this.statefulClassifier.ScanBackward(startPosition))
                    {
                        if (classificationPosition.CurrentSpan.ClassificationType == XamlAnalyzer.ClassStartClosingTag)
                        {
                            startPosition    = classificationPosition;
                            currentSpanIndex = classificationPosition.CurrentSpanIndex;
                            break;
                        }
                    }
                }
                if (shouldReturnCloseTagSpan)
                {
                    int start = startPosition.CurrentSpanList[Math.Max(0, currentSpanIndex)].Span.Start;
                    int end   = startPosition.CurrentSpanList[Math.Max(0, currentSpanIndex)].Span.End;
                    for (int index = currentSpanIndex + 1; index < startPosition.CurrentSpanList.Count && XamlAnalyzer.IsTokenValidInCloseTag(startPosition.CurrentSpanList[index].ClassificationType); ++index)
                    {
                        end = startPosition.CurrentSpanList[index].Span.End;
                    }
                    return(new SnapshotSpan(startPosition.Snapshot, start, end - start));
                }
                int num2 = 1;
                foreach (ClassificationPosition classificationPosition in this.statefulClassifier.ScanBackward(startPosition))
                {
                    num2 += XamlAnalyzer.TagDepthDelta(false, classificationPosition.CurrentSpan.ClassificationType);
                    if (num2 == 0)
                    {
                        startPosition = classificationPosition;
                        break;
                    }
                }
                if (num2 != 0)
                {
                    return(new SnapshotSpan());
                }
                int start1 = startPosition.CurrentSpan.Span.Start;
                foreach (ClassificationPosition classificationPosition in this.statefulClassifier.ScanForward(startPosition))
                {
                    if (classificationPosition.CurrentSpan.ClassificationType == XamlAnalyzer.ClassEndTag || classificationPosition.CurrentSpan.ClassificationType == XamlAnalyzer.ClassEndEmptyTag)
                    {
                        return(new SnapshotSpan(classificationPosition.Snapshot, new Span(start1, classificationPosition.CurrentSpan.Span.End - start1)));
                    }
                    if (classificationPosition.CurrentSpan.Span != startPosition.CurrentSpan.Span && (classificationPosition.CurrentSpan.ClassificationType == XamlAnalyzer.ClassStartTag || classificationPosition.CurrentSpan.ClassificationType == XamlAnalyzer.ClassStartClosingTag))
                    {
                        return(new SnapshotSpan(classificationPosition.Snapshot, new Span(start1, classificationPosition.CurrentSpan.Span.Start - start1)));
                    }
                }
            }
            else if (XamlAnalyzer.IsInsideTag(state2))
            {
                ClassificationPosition startPosition = new ClassificationPosition()
                {
                    CurrentLine      = spanToTokenize,
                    CurrentSpanList  = list1,
                    CurrentSpanIndex = startSpanIndex
                };
                int start = -1;
                if (startPosition.CurrentSpan.ClassificationType == XamlAnalyzer.ClassStartTag)
                {
                    start = startPosition.CurrentSpan.Span.Start;
                }
                else
                {
                    foreach (ClassificationPosition classificationPosition in this.statefulClassifier.ScanBackward(startPosition))
                    {
                        if (classificationPosition.CurrentSpan.ClassificationType == XamlAnalyzer.ClassStartTag)
                        {
                            start = classificationPosition.CurrentSpan.Span.Start;
                            break;
                        }
                    }
                }
                int num2 = startPosition.Snapshot.Length;
                foreach (ClassificationPosition classificationPosition in this.statefulClassifier.ScanForward(startPosition))
                {
                    if (classificationPosition.CurrentSpan.ClassificationType == XamlAnalyzer.ClassEndEmptyTag || classificationPosition.CurrentSpan.ClassificationType == XamlAnalyzer.ClassEndTag)
                    {
                        num2 = classificationPosition.CurrentSpan.Span.End;
                        break;
                    }
                    if (classificationPosition.CurrentSpan.Span != startPosition.CurrentSpan.Span && (classificationPosition.CurrentSpan.ClassificationType == XamlAnalyzer.ClassStartTag || classificationPosition.CurrentSpan.ClassificationType == XamlAnalyzer.ClassStartClosingTag))
                    {
                        num2 = classificationPosition.CurrentSpan.Span.Start;
                        break;
                    }
                }
                if (start >= 0 && num2 > start)
                {
                    return(new SnapshotSpan(startPosition.Snapshot, new Span(start, num2 - start)));
                }
            }
            else
            {
                if (returnEmptySpanOnContent)
                {
                    return(new SnapshotSpan());
                }
                int num2 = state2 == XamlAnalyzer.ParseState.EmptyTagEnd ? 2 : 1;
                ClassificationPosition startPosition = new ClassificationPosition()
                {
                    CurrentLine      = spanToTokenize,
                    CurrentSpanList  = list1,
                    CurrentSpanIndex = startSpanIndex
                };
                foreach (ClassificationPosition classificationPosition in this.statefulClassifier.ScanBackward(startPosition))
                {
                    num2 += XamlAnalyzer.TagDepthDelta(false, classificationPosition.CurrentSpan.ClassificationType);
                    if (num2 == 0)
                    {
                        startPosition = classificationPosition;
                        break;
                    }
                }
                if (num2 != 0)
                {
                    return(new SnapshotSpan());
                }
                int start = startPosition.CurrentSpan.Span.Start;
                foreach (ClassificationPosition classificationPosition in this.statefulClassifier.ScanForward(startPosition))
                {
                    if (classificationPosition.CurrentSpan.ClassificationType == XamlAnalyzer.ClassEndTag)
                    {
                        return(new SnapshotSpan(classificationPosition.Snapshot, new Span(start, classificationPosition.CurrentSpan.Span.End - start)));
                    }
                }
            }
            return(new SnapshotSpan());
        }