Пример #1
0
        public LineCommentInfoTest()
        {
            this.commentClass = new StubIClassificationType();
            this.commentClass.ClassificationGet = () => "comment";
            this.commentClass.IsOfTypeString = s => string.Equals(s, "comment");

            this.wholeLineCommentClassifier = new StubIClassifier();
            this.wholeLineCommentClassifier.GetClassificationSpansSnapshotSpan = s =>
            {
                // Find the "//"... Note: doesn't look for "''" (VB) or "/*"
                // (multi-line).  That might need to change when we start
                // supporting more comment styles.
                var markerStart = s.GetText().IndexOf("//");
                Assert.IsTrue(markerStart >= 0);
                var commentSpan = new SnapshotSpan(s.Start + markerStart, s.End);
                var span = new ClassificationSpan(commentSpan, this.commentClass);

                var list = new List<ClassificationSpan>();
                list.Add(span);
                return list;
            };

            this.defaultOptions = new SimpleEditorOptions();
            this.defaultOptions.SetOptionValue("Tabs/ConvertTabsToSpaces", true);
            this.defaultOptions.SetOptionValue("Tabs/TabSize", 4);
        }
Пример #2
0
        public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
        {
            List<ClassificationSpan> spans = new List<ClassificationSpan>();
            if (!WESettings.Instance.Css.SyncVendorValues)
                return spans;

            foreach (Declaration dec in Cache.Where(d => d.PropertyName.Text.Length > 0 && span.Start <= d.Start && span.End >= d.AfterEnd))
            {
                if (dec.IsVendorSpecific())
                {
                    var ss = new SnapshotSpan(span.Snapshot, dec.Start, dec.Length);
                    var s = new ClassificationSpan(ss, _decClassification);
                    spans.Add(s);
                }

                if (dec.Semicolon == null)
                    continue;

                int start = dec.Colon.AfterEnd;
                int length = dec.AfterEnd - start;
                if (span.Snapshot.Length > start + length)
                {
                    var ss2 = new SnapshotSpan(span.Snapshot, start, length);
                    var s2 = new ClassificationSpan(ss2, _valClassification);
                    spans.Add(s2);
                }
            }

            return spans;
        }
        private List <ClassificationSpan> GetKeywordMatchList(SnapshotSpan span)
        {
            var result = new List <ClassificationSpan>();

            var originalText = span.GetText();
            var words        = originalText.Split(delimiterChars);

            foreach (var word in words)
            {
                foreach (var keyword in keywords)
                {
                    if (word == keyword)
                    {
                        // TODO:複数個同じキーワードがあった場合の対応
                        var index = originalText.IndexOf(keyword);
                        if (index >= 0)
                        {
                            var start = span.Start.Position + index;

                            var snapshotSpan       = new SnapshotSpan(span.Snapshot, new Span(start, keyword.Length));
                            var classificationSpan = new ClassificationSpan(snapshotSpan, categoryMap[PredefinedClassificationTypeNames.Keyword]);
                            result.Add(classificationSpan);
                        }
                    }
                }
            }
            return(result);
        }
        private ClassificationSpan GetRootSpan(ITextSnapshot snapshot)
        {
            const int countByPage = 200;

            int totalPages = (snapshot.Length + countByPage - 1) / countByPage;

            for (int index = 0; index < totalPages; index++)
            {
                int fromIndex = Math.Max(0, (index - 1) * countByPage);

                int otherLength = snapshot.Length - fromIndex;
                int length      = Math.Min(2 * countByPage, otherLength);

                var spans = _classifier.GetClassificationSpans(new SnapshotSpan(snapshot, fromIndex, length));

                ClassificationSpan xmlRootSpan = spans.Where((s, i) =>
                                                             i > 0 &&
                                                             s.ClassificationType.IsOfType(xmlClassificationXmlName) &&
                                                             spans[i - 1].ClassificationType.IsOfType(xmlClassificationDelimiter) &&
                                                             spans[i - 1].Span.GetText() == "<"
                                                             ).FirstOrDefault();

                if (xmlRootSpan != null)
                {
                    return(xmlRootSpan);
                }
            }

            return(null);
        }
        private static SnapshotSpan?GetExtent(ClassificationSpan delimiterBefore, ClassificationSpan delimiterAfter, ITextSnapshot snapshot, int cursorPosition)
        {
            SnapshotSpan?extentTemp = null;

            if (delimiterBefore != null &&
                delimiterAfter != null &&
                delimiterBefore.ClassificationType.IsOfType(xmlClassificationDelimiter) &&
                delimiterAfter.ClassificationType.IsOfType(xmlClassificationDelimiter)
                )
            {
                var tempSpan = new SnapshotSpan(delimiterBefore.Span.End, delimiterAfter.Span.Start);

                if (string.IsNullOrWhiteSpace(tempSpan.GetText()))
                {
                    //extentTemp = new SnapshotSpan(delimiterBefore.Span.End, 0);

                    extentTemp = new SnapshotSpan(snapshot, cursorPosition, 0);
                }
                else
                {
                    int spacesStart = tempSpan.GetText().TakeWhile(ch => char.IsWhiteSpace(ch)).Count();
                    int spacesEnd   = tempSpan.GetText().Reverse().TakeWhile(ch => char.IsWhiteSpace(ch)).Count();

                    extentTemp = new SnapshotSpan(delimiterBefore.Span.End.Add(spacesStart), delimiterAfter.Span.Start.Add(-spacesEnd));
                }
            }

            return(extentTemp);
        }
Пример #6
0
        /// <summary>
        /// tries to close region
        /// </summary>
        /// <param name="parser">parser</param>
        /// <returns>whether region was closed</returns>
        protected override bool TryComplete(TextRegion r, SnapshotParser parser)
        {
            ClassificationSpan span  = parser.CurrentSpan;
            SnapshotPoint      point = parser.CurrentPoint;

            if (span != null)
            {
                string text = span.Span.GetText();
                if (span.ClassificationType.Classification == "punctuation")
                {
                    char c = point.GetChar();
                    //text can be "};", not just "}"
                    if (r.RegionType == TextRegionType.Block && c == '}' ||
                        r.RegionType == TextRegionType.Array && c == ']')
                    {
                        r.EndPoint = span.Span.Start + 1;
                    }
                }
                else if (span.ClassificationType.Classification == "comment" && r.RegionType == TextRegionType.Region)
                {
                    Match m = RegionEndRegex.Match(text);
                    if (m.Success)
                    {
                        r.EndPoint = span.Span.End;
                    }
                }
            }
            return(r.Complete);
        }
        private void AddTokenClassifications(ITextBuffer buffer, SnapshotSpan span, List <ClassificationSpan> classifications, Span?lastClassificationSpan, IClassificationType gapType)
        {
            List <ClassificationInfo> spans = null;

            if (!buffer.Properties.TryGetProperty <List <ClassificationInfo> >(BufferProperties.TokenSpans, out spans) || spans == null)
            {
                return;
            }

            foreach (var current in spans)
            {
                if (current.Start + current.Length < span.Start)
                {
                    continue;
                }

                if (current.Start > span.End)
                {
                    break;
                }

                if (current.Start + current.Length > buffer.CurrentSnapshot.Length)
                {
                    continue;
                }

                var snapshotSpan       = new SnapshotSpan(span.Snapshot, current.Start, current.Length);
                var classificationSpan = new ClassificationSpan(snapshotSpan, current.ClassificationType);

                FillClassificationGap(classifications, lastClassificationSpan, snapshotSpan, buffer.CurrentSnapshot, gapType);
                lastClassificationSpan = snapshotSpan;

                classifications.Add(classificationSpan);
            }
        }
