Esempio n. 1
0
 public TextSnapshot(ITextBuffer buffer, ITextVersion2 version, StringOperand source)
 {
     _version    = version;
     TextBuffer  = buffer;
     TextImage   = new TextImage(version.ImageVersion, source);
     ContentType = version.TextBuffer.ContentType;
 }
Esempio n. 2
0
 public ElisionSnapshot(ElisionBuffer elisionBuffer,
                        ITextSnapshot sourceSnapshot,
                        ITextVersion2 version,
                        StringRebuilder builder,
                        ElisionMap content,
                        bool fillInMappingMode)
     : base(version, builder)
 {
     this.elisionBuffer  = elisionBuffer;
     this.sourceSnapshot = sourceSnapshot;
     // The SourceSnapshots property is used heavily, so cache a handy copy.
     this.sourceSnapshots = new ReadOnlyCollection <ITextSnapshot>(new FrugalList <ITextSnapshot>()
     {
         sourceSnapshot
     });
     this.totalLength       = content.Length;
     this.content           = content;
     this.totalLineCount    = content.LineCount;
     this.fillInMappingMode = fillInMappingMode;
     Debug.Assert(this.totalLength == version.Length,
                  string.Format(System.Globalization.CultureInfo.CurrentCulture,
                                "Elision Snapshot Inconsistency. Content: {0}, Previous + delta: {1}", this.totalLength, version.Length));
     if (this.totalLength != version.Length)
     {
         throw new InvalidOperationException(Strings.InvalidLengthCalculation);
     }
 }
Esempio n. 3
0
        protected BaseSnapshot(ITextVersion2 version, StringRebuilder content)
        {
            this.version        = version;
            this.Content        = content;
            this.cachingContent = CachingTextImage.Create(this.Content, version.ImageVersion);

            // we must extract the content type here, because the content type of the text buffer may change later.
            this.contentType = version.TextBuffer.ContentType;
        }
Esempio n. 4
0
        public ProjectionSnapshot(ProjectionBuffer projectionBuffer, ITextVersion2 version, StringRebuilder content, IList <SnapshotSpan> sourceSpans)
            : base(version, content)
        {
            this.projectionBuffer = projectionBuffer;
            this.sourceSpans      = new ReadOnlyCollection <SnapshotSpan>(sourceSpans);

            this.cumulativeLengths         = new int[sourceSpans.Count + 1];
            this.cumulativeLineBreakCounts = new int[sourceSpans.Count + 1];

            this.sourceSnapshotMap = new Dictionary <ITextSnapshot, List <InvertedSource> >();
            for (int s = 0; s < sourceSpans.Count; ++s)
            {
                SnapshotSpan sourceSpan = sourceSpans[s];
                this.totalLength += sourceSpan.Length;

                this.cumulativeLengths[s + 1] = this.cumulativeLengths[s] + sourceSpan.Length;

                // Most source spans won't change when generating a new projection snapshot,
                // which means we should be able to reuse the line break count from the previous
                // projection snapshot.

                int lineBreakCount = sourceSpan.Snapshot.GetLineNumberFromPosition(sourceSpan.End) - sourceSpan.Snapshot.GetLineNumberFromPosition(sourceSpan.Start);

                // todo: incorrect when span ends with \r and following begins with \n
                this.totalLineCount += lineBreakCount;

                this.cumulativeLineBreakCounts[s + 1] = this.cumulativeLineBreakCounts[s] + lineBreakCount;

                ITextSnapshot         snapshot = sourceSpan.Snapshot;
                List <InvertedSource> invertedSources;
                if (!this.sourceSnapshotMap.TryGetValue(snapshot, out invertedSources))
                {
                    invertedSources = new List <InvertedSource>();
                    this.sourceSnapshotMap.Add(snapshot, invertedSources);
                }
                invertedSources.Add(new InvertedSource(sourceSpan.Span, this.cumulativeLengths[s]));
            }

            // The SourceSnapshots property is heavily used, so calculate it once
            this.sourceSnapshots = new ReadOnlyCollection <ITextSnapshot>(new List <ITextSnapshot>(this.sourceSnapshotMap.Keys));

            // sort the per-buffer source span lists by position in source snapshot
            foreach (var v in this.sourceSnapshotMap.Values)
            {
                // sort by starting position. Spans can't overlap, but we do need null spans at a particular position
                // to precede non-null spans at that position, so if starting positions are equal, compare the ends.
                v.Sort((left, right) => (left.sourceSpan.Start == right.sourceSpan.Start
                                            ? left.sourceSpan.End - right.sourceSpan.End
                                            : left.sourceSpan.Start - right.sourceSpan.Start));
            }

            if (BufferGroup.Tracing)
            {
                Debug.WriteLine(LocalToString());
            }
            if (this.totalLength != version.Length)
            {
                Debug.Fail(string.Format(System.Globalization.CultureInfo.CurrentCulture,
                                         "Projection Snapshot Inconsistency. Sum of spans: {0}, Previous + delta: {1}", this.totalLength, version.Length));
                throw new InvalidOperationException(Strings.InvalidLengthCalculation);
            }
            OverlapCheck();
        }
Esempio n. 5
0
 protected BaseProjectionSnapshot(ITextVersion2 version, StringRebuilder builder)
     : base(version, builder)
 {
 }
Esempio n. 6
0
 public TextSnapshot(ITextBuffer textBuffer, ITextVersion2 version, StringRebuilder content)
     : base(version, content)
 {
     System.Diagnostics.Debug.Assert(version.Length == content.Length);
     this.textBuffer = textBuffer;
 }