Ejemplo n.º 1
0
        private static SnapshotSpan AsSnapshotSpan(OneSClassifier.Region region, ITextSnapshot snapshot)
        {
            ITextSnapshotLine lineFromLineNumber = snapshot.GetLineFromLineNumber(region.StartLine);
            ITextSnapshotLine textSnapshotLine   = region.StartLine == region.EndLine ? lineFromLineNumber : snapshot.GetLineFromLineNumber(region.EndLine);

            return(new SnapshotSpan(lineFromLineNumber.Start + region.StartOffset, textSnapshotLine.End));
        }
Ejemplo n.º 2
0
        private void ReParse(object sender, EventArgs args)
        {
            ITextSnapshot newSnapshot           = this._buffer.CurrentSnapshot;
            List <OneSClassifier.Region> source = new List <OneSClassifier.Region>();

            foreach (Match match in new Regex(this.Subs, RegexOptions.IgnoreCase | RegexOptions.Singleline).Matches(newSnapshot.GetText()))
            {
                ITextSnapshotLine lineFromPosition1 = newSnapshot.GetLineFromPosition(match.Index);
                ITextSnapshotLine lineFromPosition2 = newSnapshot.GetLineFromPosition(match.Index + match.Length);
                if (lineFromPosition1.LineNumber != lineFromPosition2.LineNumber)
                {
                    if (lineFromPosition1.GetText().Contains("Далее"))
                    {
                        int num = Math.Max(match.Value.LastIndexOf("Функция"), match.Value.LastIndexOf("Процедура"));
                        lineFromPosition1 = newSnapshot.GetLineFromPosition(match.Index + num);
                    }
                    List <OneSClassifier.Region> regionList = source;
                    OneSClassifier.Region        region1    = new OneSClassifier.Region();
                    region1.Level       = 1;
                    region1.StartLine   = lineFromPosition1.LineNumber;
                    region1.StartOffset = lineFromPosition1.Length;
                    region1.EndLine     = lineFromPosition2.LineNumber;
                    region1.HoverText   = newSnapshot.GetText(lineFromPosition1.Start.Position, lineFromPosition2.End.Position - lineFromPosition1.Start.Position);
                    OneSClassifier.Region region2 = region1;
                    regionList.Add(region2);
                }
            }
            List <Span> spanList1 = new List <Span>(this.regions.Select <OneSClassifier.Region, Span>((Func <OneSClassifier.Region, Span>)(r => OneSClassifier.AsSnapshotSpan(r, this.snapshot).TranslateTo(newSnapshot, SpanTrackingMode.EdgeExclusive).Span)));
            List <Span> spanList2 = new List <Span>(source.Select <OneSClassifier.Region, Span>((Func <OneSClassifier.Region, Span>)(r => OneSClassifier.AsSnapshotSpan(r, newSnapshot).Span)));
            NormalizedSpanCollection normalizedSpanCollection = NormalizedSpanCollection.Difference(new NormalizedSpanCollection((IEnumerable <Span>)spanList1), new NormalizedSpanCollection((IEnumerable <Span>)spanList2));
            int num1 = int.MaxValue;
            int num2 = -1;

            if (normalizedSpanCollection.Count > 0)
            {
                num1 = normalizedSpanCollection[0].Start;
                num2 = normalizedSpanCollection[normalizedSpanCollection.Count - 1].End;
            }
            if (spanList2.Count > 0)
            {
                num1 = Math.Min(num1, spanList2[0].Start);
                num2 = Math.Max(num2, spanList2[spanList2.Count - 1].End);
            }
            this.snapshot = newSnapshot;
            this.regions  = source;
            if (num1 > num2 || this.TagsChanged == null)
            {
                return;
            }
            this.TagsChanged((object)this, new SnapshotSpanEventArgs(new SnapshotSpan(this.snapshot, Span.FromBounds(num1, num2))));
        }