Пример #8
0
 private bool FindMatchingOpenTag(List <ClassificationSpan> sortedTags, int indexTag, ITextSnapshot snapshot, out SnapshotSpan pairSpan)
 {
     pairSpan = new SnapshotSpan(snapshot, 1, 1);
     try
     {
         ClassificationSpan currentTag = sortedTags[indexTag];
         ITextSnapshotLine  line       = currentTag.Span.Start.GetContainingLine();
         int lineNumber = line.LineNumber;
         int nested     = 0;
         for (int i = indexTag - 1; i >= 0; i--)
         {
             var openTag = sortedTags[i];
             if (openTag.ClassificationType.IsOfType(ColorizerConstants.XSharpBraceOpenFormat))
             {
                 nested--;
                 if (nested < 0)
                 {
                     pairSpan = new SnapshotSpan(snapshot, openTag.Span);
                     return(true);
                 }
             }
             else
             {
                 nested++;
             }
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e.Message);
     }
     //
     return(false);
 }
Пример #9
0
        public static bool FindTest(this SnapshotSpan extent, ITextView view, IClassifier classifier, out int lineNumber)
        {
            lineNumber = view.TextSnapshot.GetLineNumberFromPosition(extent.Start) + 1;

            IList <ClassificationSpan> classifiers = classifier.GetClassificationSpans(extent);

            ClassificationSpan cspan = classifiers.FirstOrDefault(c =>
                                                                  c.ClassificationType.Classification.Contains("PowerShellCommand"));

            bool   found = false;
            string text  = cspan?.Span.GetText();

            if (string.Equals(text, "describe", StringComparison.InvariantCultureIgnoreCase))
            {
                found = true;
            }
            else if (string.Equals(text, "context", StringComparison.InvariantCultureIgnoreCase))
            {
                found = true;
            }
            else if (string.Equals(text, "it", StringComparison.InvariantCultureIgnoreCase))
            {
                found = true;
            }
            return(found);
        }
Пример #10
0
        /// <summary>
        /// "Mark" a Token, specifying it's type and the span it covers
        /// </summary>
        /// <param name="token"></param>
        /// <param name="snapshot"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        private ClassificationSpan Token2ClassificationSpan(IToken token, ITextSnapshot snapshot, IClassificationType type)
        {
            TextSpan           tokenSpan = new TextSpan(token.StartIndex, token.StopIndex - token.StartIndex + 1);
            ClassificationSpan span      = tokenSpan.ToClassificationSpan(snapshot, type);

            return(span);
        }
Пример #11
0
        public IList <ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
        {
            List <ClassificationSpan> result = new List <ClassificationSpan>();

            this.UpdateBlocks(span, true);
            int position = span.Start.Position;
            int index    = this.FindBlockIndex(span, span.Start.Position, false);

            while (index < this.trackedBlocks.Count)
            {
                TrackedBlock block = this.trackedBlocks[index];
                this.CacheBlock(span, block);
                int classificationStartPosition = block.Block.GetStartPoint(span.Snapshot);
                int classificationIndex         = 0;
                while (classificationIndex < block.CachedClassifications.Count && position < span.End.Position)
                {
                    ClassificationSpan classification = block.CachedClassifications[classificationIndex];
                    int classificationEndPosition     = classificationStartPosition + classification.Span.Length;
                    if (span.OverlapsWith(Span.FromBounds(classificationStartPosition, classificationEndPosition)))
                    {
                        result.Add(classification);
                    }
                    ++classificationIndex;
                    classificationStartPosition = classificationEndPosition;
                    if (classificationEndPosition >= span.End.Position)
                    {
                        return(result);
                    }
                }
                ++index;
            }
            return(result);
        }
Пример #12
0
        private Span GetSyntaxSpan(out string text)
        {
            int position = _view.Caret.Position.BufferPosition.Position;

            text = string.Empty;

            if (position == 0)
            {
                return(_emptySpan);
            }

            ITextSnapshotLine  line  = _view.TextBuffer.CurrentSnapshot.GetLineFromPosition(position);
            ClassificationSpan last  = _classifier.GetClassificationSpans(line.Extent).LastOrDefault();
            SnapshotPoint      start = last?.Span.End ?? line.Start;

            if (start > position)
            {
                return(_emptySpan);
            }

            text = line.Snapshot.GetText(start, position - start).Trim();
            int offset = position - start - text.Length;

            return(Span.FromBounds(start + offset, position));
        }
        public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
        {
            List<ClassificationSpan> spans = new List<ClassificationSpan>();

            if (!WESettings.Instance.Css.SyncBase64ImageValues)
                return spans;

            foreach (Declaration dec in Cache.Where(d => d.PropertyName.Text.EndsWith("background-image", StringComparison.OrdinalIgnoreCase) && span.Start <= d.Start && span.End >= d.AfterEnd))
            {
                if (dec.PropertyName.Text.StartsWith("*background", StringComparison.OrdinalIgnoreCase))
                {
                    var ss = new SnapshotSpan(span.Snapshot, dec.Start, dec.Length);
                    var s = new ClassificationSpan(ss, _decClassification);
                    spans.Add(s);
                }

                if (dec.Semicolon == null)
                    continue;

                int start = dec.Colon.AfterEnd;
                int length = dec.AfterEnd - start;
                if (span.Snapshot.Length > start + length)
                {
                    var ss2 = new SnapshotSpan(span.Snapshot, start, length);
                    var s2 = new ClassificationSpan(ss2, _valClassification);
                    spans.Add(s2);
                }
            }

            return spans;
        }
