예제 #1
0
        internal static IEnumerator <ClassificationSpan> ForwardClassificationSpanEnumerator(PythonClassifier classifier, SnapshotPoint startPoint)
        {
            var startLine = startPoint.GetContainingLine();
            int curLine   = startLine.LineNumber;

            if (startPoint > startLine.End)
            {
                // May occur if startPoint is between \r and \n
                startPoint = startLine.End;
            }
            var tokens = classifier.GetClassificationSpans(new SnapshotSpan(startPoint, startLine.End));

            for (; ;)
            {
                for (int i = 0; i < tokens.Count; ++i)
                {
                    yield return(tokens[i]);
                }

                // indicate the line break
                yield return(null);

                ++curLine;
                if (curLine < startPoint.Snapshot.LineCount)
                {
                    var nextLine = startPoint.Snapshot.GetLineFromLineNumber(curLine);
                    tokens = classifier.GetClassificationSpans(nextLine.Extent);
                }
                else
                {
                    break;
                }
            }
        }
예제 #2
0
        internal static IEnumerator <ClassificationSpan> ReverseClassificationSpanEnumerator(PythonClassifier classifier, SnapshotPoint startPoint)
        {
            var startLine = startPoint.GetContainingLine();
            int curLine   = startLine.LineNumber;
            var tokens    = classifier.GetClassificationSpans(new SnapshotSpan(startLine.Start, startPoint));

            for (; ;)
            {
                for (int i = tokens.Count - 1; i >= 0; i--)
                {
                    yield return(tokens[i]);
                }

                // indicate the line break
                yield return(null);

                curLine--;
                if (curLine >= 0)
                {
                    var prevLine = startPoint.Snapshot.GetLineFromLineNumber(curLine);
                    tokens = classifier.GetClassificationSpans(prevLine.Extent);
                }
                else
                {
                    break;
                }
            }
        }
        private static bool IsCommentChar(SnapshotPoint prevPoint, PythonClassifier classifier)
        {
            IList <ClassificationSpan> spans;

            spans = classifier.GetClassificationSpans(new SnapshotSpan(prevPoint, 1));
            if (spans.Count == 1 && spans[0].ClassificationType.IsOfType(PredefinedClassificationTypeNames.Comment))
            {
                return(true);
            }
            return(false);
        }
예제 #4
0
 private static bool IsCommentChar(SnapshotPoint prevPoint, PythonClassifier classifier) {
     IList<ClassificationSpan> spans;
     spans = classifier.GetClassificationSpans(new SnapshotSpan(prevPoint, 1));
     if (spans.Count == 1 && spans[0].ClassificationType.IsOfType(PredefinedClassificationTypeNames.Comment)) {
         return true;
     }
     return false;
 }