Exemplo n.º 1
0
#pragma warning restore 67

        public IList <ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
        {
            PreCondition.AssertNotNull(span, nameof(span));

            ITextSnapshot textSnapshot      = span.Snapshot;
            ITextBuffer   textBuffer        = textSnapshot.TextBuffer;
            ITextVersion  textVersion       = textSnapshot.Version;
            int           textVersionNumber = textVersion.VersionNumber;

            if (!this.textSnapshotClassifications.TryGet(textBuffer, textVersionNumber, out IReadOnlyList <ClassificationSpan> classificationSpans))
            {
                PkgdefDocument parsedDocument = PkgdefDocument.Parse(textSnapshot.GetText());

                List <ClassificationSpan> spans = new List <ClassificationSpan>();
                foreach (PkgdefSegment segment in parsedDocument.GetSegments())
                {
                    switch (segment.GetSegmentType())
                    {
                    case PkgdefSegmentType.LineComment:
                        spans.Add(PkgdefClassifier.CreateClassificationSpan(textSnapshot, segment, this.commentClassificationType));
                        break;

                    case PkgdefSegmentType.RegistryKeyPath:
                        spans.Add(PkgdefClassifier.CreateClassificationSpan(textSnapshot, segment, this.registryKeyRelativePathClassificationType));
                        break;

                    case PkgdefSegmentType.RegistryKeyDataItem:
                        PkgdefRegistryKeyDataItemSegment registryKeyDataItemSegment = (PkgdefRegistryKeyDataItemSegment)segment;
                        spans.Add(PkgdefClassifier.CreateClassificationSpan(textSnapshot, registryKeyDataItemSegment.GetNameSegment(), this.registryKeyDataItemNameClassificationType));
                        break;
                    }
                }
                classificationSpans = spans;
                this.textSnapshotClassifications.Set(textBuffer, textVersionNumber, classificationSpans);
            }

            return(classificationSpans
                   .Where((ClassificationSpan classificationSpan) => classificationSpan.Span.IntersectsWith(span.Span))
                   .ToList());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parse a PkgdefDocument from the provided text.
        /// </summary>
        /// <param name="text">The text to parse.</param>
        /// <returns>The parsed PkgdefDocument.</returns>
        public static PkgdefDocument Parse(string text)
        {
            PreCondition.AssertNotNull(text, nameof(text));

            return(PkgdefDocument.Parse(Iterator.Create(text)));
        }