Пример #14
0
        internal static void AddTokenClassifications(ITextBuffer buffer, SnapshotSpan span, List <ClassificationSpan> classifications, Span?lastClassificationSpan, IClassificationType gapType)
        {
            var spans = (List <ClassificationInfo>)buffer.Properties.GetProperty(BufferProperties.TokenSpans);

            foreach (var current in spans)
            {
                if (current.Start + current.Length < span.Start)
                {
                    continue;
                }

                if (current.Start > span.End)
                {
                    break;
                }

                if (current.Start + current.Length > buffer.CurrentSnapshot.Length)
                {
                    continue;
                }

                var snapshotSpan       = new SnapshotSpan(span.Snapshot, current.Start, current.Length);
                var classificationSpan = new ClassificationSpan(snapshotSpan, current.ClassificationType);
                FillClassificationGap(classifications, lastClassificationSpan, snapshotSpan, buffer.CurrentSnapshot, gapType);
                lastClassificationSpan = snapshotSpan;
                classifications.Add(classificationSpan);
            }
        }
Пример #15
0
        public IList <ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
        {
            List <ClassificationSpan> spans = new List <ClassificationSpan>();

            if (!WESettings.GetBoolean(WESettings.Keys.SyncVendorValues) || !EnsureInitialized())
            {
                return(spans);
            }

            var declarations = Cache.Where(d => span.End <= d.AfterEnd && d.Start >= span.Start);

            foreach (Declaration dec in Cache.Where(d => d.PropertyName.Text.Length > 0 && span.Snapshot.Length >= d.AfterEnd))
            {
                if (dec.IsVendorSpecific())
                {
                    var ss = new SnapshotSpan(span.Snapshot, dec.Start, dec.Length);
                    var s  = new ClassificationSpan(ss, _decClassification);
                    spans.Add(s);
                }

                int start  = dec.Colon.AfterEnd;
                int length = dec.AfterEnd - start;
                if (span.Snapshot.Length > start + length)
                {
                    var ss2 = new SnapshotSpan(span.Snapshot, start, length);
                    var s2  = new ClassificationSpan(ss2, _valClassification);
                    spans.Add(s2);
                }
            }

            return(spans);
        }
        public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
        {
            List<ClassificationSpan> spans = new List<ClassificationSpan>();
            if (!WESettings.GetBoolean(WESettings.Keys.SyncVendorValues) || !EnsureInitialized())
                return spans;

            var declarations = Cache.Where(d => span.End <= d.AfterEnd && d.Start >= span.Start);
            foreach (Declaration dec in Cache.Where(d => d.PropertyName.Text.Length > 0 && span.Snapshot.Length >= d.AfterEnd))
            {
                if (dec.IsVendorSpecific())
                {
                    var ss = new SnapshotSpan(span.Snapshot, dec.Start, dec.Length);
                    var s = new ClassificationSpan(ss, _decClassification);
                    spans.Add(s);
                }

                int start = dec.Colon.AfterEnd;
                int length = dec.AfterEnd - start;
                if (span.Snapshot.Length > start + length)
                {
                    var ss2 = new SnapshotSpan(span.Snapshot, start, length);
                    var s2 = new ClassificationSpan(ss2, _valClassification);
                    spans.Add(s2);
                }
            }

            return spans;
        }
Пример #17
0
        private bool IsCompletionSupported(SnapshotPoint triggerLocation, out string attributeName, out SnapshotSpan applicapleTo)
        {
            applicapleTo  = new SnapshotSpan(triggerLocation, 0);
            attributeName = null;

            if (!IsXmlAttributeValue(triggerLocation))
            {
                return(false);
            }

            applicapleTo = triggerLocation.GetContainingLine().Extent;
            string line = applicapleTo.GetText();

            IList <ClassificationSpan> spans         = _classifier.GetClassificationSpans(applicapleTo);
            ClassificationSpan         attrValueSpan = spans.FirstOrDefault(s => s.Span.Start <= triggerLocation && s.Span.End >= triggerLocation && s.ClassificationType.IsOfType("XML Attribute Value"));
            int valueSpanIndex = spans.IndexOf(attrValueSpan);

            if (attrValueSpan == null || valueSpanIndex < 3)
            {
                return(false);
            }

            applicapleTo = attrValueSpan.Span;
            ClassificationSpan attrNameSpan = spans.ElementAt(valueSpanIndex - 3);

            if (!attrNameSpan.ClassificationType.IsOfType("XML Attribute"))
            {
                return(false);
            }

            attributeName = attrNameSpan.Span.GetText();

            return(true);
        }
Пример #18
0
 IList<ClassificationSpan> IClassifier.GetClassificationSpans(SnapshotSpan toClassifySpan)
 {
     List<ClassificationSpan> list = new List<ClassificationSpan>();
     if (_document.IsMassiveChangeInProgress)
     {
         return list;
     }
     EnsureInitialized();
     ITextSnapshot snapshot = toClassifySpan.Snapshot;
     for (int i = GetFirstClassificationDataAfterOrAtPosition(toClassifySpan.Start, snapshot); i < _spansToClassify.Count; i++)
     {
         ClassificationData classificationData = _spansToClassify[i];
         SnapshotSpan span = classificationData.TrackingSpan.GetSpan(snapshot);
         if (span.Start >= toClassifySpan.End)
         {
             break;
         }
         Microsoft.VisualStudio.Text.Span span2 = Microsoft.VisualStudio.Text.Span.FromBounds(Math.Max(span.Start, toClassifySpan.Start), Math.Min(span.End, toClassifySpan.End));
         SnapshotSpan arg_C4_0 = new SnapshotSpan(snapshot, span2);
         IClassificationType classificationType = classificationData.ClassificationType;
         ClassificationSpan item = new ClassificationSpan(arg_C4_0, classificationType);
         list.Add(item);
     }
     return list;
 }
