コード例 #1
0
        private static SnapshotSpan AsSnapshotSpan(SimpleRegion region, ITextSnapshot snapshot)
        {
            var startLine = snapshot.GetLineFromLineNumber(region.StartLine);
            var endLine   = (region.StartLine == region.EndLine)
                        ? startLine
                        : snapshot.GetLineFromLineNumber(region.EndLine);

            return(new SnapshotSpan(startLine.Start + region.StartOffset, endLine.End));
        }
コード例 #2
0
ファイル: PointParam.cs プロジェクト: esmayl/dstools
 internal SimpleRegion(SimpleRegion clone) : base(clone)
 {
 }
コード例 #3
0
        private void ReParse()
        {
            ITextSnapshot newSnapshot = this.buffer.CurrentSnapshot;
            var           newRegions  = new List <SimpleRegion>();

            SimpleRegion currentRegion = null;

            foreach (var line in newSnapshot.Lines)
            {
                string text = line.GetText();

                var trimText = text.Trim();

                var isCommentOfInterest = false;

                if (trimText == "//" || trimText == "////" ||
                    trimText.StartsWith("// ") || trimText.StartsWith("////"))
                {
                    isCommentOfInterest = true;
                }

                if (isCommentOfInterest)
                {
                    if (currentRegion == null)
                    {
                        currentRegion = new SimpleRegion
                        {
                            StartLine   = line.LineNumber,
                            StartOffset = text.IndexOf("//"),
                        };
                    }
                }
                else
                {
                    if (currentRegion != null)
                    {
                        var endLineNumber = line.LineNumber - 1;

                        if (endLineNumber != currentRegion.StartLine)
                        {
                            currentRegion.EndLine = endLineNumber;
                            newRegions.Add(currentRegion);
                        }

                        currentRegion = null;
                    }
                }
            }

            if (currentRegion != null)
            {
                var endLineNumber = newSnapshot.Lines.Count() - 1;

                if (endLineNumber != currentRegion.StartLine)
                {
                    currentRegion.EndLine = endLineNumber;
                    newRegions.Add(currentRegion);
                }
            }

            // determine the changed span, and send a changed event with the new spans
            List <Span> oldSpans =
                new List <Span>(this.regions.Select(r => AsSnapshotSpan(r, this.snapshot)
                                                    .TranslateTo(newSnapshot, SpanTrackingMode.EdgeExclusive)
                                                    .Span));
            List <Span> newSpans =
                new List <Span>(newRegions.Select(r => AsSnapshotSpan(r, newSnapshot).Span));

            NormalizedSpanCollection oldSpanCollection = new NormalizedSpanCollection(oldSpans);
            NormalizedSpanCollection newSpanCollection = new NormalizedSpanCollection(newSpans);

            // the changed regions are regions that appear in one set or the other, but not both.
            NormalizedSpanCollection removed =
                NormalizedSpanCollection.Difference(oldSpanCollection, newSpanCollection);

            int changeStart = int.MaxValue;
            int changeEnd   = -1;

            if (removed.Count > 0)
            {
                changeStart = removed[0].Start;
                changeEnd   = removed[removed.Count - 1].End;
            }

            if (newSpans.Count > 0)
            {
                changeStart = Math.Min(changeStart, newSpans[0].Start);
                changeEnd   = Math.Max(changeEnd, newSpans[newSpans.Count - 1].End);
            }

            this.snapshot = newSnapshot;
            this.regions  = newRegions;

            if (changeStart <= changeEnd)
            {
                ITextSnapshot snap = this.snapshot;

                this.TagsChanged?.Invoke(
                    this,
                    new SnapshotSpanEventArgs(
                        new SnapshotSpan(this.snapshot, Span.FromBounds(changeStart, changeEnd))));
            }
        }