Beispiel #1
0
#pragma warning restore 67

        /// <summary>
        /// This method scans the given SnapshotSpan for potential matches for this classification.
        /// </summary>
        /// <param name="span">The span currently being classified.</param>
        /// <returns>A list of ClassificationSpans that represent spans identified to be of this classification.</returns>
        public IList <ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
        {
            // TODO this is an inefficient call to GetMultiLineComments each time!
            var multiLineComments = GetMultiLineComments(span.Snapshot);

            var compiler = new Compiler();

            compiler.Options.Add("number", "float");

            // Use Cobra's own tokenizer
            var tokCobra = new VisualCobraTokenizer
            {
                TypeProvider         = compiler,
                WillReturnComments   = true,
                WillReturnDirectives = true
            };

            Node.SetCompiler(compiler);
            tokCobra.StartSource(span.GetText());

            var classifications = GetClassificationsFromCobraTokenizer(span, tokCobra);

            // Add classification spans for indent errors
            classifications.AddRange(GetIndentErrorSpans(span));

            // Remove classification spans that are (partly) inside multi-line comment spans
            var multiLineCommentsInCurrentSpan = multiLineComments.Where(span.IntersectsWith).ToList();

            classifications.RemoveAll(
                cs => multiLineCommentsInCurrentSpan.AsParallel().Any(mlc => mlc.IntersectsWith(cs.Span.Span)));

            // Add all comment spans
            classifications.AddRange(
                multiLineCommentsInCurrentSpan.Select(
                    mlc => new ClassificationSpan(new SnapshotSpan(span.Snapshot, mlc), _cobraCommentClassificationType)));

            return(classifications);
        }
Beispiel #2
0
#pragma warning restore 67

        /// <summary>
        /// This method scans the given SnapshotSpan for potential matches for this classification.
        /// </summary>
        /// <param name="span">The span currently being classified.</param>
        /// <returns>A list of ClassificationSpans that represent spans identified to be of this classification.</returns>
        public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
        {
            // TODO this is an inefficient call to GetMultiLineComments each time!
            var multiLineComments = GetMultiLineComments(span.Snapshot);

            var compiler = new Compiler();
            compiler.Options.Add("number", "float");

            // Use Cobra's own tokenizer
            var tokCobra = new VisualCobraTokenizer
            {
                TypeProvider = compiler,
                WillReturnComments = true,
                WillReturnDirectives = true
            };

            Node.SetCompiler(compiler);
            tokCobra.StartSource(span.GetText());

            var classifications = GetClassificationsFromCobraTokenizer(span, tokCobra);

            // Add classification spans for indent errors
            classifications.AddRange(GetIndentErrorSpans(span));

            // Remove classification spans that are (partly) inside multi-line comment spans
            var multiLineCommentsInCurrentSpan = multiLineComments.Where(span.IntersectsWith).ToList();
            classifications.RemoveAll(
                cs => multiLineCommentsInCurrentSpan.AsParallel().Any(mlc => mlc.IntersectsWith(cs.Span.Span)));

            // Add all comment spans
            classifications.AddRange(
                multiLineCommentsInCurrentSpan.Select(
                    mlc => new ClassificationSpan(new SnapshotSpan(span.Snapshot, mlc), _cobraCommentClassificationType)));

            return classifications;
        }