Пример #19
0
        public static CompletionAnalysis Make(IList <ClassificationSpan> classifications, ClassificationSpan start,
                                              Span loc, ITextSnapshot snapshot, ITrackingSpan span, ITextBuffer buffer, bool isSpace)
        {
            if (classifications.Count == 1)
            {
                return(new ImportCompletionAnalysis(String.Empty, loc.Start, span, buffer));
            }

            ClassificationSpan imp = null;

            for (int i = 1; i < classifications.Count; i++)
            {
                if (IsKeyword(classifications[i], "import"))
                {
                    imp = classifications[i];
                }
            }

            var end = classifications[classifications.Count - 1];

            if (imp == null)
            {
                if (isSpace)
                {
                    return(EmptyCompletionContext);
                }

                // from [completion]
                //  or
                // from xxx.[completion]
                //  or
                // from xxx[Ctrl-Space completion]
                return(new ImportCompletionAnalysis(GetText(snapshot, start, end, true), loc.Start, span, buffer));
            }

            // from xyz import [completion]
            //  or
            // from xyz import abc[Ctrl-Space completion]
            var nsText = GetText(snapshot, start, imp, false);

            string itemText;

            if (Object.ReferenceEquals(end, imp))
            {
                itemText = String.Empty;
            }
            else
            {
                if (isSpace)
                {
                    return(EmptyCompletionContext);
                }

                var itemLen  = end.Span.End - imp.Span.End - 1;
                var itemSpan = new SnapshotSpan(snapshot, imp.Span.End + 1, itemLen);
                itemText = itemSpan.GetText();
            }

            return(new FromImportCompletionAnalysis(itemText, loc.Start, span, buffer, nsText));
        }
        private void AddClassificationSpan(List <ClassificationSpan> result, SnapshotPoint startPoint, SnapshotPoint endPoint)
        {
            SnapshotSpan       snapshotSpan       = new SnapshotSpan(startPoint, endPoint);
            ClassificationSpan classificationSpan = new ClassificationSpan(snapshotSpan, this.classificationType);

            result.Add(classificationSpan);
        }
Пример #21
0
        public IList <ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
        {
            List <ClassificationSpan> spans = new List <ClassificationSpan>();

            if (!WESettings.Instance.Css.SyncBase64ImageValues)
            {
                return(spans);
            }

            foreach (Declaration dec in Cache.Where(d => d.PropertyName.Text.EndsWith("background-image", StringComparison.OrdinalIgnoreCase) && span.Start <= d.Start && span.End >= d.AfterEnd))
            {
                if (dec.PropertyName.Text.StartsWith("*background", StringComparison.OrdinalIgnoreCase))
                {
                    var ss = new SnapshotSpan(span.Snapshot, dec.Start, dec.Length);
                    var s  = new ClassificationSpan(ss, _decClassification);
                    spans.Add(s);
                }

                if (dec.Semicolon == null)
                {
                    continue;
                }

                int start  = dec.Colon.AfterEnd;
                int length = dec.AfterEnd - start;
                if (span.Snapshot.Length > start + length)
                {
                    var ss2 = new SnapshotSpan(span.Snapshot, start, length);
                    var s2  = new ClassificationSpan(ss2, _valClassification);
                    spans.Add(s2);
                }
            }

            return(spans);
        }
Пример #22
0
        /// <summary>
        /// parses input buffer, searches for region start
        /// </summary>
        /// <param name="parser"></param>
        /// <returns>created region or null</returns>
        public override TextRegion TryCreateRegion(SnapshotParser parser)
        {
            ClassificationSpan span  = parser.CurrentSpan;
            SnapshotPoint      point = parser.CurrentPoint;

            if (span != null)
            {
                switch (span.ClassificationType.Classification)
                {
                case "punctuation":
                    char c = point.GetChar();
                    switch (c)
                    {
                    case '{':
                        return(new TextRegion(span.Span.Start, TextRegionType.Block));

                    case '[':
                        return(new TextRegion(span.Span.Start, TextRegionType.Array));
                    }
                    break;

                case "comment":
                    return(ParseComment(parser, RegionStartRegex, RegionEndRegex));
                }
            }
            return(null);
        }
Пример #23
0
        private void CreateNormalizedSpans()
        {
            Int32          startCharacterIndex = _startCharacterIndex;
            Int32          length = _text.Length;
            NormalizedSpan span   = new NormalizedSpan("", "_gap_", _startCharacterIndex, TextFormattingRunProperties.DefaultProperties);

            _startNode = span;
            for (Int32 i = 0; i < _classificationSpanList.Count; i++)
            {
                ClassificationSpan span2 = _classificationSpanList[i];
                Span span3 = span2.Span();
                if (span3.Start >= (_startCharacterIndex + length))
                {
                    break;
                }
                Int32 num4 = span3.Start - startCharacterIndex;
                if (num4 > 0)
                {
                    NormalizedSpan span4 = new NormalizedSpan(_text.Substring(startCharacterIndex - _startCharacterIndex, span3.Start - startCharacterIndex), "_gap_", startCharacterIndex, TextFormattingRunProperties.DefaultProperties);
                    span = span.AddNode(span4);
                    startCharacterIndex += num4;
                }
                else if (num4 < 0)
                {
                    Int32 num5 = span3.Length + num4;
                    if (num5 <= 0)
                    {
                        continue;
                    }
                    span3 = new Span(startCharacterIndex, num5);
                }
                if (span3.Length > 0)
                {
                    Int32 num6 = startCharacterIndex - _startCharacterIndex;
                    TextFormattingRunProperties textProperties = _classificationFormatMap.GetTextProperties(span2.Classification);
                    if ((span3.Length + num6) > length)
                    {
                        Int32          num7  = length - num6;
                        NormalizedSpan span5 = new NormalizedSpan(_text.Substring(span3.Start - _startCharacterIndex, num7), span2.Classification, span3.Start, textProperties);
                        span = span.AddNode(span5);
                        startCharacterIndex = _startCharacterIndex + length;
                        break;
                    }
                    NormalizedSpan span6 = new NormalizedSpan(_text.Substring(span3.Start - _startCharacterIndex, span3.Length), span2.Classification, span3.Start, textProperties);
                    span = span.AddNode(span6);
                    startCharacterIndex += span3.Length;
                }
            }
            if (startCharacterIndex < (_startCharacterIndex + length))
            {
                Int32          num8  = length - (startCharacterIndex - _startCharacterIndex);
                NormalizedSpan span7 = new NormalizedSpan(_text.Substring(startCharacterIndex - _startCharacterIndex, num8), "_gap_", startCharacterIndex, TextFormattingRunProperties.DefaultProperties);
                span = span.AddNode(span7);
            }
            if (_startNode.Next != null)
            {
                _startNode          = _startNode.Next;
                _startNode.Previous = null;
            }
        }
