Beispiel #1
0
        public void CanGetSurroundingBraces()
        {
            var textBuffer = GetCSharpTextBuffer("Rainbow1.txt");
              var snapshot = textBuffer.CurrentSnapshot;
              var cache = new BraceCache(snapshot, GetLang(textBuffer));
              var span = snapshot.GetSpan();
              // force parsing all text
              cache.BracesInSpans(new NormalizedSnapshotSpanCollection(span)).Count();

              // we're looking at the {} for this function
              //public static bool Has<T>(this IPropertyOwner owner) {
              //  return owner.Properties.ContainsProperty(typeof(T));
              //}
              var line10 = snapshot.GetLineFromLineNumber(9);
              var matchingBraces = cache.GetBracePairFromPosition(line10.Start + 10, RainbowHighlightMode.TrackInsertionPoint);
              Assert.NotNull(matchingBraces);
              Assert.Equal('{', matchingBraces.Item1.Brace);
              Assert.Equal('}', matchingBraces.Item2.Brace);
        }
Beispiel #2
0
        public void CanGetSurroundingBraces_TrackNextScope()
        {
            var textBuffer = GetCSharpTextBuffer("Rainbow1.txt");
              var snapshot = textBuffer.CurrentSnapshot;
              var cache = new BraceCache(snapshot, GetLang(textBuffer));
              var span = snapshot.GetSpan();
              // force parsing all text
              cache.BracesInSpans(new NormalizedSnapshotSpanCollection(span)).Count();

              // we're looking at the {} for this function, positioned just at the {
              //public static bool Has<T>(this IPropertyOwner owner) {
              //  return owner.Properties.ContainsProperty(typeof(T));
              //}
              var line9 = snapshot.GetLineFromLineNumber(8);
              Console.WriteLine(line9.GetText());
              var openingBrace = line9.End - 1;
              Assert.Equal('{', openingBrace.GetChar());
              var matchingBraces = cache.GetBracePairFromPosition(openingBrace, RainbowHighlightMode.TrackNextScope);
              Assert.NotNull(matchingBraces);
              Assert.Equal(openingBrace.Position, matchingBraces.Item1.Position);
        }
Beispiel #3
0
        public void CanGetSurroundingBraces_TrackInsertionPoint()
        {
            var textBuffer = GetCSharpTextBuffer("Rainbow1.txt");
              var snapshot = textBuffer.CurrentSnapshot;
              var cache = new BraceCache(snapshot, GetLang(textBuffer));
              var span = snapshot.GetSpan();
              // force parsing all text
              cache.BracesInSpans(new NormalizedSnapshotSpanCollection(span)).Count();

              // we're looking at the {} for this function, positioned just at the {
              //public static bool Has<T>(this IPropertyOwner owner) {
              //  return owner.Properties.ContainsProperty(typeof(T));
              //}
              var line9 = snapshot.GetLineFromLineNumber(8);
              var openingBrace = line9.Start + line9.GetText().IndexOf('{');
              Assert.Equal('{', openingBrace.GetChar());
              var matchingBraces = cache.GetBracePairFromPosition(openingBrace, RainbowHighlightMode.TrackInsertionPoint);
              Assert.NotNull(matchingBraces);
              // we should have gotten braces starting *before* the search position!
              Assert.True(openingBrace.Position > matchingBraces.Item1.Position);
        }
Beispiel #4
0
        public IEnumerable <ITagSpan <RainbowTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (!VsfSettings.RainbowTagsEnabled)
            {
                yield break;
            }
            if (spans.Count == 0)
            {
                yield break;
            }
            BraceCache    braceCache = provider.BraceCache;
            ITextSnapshot snapshot   = spans[0].Snapshot;

            if (braceCache == null || braceCache.Snapshot != spans[0].Snapshot)
            {
                yield break;
            }
            foreach (var brace in braceCache.BracesInSpans(spans))
            {
                var ctype = rainbowTags[brace.Depth % Constants.MAX_RAINBOW_DEPTH];
                yield return(brace.ToSpan(snapshot, ctype));
            }
        }
Beispiel #5
0
        public void CanInvalidate()
        {
            var textBuffer = GetCSharpTextBuffer("Rainbow1.txt");
              var snapshot = textBuffer.CurrentSnapshot;
              var cache = new BraceCache(snapshot, GetLang(textBuffer));
              var span = snapshot.GetSpan();

              // force the cache to parse entire file
              cache.BracesInSpans(new NormalizedSnapshotSpanCollection(span)).Count();

              // invalidate starting in Get_<T>
              var endpoint = new SnapshotPoint(snapshot, 357);
              cache.Invalidate(endpoint);
              // 331 is the position of the closing } of method before this
              Assert.Equal(331, cache.LastParsedPosition);
        }
Beispiel #6
0
 public void CanParseEntireFile()
 {
     var textBuffer = GetCSharpTextBuffer("Rainbow1.txt");
       var snapshot = textBuffer.CurrentSnapshot;
       var cache = new BraceCache(snapshot, GetLang(textBuffer));
       var span = snapshot.GetSpan();
       Assert.Equal(32, cache.BracesInSpans(new NormalizedSnapshotSpanCollection(span)).Count());
 }