public SnapshotSourceText(ITextSnapshot roslynSnapshot, TextBufferContainer containerOpt)
            {
                Contract.ThrowIfNull(roslynSnapshot);

                this.EditorSnapshot = roslynSnapshot;
                _containerOpt       = containerOpt;
            }
Example #2
0
            public static SourceText From(
                ITextBufferCloneService?textBufferCloneService,
                ITextSnapshot editorSnapshot
                )
            {
                if (editorSnapshot == null)
                {
                    throw new ArgumentNullException(nameof(editorSnapshot));
                }

                if (!s_textSnapshotMap.TryGetValue(editorSnapshot, out var snapshot))
                {
                    // Explicitly obtain the TextBufferContainer before calling GetValue to avoid reentrancy in
                    // ConditionalWeakTable. https://github.com/dotnet/roslyn/issues/28256
                    var container = TextBufferContainer.From(editorSnapshot.TextBuffer);

                    // Avoid capturing `textBufferCloneServiceOpt` on the fast path
                    var tempTextBufferCloneService = textBufferCloneService;
                    snapshot = s_textSnapshotMap.GetValue(
                        editorSnapshot,
                        s => new SnapshotSourceText(tempTextBufferCloneService, s, container)
                        );
                }

                return(snapshot);
            }
            private SnapshotSourceText(ITextSnapshot editorSnapshot)
            {
                Contract.ThrowIfNull(editorSnapshot);

                this.EditorSnapshot = editorSnapshot;
                _containerOpt       = TextBufferContainer.From(editorSnapshot.TextBuffer);
                _reiteratedVersion  = editorSnapshot.Version.ReiteratedVersionNumber;
            }
            public SnapshotSourceText(ITextSnapshot roslynSnapshot, Encoding encodingOpt, TextBufferContainer containerOpt)
            {
                Contract.ThrowIfNull(roslynSnapshot);

                this.RoslynSnapshot = roslynSnapshot;
                _encodingOpt        = encodingOpt;
                _containerOpt       = containerOpt;
            }
            public SnapshotSourceText(ITextSnapshot roslynSnapshot, Encoding encodingOpt, TextBufferContainer containerOpt)
            {
                Contract.ThrowIfNull(roslynSnapshot);

                this.RoslynSnapshot = roslynSnapshot;
                _encodingOpt = encodingOpt;
                _containerOpt = containerOpt;
            }
            public SnapshotSourceText(ITextImage textImage, Encoding encodingOpt, TextBufferContainer containerOpt)
            {
                Contract.ThrowIfNull(textImage);

                this.TextImage = textImage;
                _encodingOpt   = encodingOpt;
                _containerOpt  = containerOpt;
            }
Example #7
0
            private SnapshotSourceText(ITextSnapshot editorSnapshot, TextBufferContainer container)
            {
                Contract.ThrowIfNull(editorSnapshot);

                this.TextImage = RecordReverseMapAndGetImage(editorSnapshot);
                _encodingOpt   = editorSnapshot.TextBuffer.GetEncodingOrUTF8();
                _containerOpt  = container;
            }
            private SnapshotSourceText(ITextSnapshot editorSnapshot, Encoding encodingOpt)
            {
                Contract.ThrowIfNull(editorSnapshot);

                this.RoslynSnapshot = TextBufferMapper.ToRoslyn(editorSnapshot);
                _containerOpt       = TextBufferContainer.From(editorSnapshot.TextBuffer);
                _reiteratedVersion  = editorSnapshot.Version.ReiteratedVersionNumber;
                _encodingOpt        = encodingOpt;
            }
            private SnapshotSourceText(ITextSnapshot editorSnapshot, Encoding encodingOpt)
            {
                Contract.ThrowIfNull(editorSnapshot);

                this.RoslynSnapshot = TextBufferMapper.ToRoslyn(editorSnapshot);
                _containerOpt = TextBufferContainer.From(editorSnapshot.TextBuffer);
                _reiteratedVersion = editorSnapshot.Version.ReiteratedVersionNumber;
                _encodingOpt = encodingOpt;
            }
Example #10
0
            /// <summary>
            /// This only exist to break circular dependency on creating buffer. nobody except extension itself should use it
            /// </summary>
            internal static SourceText From(ITextSnapshot editorSnapshot, TextBufferContainer container)
            {
                if (editorSnapshot == null)
                {
                    throw new ArgumentNullException(nameof(editorSnapshot));
                }

                Contract.ThrowIfFalse(editorSnapshot.TextBuffer == container.GetTextBuffer());
                return(s_textSnapshotMap.GetValue(editorSnapshot, s => new SnapshotSourceText(s, container)));
            }
Example #11
0
 private SnapshotSourceText(ITextBufferCloneService textBufferCloneServiceOpt, ITextSnapshot editorSnapshot) :
     this(textBufferCloneServiceOpt, editorSnapshot, TextBufferContainer.From(editorSnapshot.TextBuffer))
 {
 }
Example #12
0
 public static SourceTextContainer AsTextContainer(this ITextBuffer buffer) =>
 TextBufferContainer.From(buffer);
Example #13
0
 public static SourceTextContainer AsTextContainer(this ITextBuffer buffer)
 {
     return(TextBufferContainer.From(buffer));
 }
Example #14
0
 private SnapshotSourceText(ITextSnapshot editorSnapshot) :
     this(editorSnapshot, TextBufferContainer.From(editorSnapshot.TextBuffer))
 {
 }