Пример #24
0
        IList <ClassificationSpan> IClassifier.GetClassificationSpans(SnapshotSpan toClassifySpan)
        {
            List <ClassificationSpan> list = new List <ClassificationSpan>();

            if (_document.IsMassiveChangeInProgress)
            {
                return(list);
            }
            EnsureInitialized();
            ITextSnapshot snapshot = toClassifySpan.Snapshot;

            for (int i = GetFirstClassificationDataAfterOrAtPosition(toClassifySpan.Start, snapshot); i < _spansToClassify.Count; i++)
            {
                ClassificationData classificationData = _spansToClassify[i];
                SnapshotSpan       span = classificationData.TrackingSpan.GetSpan(snapshot);
                if (span.Start >= toClassifySpan.End)
                {
                    break;
                }
                Microsoft.VisualStudio.Text.Span span2 = Microsoft.VisualStudio.Text.Span.FromBounds(Math.Max(span.Start, toClassifySpan.Start), Math.Min(span.End, toClassifySpan.End));
                SnapshotSpan        arg_C4_0           = new SnapshotSpan(snapshot, span2);
                IClassificationType classificationType = classificationData.ClassificationType;
                ClassificationSpan  item = new ClassificationSpan(arg_C4_0, classificationType);
                list.Add(item);
            }
            return(list);
        }
Пример #25
0
        static List <ClassificationSpan> Merge(List <ClassificationSpan> list)
        {
            if (list.Count <= 1)
            {
                return(list);
            }

            var prev = list[0];
            int read = 1, write = 0;

            for (; read < list.Count; read++)
            {
                var a = list[read];
                if (prev.ClassificationType == a.ClassificationType && prev.Span.End == a.Span.Start)
                {
                    list[write] = prev = new ClassificationSpan(new SnapshotSpan(prev.Span.Start, a.Span.End), prev.ClassificationType);
                }
                else
                {
                    prev          = a;
                    list[++write] = a;
                }
            }
            write++;
            if (list.Count != write)
            {
                list.RemoveRange(write, list.Count - write);
            }

            return(list);
        }
        // This is called on a background thread.
        public async Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken)
        {
            SnapshotPoint?triggerPoint = session.GetTriggerPoint(_buffer.CurrentSnapshot);

            if (triggerPoint != null)
            {
                ITextSnapshotLine          line      = triggerPoint.Value.GetContainingLine();
                IList <ClassificationSpan> spans     = _classifier.GetClassificationSpans(line.Extent);
                ClassificationSpan         attrValue = spans.FirstOrDefault(s => s.ClassificationType.IsOfType("XML Attribute Value") && s.Span.Contains(triggerPoint.Value.Position));

                if (attrValue != null)
                {
                    ITrackingSpan id = _buffer.CurrentSnapshot.CreateTrackingSpan(attrValue.Span, SpanTrackingMode.EdgeInclusive);

                    var fileName = VsctCompletionSource.GetFileName(attrValue.Span.GetText());

                    // Image exist
                    if (!string.IsNullOrEmpty(fileName))
                    {
                        await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                        var img = new Image
                        {
                            Source    = new BitmapImage(new Uri(fileName)),
                            MaxHeight = 500
                        };

                        return(new QuickInfoItem(id, img));
                    }
                }
            }

            return(null);
        }
Пример #27
0
 private bool FindMatchingCloseTag(List <ClassificationSpan> sortedTags, int indexTag, ITextSnapshot snapshot, out SnapshotSpan pairSpan)
 {
     pairSpan = new SnapshotSpan(snapshot, 1, 1);
     try
     {
         ClassificationSpan currentTag = sortedTags[indexTag];
         ITextSnapshotLine  line       = currentTag.Span.Start.GetContainingLine();
         int lineNumber = line.LineNumber;
         int nested     = 0;
         for (int i = indexTag + 1; i < sortedTags.Count; i++)
         {
             var closeTag = sortedTags[i];
             if (closeTag.ClassificationType.IsOfType(ColorizerConstants.XSharpKwCloseFormat))
             {
                 nested--;
                 if (nested < 0)
                 {
                     pairSpan = new SnapshotSpan(snapshot, closeTag.Span);
                     return(true);
                 }
             }
             else
             {
                 nested++;
             }
         }
     }
     catch (Exception e)
     {
         XSettings.LogException(e, "FindMatchingCloseTag failed");
     }
     //
     return(false);
 }
        public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span) {
            var result = new List<ClassificationSpan>();
            
            var semanticModelResult = SemanticModelService.SemanticModelResult;
            if(semanticModelResult == null) {
                return result;
            }

            var classificationType = ClassificationTypeRegistryService.GetClassificationType(ClassificationTypeNames.DeadCode);

            var extent      = TextExtent.FromBounds(span.Start.Position, span.End.Position);
            var diagnostics = semanticModelResult.CompilationUnit.Diagnostics;
            var candidates  = diagnostics.Where(diagnostic => diagnostic.Category == DiagnosticCategory.DeadCode)
                                         .Where(d => d.Location.Extent.IntersectsWith(extent)); 

            foreach (var diagnostic in candidates) {
                var diagnosticSpan = new SnapshotSpan(semanticModelResult.Snapshot, new Span(diagnostic.Location.Start, diagnostic.Location.Length));

                var classification = new ClassificationSpan(
                        diagnosticSpan.TranslateTo(span.Snapshot, SpanTrackingMode.EdgeExclusive),
                        classificationType);


                result.Add(classification);
            }
            
            return result;
        }
        private bool IsAllowed(SnapshotPoint triggerPoint, out ClassificationSpan classificationType)
        {
            var line  = triggerPoint.GetContainingLine().Extent;
            var spans = _classifier.GetClassificationSpans(line).Where(c => c.Span.Contains(triggerPoint.Position - 1));

            classificationType = spans.LastOrDefault();

            if (spans.Any(c => c.ClassificationType.IsOfType(PredefinedClassificationTypeNames.SymbolDefinition)))
            {
                return(true);
            }

            bool isComment = spans.Any(c => c.ClassificationType.IsOfType(PredefinedClassificationTypeNames.Comment));

            if (isComment)
            {
                return(false);
            }

            bool isString = spans.Any(c => c.ClassificationType.IsOfType(PredefinedClassificationTypeNames.String));

            if (isString)
            {
                return(false);
            }

            return(true);
        }
Пример #30
0
        private ClassificationSpan GetCurrentXmlAttributeName(ITextSnapshot snapshot, ClassificationSpan containingSpan, IList <ClassificationSpan> spans)
        {
            ClassificationSpan currentAttr = spans
                                             .Where(s => s.ClassificationType.IsOfType("XML Attribute") && s.Span.Start <= containingSpan.Span.Start)
                                             .OrderByDescending(s => s.Span.Start.Position)
                                             .FirstOrDefault();

            if (currentAttr != null)
            {
                return(currentAttr);
            }

            IList <ClassificationSpan> allSpans = _classifier.GetClassificationSpans(new SnapshotSpan(containingSpan.Span.Snapshot, 0, containingSpan.Span.Snapshot.Length));

            currentAttr = allSpans
                          .Where(s => s.ClassificationType.IsOfType("XML Name"))
                          .OrderByDescending(s => s.Span.Start.Position)
                          .FirstOrDefault();

            if (currentAttr != null)
            {
                return(currentAttr);
            }

            return(null);
        }
        public IList <ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
        {
            List <ClassificationSpan> spans = new List <ClassificationSpan>();

            foreach (Declaration dec in Cache.Where(d => d.PropertyName.Text.Length > 0 && span.Start <= d.Start && span.End >= d.AfterEnd))
            {
                if (dec.IsVendorSpecific())
                {
                    var ss = new SnapshotSpan(span.Snapshot, dec.Start, dec.Length);
                    var s  = new ClassificationSpan(ss, _decClassification);
                    spans.Add(s);
                }

                if (dec.Semicolon == null)
                {
                    continue;
                }

                int start  = dec.Colon.AfterEnd;
                int length = dec.AfterEnd - start;
                if (span.Snapshot.Length > start + length)
                {
                    var ss2 = new SnapshotSpan(span.Snapshot, start, length);
                    var s2  = new ClassificationSpan(ss2, _valClassification);
                    spans.Add(s2);
                }
            }

            return(spans);
        }
        public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span) {
            var result = new List<ClassificationSpan>();

            var parseResult = ParserService.ParseResult;
            if (parseResult == null) {
                return result;
            }

            var extent = TextExtent.FromBounds(span.Start.Position, span.End.Position);
            foreach(var token in parseResult.SyntaxTree.Tokens[extent, includeOverlapping: true]) {

                IClassificationType ct;
                _classificationMap.TryGetValue(token.Classification, out ct);
                if (ct == null) {
                    continue;
                }

                var tokenSpan = new SnapshotSpan(parseResult.Snapshot, new Span(token.Start, token.Length));
                
                var classification = new ClassificationSpan(
                        tokenSpan.TranslateTo(span.Snapshot, SpanTrackingMode.EdgeExclusive),
                        ct);

                result.Add(classification);
            }

            return result;
        }
Пример #33
0
        // TODO: track the snapshot version so we don't re-calculate for each signature?
        private List <ClassificationSpan> GetReplacementSpans(SnapshotPoint point)
        {
            IList <ClassificationSpan> spans = this.classifier.GetClassificationSpans(point.GetContainingLine().Extent);
            ClassificationSpan         span  = spans.FirstOrDefault(s => s.Span.Contains(point - 1));

            if (span == null || !IsReplacementSpan(span))
            {
                return(null);
            }

            // expand to find entire replacement block...
            int initialSpan = spans.IndexOf(span);
            int firstSpan   = initialSpan;
            int lastSpan    = initialSpan;

            while (firstSpan > 0 && !spans[firstSpan].ClassificationType.IsOfType(TypeConstants.ReplacementStart))
            {
                --firstSpan;
            }

            while (lastSpan < spans.Count - 1 && !spans[lastSpan].ClassificationType.IsOfType(TypeConstants.ReplacementEnd))
            {
                ++lastSpan;
            }

            return(spans.Skip(firstSpan).Take(lastSpan - firstSpan + 1).ToList());
        }
Пример #34
0
        private static void AssertFilenameClassified(ClassificationSpan classificationSpan, SnapshotSpan snapshotSpan)
        {
            var text  = snapshotSpan.GetText();
            var index = text.IndexOf(':');

            index = text.IndexOf(':', index + 1);
            AssertClassification(classificationSpan, OutputClassificationDefinitions.FindResultsFilename, snapshotSpan.Start.Position, index + 1);
        }
        private static string GetText(ITextSnapshot snapshot, ClassificationSpan start, ClassificationSpan target, bool includeEnd)
        {
            var nsLen  = (includeEnd ? target.Span.End : target.Span.Start) - start.Span.End - 1;
            var nsSpan = new SnapshotSpan(snapshot, start.Span.End + 1, nsLen);
            var nsText = nsSpan.GetText().Trim();

            return(nsText);
        }
        private static void AssertFilenameClassified(ClassificationSpan classificationSpan, SnapshotSpan snapshotSpan)
        {
            var text  = snapshotSpan.GetText();
            var index = Regex.Match(text, @"[:\\]").Index;

            index = text.IndexOf(':', index + 1);
            AssertClassification(classificationSpan, ClassificationTypeDefinitions.FindResultsFilename, snapshotSpan.Start.Position, index + 1);
        }
        private IList <ClassificationSpan> GetFallbackClassificationSpans(SnapshotSpan span)
        {
            var cs  = new ClassificationSpan(span, Classifier.ProbeClassifier.GetClassificationType(Classifier.ProbeClassifierType.Normal));
            var ret = new List <ClassificationSpan>();

            ret.Add(cs);
            return(ret);
        }
Пример #38
0
		public SnapshotParser(ITextSnapshot snapshot, IClassifier classifier)
		{
			Snapshot = snapshot;
			Classifier = classifier;
			ClassificationSpans = Classifier.GetClassificationSpans(new SnapshotSpan(Snapshot, 0, snapshot.Length));
			foreach (ClassificationSpan s in ClassificationSpans)
				SpanIndex.Add(s.Span.Start.Position, s);

			CurrentPoint = Snapshot.GetLineFromLineNumber(0).Start;
			if (SpanIndex.ContainsKey(0))
				CurrentSpan = SpanIndex[0];
		}
		public void MergingTwoEqualFollowingDifferentReturnsDifferentFollowedByMerged()
		{
			var different = new ClassificationSpan(new Mock<IClassification>().Object, new TextSpan(null, new Span(0, 1)));
			var classification = new Mock<IClassification>().Object;
			var classificationSpans = new[]
			{
				different,
				new ClassificationSpan(classification, new TextSpan(null, new Span(1, 1))),
				new ClassificationSpan(classification, new TextSpan(null, new Span(2, 1)))
			};
			CollectionAssert.AreEqual(
				new[] {different, new ClassificationSpan(classification, new TextSpan(null, new Span(1, 2)))},
				ClassificationSpans.Merge(classificationSpans).ToArray());
		}
        /// <summary>
        /// Moves forward by one char or one classification span
        /// </summary>
        /// <returns>true, if moved</returns>
        public bool MoveNext()
        {
            if (!AtEnd())
            {
                CurrentPoint = CurrentSpan != null ? CurrentSpan.Span.End : CurrentPoint + 1;

                if (SpanIndex.ContainsKey(CurrentPoint.Position))
                    CurrentSpan = SpanIndex[CurrentPoint.Position];
                else
                    CurrentSpan = null;
                return true;
            }
            return false;
        }
Пример #41
0
 public static CompletionAnalysis Make(ClassificationSpan start, ClassificationSpan end, Span loc,
     ITextSnapshot snapshot, ITrackingSpan span, ITextBuffer buffer, bool isSpace)
 {
     if (start == end) {
         return new ImportCompletionAnalysis(String.Empty, loc.Start, span, buffer);
     } else if (!isSpace) {
         int nsLen = end.Span.End - start.Span.End - 1;
         var nsSpan = new SnapshotSpan(snapshot, start.Span.End + 1, nsLen);
         var text = nsSpan.GetText().Trim();
         return new ImportCompletionAnalysis(text, loc.Start, span, buffer);
     } else {
         return EmptyCompletionContext;
     }
 }
Пример #42
0
        public static CompletionAnalysis Make(IList<ClassificationSpan> classifications, ClassificationSpan start,
            Span loc, ITextSnapshot snapshot, ITrackingSpan span, ITextBuffer buffer, bool isSpace)
        {
            if (classifications.Count == 1) {
                return new ImportCompletionAnalysis(String.Empty, loc.Start, span, buffer);
            }

            ClassificationSpan imp = null;
            for (int i = 1; i < classifications.Count; i++) {
                if (IsKeyword(classifications[i], "import")) {
                    imp = classifications[i];
                }
            }

            var end = classifications[classifications.Count - 1];
            if (imp == null) {
                if (isSpace) {
                    return EmptyCompletionContext;
                }

                // from [completion]
                //  or
                // from xxx.[completion]
                //  or
                // from xxx[Ctrl-Space completion]
                return new ImportCompletionAnalysis(GetText(snapshot, start, end, true), loc.Start, span, buffer);
            }

            // from xyz import [completion]
            //  or
            // from xyz import abc[Ctrl-Space completion]
            var nsText = GetText(snapshot, start, imp, false);

            string itemText;
            if (Object.ReferenceEquals(end, imp)) {
                itemText = String.Empty;
            } else {
                if (isSpace) {
                    return EmptyCompletionContext;
                }

                var itemLen = end.Span.End - imp.Span.End - 1;
                var itemSpan = new SnapshotSpan(snapshot, imp.Span.End + 1, itemLen);
                itemText = itemSpan.GetText();
            }

            return new FromImportCompletionAnalysis(itemText, loc.Start, span, buffer, nsText);
        }
        public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
        {
            List<ClassificationSpan> spans = new List<ClassificationSpan>();

            foreach (SimpleSelector selector in _cache)
            {
                int start = span.Start.Position;
                int end = span.End.Position;

                if (selector.Start >= start && selector.AfterEnd <= end)
                {
                    var snapShotSpan = new SnapshotSpan(span.Snapshot, selector.Start, selector.Length);
                    var classSpan = new ClassificationSpan(snapShotSpan, _modernizrClassification);
                    spans.Add(classSpan);
                }
            }

            return spans;
        }
Пример #44
0
        public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
        {
            List<ClassificationSpan> spans = new List<ClassificationSpan>();
            int start = span.Start.Position;
            int end = span.End.Position;

            foreach (Declaration dec in _cache.Skip(_cache.FindInsertIndex(start, true)))
            {
                var snapShotSpan = new SnapshotSpan(span.Snapshot, dec.PropertyName.Start, dec.PropertyName.Length);
                var classSpan = new ClassificationSpan(snapShotSpan, _variableClassification);

                spans.Add(classSpan);

                if (dec.PropertyName.AfterEnd > end)
                    break;
            }

            return spans;
        }
        public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
        {
            List<ClassificationSpan> spans = new List<ClassificationSpan>();

            foreach (TokenItem item in _cache)
            {
                int start = span.Start.Position;
                int end = span.End.Position;

                if (item.Start >= start && item.AfterEnd <= end)
                {
                    var snapShotSpan = new SnapshotSpan(span.Snapshot, item.Start - 1, item.Length + 1);
                    var classSpan = new ClassificationSpan(snapShotSpan, _importantClassification);
                    spans.Add(classSpan);
                }
            }

            return spans;
        }
Пример #46
0
        /// <summary>
        /// Moves forward by one char or one classification span
        /// </summary>
        /// <returns>true, if moved</returns>
        public bool MoveNext()
        {
            if (!AtEnd()) {
                //operators are processed char by char, because the classifier can merge several operators into one span (like "]]", "[]")
                CurrentPoint = CurrentSpan != null
                        && CurrentSpan.ClassificationType.Classification != "operator"
                        && CurrentSpan.ClassificationType.Classification != "punctuation"
                    ? CurrentSpan.Span.End
                    : CurrentPoint + 1;

                if (SpanIndex.ContainsKey(CurrentPoint.Position)) {
                    CurrentSpan = SpanIndex[CurrentPoint.Position];
                } else if (CurrentSpan != null && CurrentPoint.Position >= CurrentSpan.Span.End.Position) {
                    //we're out of current span
                    CurrentSpan = null;
                }
                return true;
            }
            return false;
        }
Пример #47
0
 private static bool IsUnterminatedStringToken(ClassificationSpan lastToken) {
     if (lastToken.ClassificationType.IsOfType(PredefinedClassificationTypeNames.String)) {
         var text = lastToken.Span.GetText();
         if (text.EndsWith("\"") || text.EndsWith("'")) {
             return false;
         }
         return true;
     }
     return false;
 }
        private bool IsAllowed(SnapshotPoint triggerPoint, out ClassificationSpan classificationType)
        {
            var line = triggerPoint.GetContainingLine().Extent;
            var spans = _classifier.GetClassificationSpans(line).Where(c => c.Span.Contains(triggerPoint.Position - 1));
            classificationType = spans.LastOrDefault();

            if (spans.Any(c => c.ClassificationType.IsOfType(PredefinedClassificationTypeNames.SymbolDefinition)))
                return true;

            bool isComment = spans.Any(c => c.ClassificationType.IsOfType(PredefinedClassificationTypeNames.Comment));
            if (isComment) return false;

            bool isString = spans.Any(c => c.ClassificationType.IsOfType(PredefinedClassificationTypeNames.String));
            if (isString) return false;

            return true;
        }
Пример #49
0
 /// <summary>
 /// Gets the classifications from <see cref="VisualCobraTokenizer"/>.
 /// </summary>
 /// <param name="span">The span to get classifications from.</param>
 /// <param name="tokCobra">The tokenizer to use.</param>
 /// <returns>A list of <see cref="ClassificationSpan"/> objects representing the classifications
 /// in <paramref name="span"/>.</returns>
 private static List<ClassificationSpan> GetClassificationsFromCobraTokenizer(SnapshotSpan span, VisualCobraTokenizer tokCobra)
 {
     // Tried parallelising, but I'm not sure it's safe in combination with "previous".
     var classifications = new List<ClassificationSpan>();
     IToken previous = null;
     foreach (var tok in tokCobra.AllTokens())
     {
         if (tok.IsKeyword)
         {
             var tokenSpan = new SnapshotSpan(span.Snapshot, new Span(span.Start.Position + tok.CharNum - 1, tok.Length)); // +1
             var cs = new ClassificationSpan(tokenSpan, _cobraKeywordClassificationType);
             classifications.Add(cs);
         }
         else
         {
             switch (tok.Which)
             {
                 case "STRING_SINGLE":
                 case "STRING_DOUBLE":
                 case "CHAR":
                 case "CHAR_LIT_SINGLE":
                     AddSpanToClassifications(span, classifications, tok, tok.Length, _cobraStringClassificationType);
                     break;
                 case "ID": // Note "CLASS" is the class keyword, not "a class"
                     if (IsClass(tok))
                     {
                         AddSpanToClassifications(span, classifications, tok, tok.Length, _cobraClassClassificationType);
                     }
                     break;
                 case "QUESTION":
                     {
                         if (IsClass(previous))
                         {
                             // add another char to cover the ? on the end of a nillable class
                             AddSpanToClassifications(span, classifications, tok, 1, _cobraClassClassificationType);
                         }
                         break;
                     }
                 case "COMMENT":
                     AddSpanToClassifications(span, classifications, tok, tok.Length, _cobraCommentClassificationType);
                     break;
             }
             previous = tok;
         }
     }
     return classifications;
 }
Пример #50
0
 /// <summary>
 /// Creates a <see cref="ClassificationSpan"/> from the supplied span and token, and
 /// adds it to the supplied classifications.
 /// </summary>
 /// <param name="span">The snapshop span.</param>
 /// <param name="classifications">The classifications.</param>
 /// <param name="tok">The token.</param>
 /// <param name="tokenLength">Length of the token.</param>
 /// <param name="classificationType">Type of the classification.</param>
 private static void AddSpanToClassifications(SnapshotSpan span, List<ClassificationSpan> classifications, IToken tok, int tokenLength, IClassificationType classificationType)
 {
     var tokenSpan = new SnapshotSpan(span.Snapshot, new Span(span.Start.Position + tok.CharNum - 1, tokenLength));
     var cs = new ClassificationSpan(tokenSpan, classificationType);
     classifications.Add(cs);
 }
Пример #51
0
 private static bool IsPropertyValue(ClassificationSpan classification)
 {
     return classification.ClassificationType.Classification == "CSS Property Value";
 }
Пример #52
0
 private static bool StartsGrouping(ClassificationSpan token)
 {
     return token.ClassificationType.IsOfType("OpenGroupingClassification");
 }
Пример #53
0
 private static string GetText(ITextSnapshot snapshot, ClassificationSpan start, ClassificationSpan target, bool includeEnd) {
     var nsLen = (includeEnd ? target.Span.End : target.Span.Start) - start.Span.End - 1;
     var nsSpan = new SnapshotSpan(snapshot, start.Span.End + 1, nsLen);
     var nsText = nsSpan.GetText().Trim();
     return nsText;
 }
Пример #54
0
		void Add(List<LinePart> list, int column, ClassificationSpan cspan, SnapshotSpan lineExtent) {
			if (cspan.Span.Length == 0)
				return;
			int startOffs = lineExtent.Start.Position;
			var props = classificationFormatMap.GetTextProperties(cspan.ClassificationType);
			if (list.Count > 0) {
				var last = list[list.Count - 1];
				if (last.AdornmentElement == null && last.TextRunProperties == props && last.Span.End == cspan.Span.Start) {
					list[list.Count - 1] = new LinePart(list.Count - 1, last.Column, Span.FromBounds(last.Span.Start - startOffs, cspan.Span.End - startOffs), last.TextRunProperties);
					return;
				}
			}
			list.Add(new LinePart(list.Count, column, new Span(cspan.Span.Span.Start - startOffs, cspan.Span.Span.Length), props));
		}
Пример #55
0
        private static bool TryCreateClassificationSpan(
            SnapshotSpan span,
            IToken token, IClassificationType type,
            out ClassificationSpan classificationSpan)
        {
            classificationSpan = null;

            if (token.Text == null)
                return false;

            var length = token.Text.Length;
            var start = span.Start.Position + token.CharPositionInLine;
            var snapshotSpan = new SnapshotSpan(span.Snapshot, start, length);

            classificationSpan = new ClassificationSpan(snapshotSpan, type);

            return true;
        }
Пример #56
0
 private static bool EndsGrouping(ClassificationSpan token)
 {
     return token.ClassificationType.IsOfType("CloseGroupingClassification");
 }
Пример #57
0
 private static bool ShouldDedentAfterKeyword(ClassificationSpan span) {
     return span.ClassificationType.Classification == PredefinedClassificationTypeNames.Keyword && ShouldDedentAfterKeyword(span.Span.GetText());
 }
Пример #58
0
 private static bool IsSelector(ClassificationSpan classification)
 {
     return classification.ClassificationType.Classification == "CSS Selector";
 }
        public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
        {
            if (!EnsureInitialized())
            {
                return new ClassificationSpan[0];
            }

            var currentFile = _buffer.GetFileName().ToLowerInvariant();

            if (string.IsNullOrEmpty(currentFile))
            {
                return new ClassificationSpan[0];
            }

            var document = DocumentFactory.GetDocument(currentFile);

            if (document == null)
            {
                return new ClassificationSpan[0];
            }

            var spans = new List<ClassificationSpan>();
            var sheetRules = new HashSet<IStylingRule>(document.Rules);

            using (AmbientRuleContext.GetOrCreate())
            {
                foreach (var unusedRule in UsageRegistry.GetAllUnusedRules(sheetRules))
                {
                    if (unusedRule.Offset + unusedRule.Length > span.Snapshot.Length)
                    {
                        continue;
                    }

                    var ss = new SnapshotSpan(span.Snapshot, unusedRule.Offset, unusedRule.SelectorLength);
                    var s = new ClassificationSpan(ss, _decClassification);
                    spans.Add(s);
                }
            }

            return spans;
        }
Пример #60
0
 internal static bool IsKeyword(ClassificationSpan token, string keyword)
 {
     return token.ClassificationType.Classification == PredefinedClassificationTypeNames.Keyword && token.Span.GetText() == keyword;
 }