Пример #1
0
            private void OnTextContentChanged(object?sender, TextContentChangedEventArgs args)
            {
                var changed = this.EtextChanged;

                if (changed == null)
                {
                    return;
                }

                // we should process all changes even though there is no text changes
                // otherwise, Workspace.CurrentSolution won't move forward to latest ITextSnapshot

                // this should convert given editor snapshots to roslyn forked snapshots
                var oldText = (SnapshotSourceText)args.Before.AsText();
                var newText = SnapshotSourceText.From(_textBufferCloneService, args.After);

                _currentText = newText;

                var changes = ImmutableArray.CreateRange(
                    args.Changes.Select(
                        c =>
                        new TextChangeRange(
                            new TextSpan(c.OldSpan.Start, c.OldSpan.Length),
                            c.NewLength
                            )
                        )
                    );
                var eventArgs = new TextChangeEventArgs(oldText, newText, changes);

                this.LastEventArgs = eventArgs;
                changed(sender, eventArgs);
            }
Пример #2
0
            private TextBufferContainer(ITextBuffer editorBuffer)
            {
                Contract.ThrowIfNull(editorBuffer);

                _weakEditorBuffer = new WeakReference <ITextBuffer>(editorBuffer);
                _currentText      = SnapshotSourceText.From(editorBuffer.CurrentSnapshot, this);
            }
            private static SnapshotSourceText CreateText(ITextSnapshot editorSnapshot)
            {
                var strongBox = s_textBufferLatestSnapshotMap.GetOrCreateValue(editorSnapshot.TextBuffer);
                var text      = strongBox.Value;

                if (text != null && text._reiteratedVersion == editorSnapshot.Version.ReiteratedVersionNumber)
                {
                    if (text.Length == editorSnapshot.Length)
                    {
                        return(text);
                    }
                    else
                    {
                        // In editors with non-compliant Undo/Redo implementations, you can end up
                        // with two Versions with the same ReiteratedVersionNumber but with very
                        // different text. We've never provably seen this problem occur in Visual
                        // Studio, but we have seen crashes that look like they could have been
                        // caused by incorrect results being returned from this cache.
                        try
                        {
                            throw new InvalidOperationException(
                                      $"The matching cached SnapshotSourceText with <Reiterated Version, Length> = <{text._reiteratedVersion}, {text.Length}> " +
                                      $"does not match the given editorSnapshot with <{editorSnapshot.Version.ReiteratedVersionNumber}, {editorSnapshot.Length}>");
                        }
                        catch (Exception e) when(FatalError.ReportWithoutCrash(e))
                        {
                        }
                    }
                }

                text            = new SnapshotSourceText(editorSnapshot);
                strongBox.Value = text;
                return(text);
            }
Пример #4
0
            private TextBufferContainer(ITextBuffer editorBuffer)
            {
                Contract.ThrowIfNull(editorBuffer);

                _weakEditorBuffer = new WeakReference <ITextBuffer>(editorBuffer);
                editorBuffer.Properties.TryGetProperty(typeof(ITextBufferCloneService), out _textBufferCloneServiceOpt);
                _currentText = SnapshotSourceText.From(_textBufferCloneServiceOpt, editorBuffer.CurrentSnapshot, this);
            }
Пример #5
0
 public static SourceText AsText(this ITextSnapshot textSnapshot)
 {
     textSnapshot.TextBuffer.Properties.TryGetProperty <ITextBufferCloneService>(
         typeof(ITextBufferCloneService),
         out var textBufferCloneServiceOpt
         );
     return(SnapshotSourceText.From(textBufferCloneServiceOpt, textSnapshot));
 }
            private static SnapshotSourceText CreateText(ITextSnapshot editorSnapshot)
            {
                var strongBox = s_textBufferLatestSnapshotMap.GetOrCreateValue(editorSnapshot.TextBuffer);
                var text      = strongBox.Value;

                if (text != null && text._reiteratedVersion == editorSnapshot.Version.ReiteratedVersionNumber)
                {
                    return(text);
                }

                text            = new SnapshotSourceText(editorSnapshot, editorSnapshot.TextBuffer.GetEncodingOrUTF8());
                strongBox.Value = text;
                return(text);
            }
Пример #7
0
 public ChangedSourceText(
     ITextBufferCloneService?textBufferCloneService,
     SnapshotSourceText baseText,
     ITextImage baseSnapshot,
     ITextImage currentSnapshot
     )
     : base(
         textBufferCloneService,
         currentSnapshot,
         baseText.Encoding,
         container: null
         )
 {
     _baseText     = baseText;
     _baseSnapshot = baseSnapshot;
 }
            private void OnTextContentChanged(object sender, TextContentChangedEventArgs args)
            {
                var changed = this.EtextChanged;

                if (changed != null && args.Changes.Count != 0)
                {
                    // this should convert given editor snapshots to roslyn forked snapshots
                    var oldText = (SnapshotSourceText)args.Before.AsText();
                    var newText = SnapshotSourceText.From(args.After);
                    _currentText = newText;

                    var changes   = ImmutableArray.CreateRange(args.Changes.Select(c => new TextChangeRange(new TextSpan(c.OldSpan.Start, c.OldSpan.Length), c.NewLength)));
                    var eventArgs = new TextChangeEventArgs(oldText, newText, changes);
                    this.LastEventArgs = eventArgs;
                    changed(sender, eventArgs);
                }
            }
Пример #9
0
 public static SourceText AsText(this ITextSnapshot textSnapshot)
 => SnapshotSourceText.From(textBufferCloneServiceOpt: null, textSnapshot);
 public ChangedSourceText(SnapshotSourceText baseText, ITextSnapshot baseSnapshot, ITextSnapshot currentSnapshot)
     : base(currentSnapshot, containerOpt: null)
 {
     _baseText     = baseText;
     _baseSnapshot = baseSnapshot;
 }
 public LineInfo(SnapshotSourceText text)
 {
     _text = text;
 }
 public ChangedSourceText(SnapshotSourceText baseText, ITextImage baseSnapshot, ITextImage currentSnapshot)
     : base(currentSnapshot, baseText.Encoding, containerOpt: null)
 {
     _baseText     = baseText;
     _baseSnapshot = baseSnapshot;
 }
 public LineInfo(SnapshotSourceText text)
 {
     _text = text;
 }
Пример #14
0
 public static SourceText AsText(this ITextSnapshot textSnapshot)
 => SnapshotSourceText.From(textSnapshot);
Пример #15
0
 public static SourceText AsText(this ITextSnapshot textSnapshot)
 {
     return(SnapshotSourceText.From(textSnapshot));
 }
            private static SnapshotSourceText CreateText(ITextSnapshot editorSnapshot)
            {
                var strongBox = s_textBufferLatestSnapshotMap.GetOrCreateValue(editorSnapshot.TextBuffer);
                var text = strongBox.Value;
                if (text != null && text._reiteratedVersion == editorSnapshot.Version.ReiteratedVersionNumber)
                {
                    return text;
                }

                text = new SnapshotSourceText(editorSnapshot, editorSnapshot.TextBuffer.GetEncodingOrUTF8());
                strongBox.Value = text;
                return text;
            }
 public ChangedSourceText(SnapshotSourceText baseText, ITextSnapshot baseSnapshot, ITextSnapshot currentSnapshot)
     : base(currentSnapshot, baseText.Encoding, containerOpt: null)
 {
     _baseText = baseText;
     _baseSnapshot = baseSnapshot;
 }
            private static SnapshotSourceText CreateText(ITextSnapshot editorSnapshot)
            {
                var strongBox = s_textBufferLatestSnapshotMap.GetOrCreateValue(editorSnapshot.TextBuffer);
                var text = strongBox.Value;
                if (text != null && text._reiteratedVersion == editorSnapshot.Version.ReiteratedVersionNumber)
                {
                    if (text.Length == editorSnapshot.Length)
                    {
                        return text;
                    }
                    else
                    {
                        // In editors with non-compliant Undo/Redo implementations, you can end up
                        // with two Versions with the same ReiteratedVersionNumber but with very
                        // different text. We've never provably seen this problem occur in Visual 
                        // Studio, but we have seen crashes that look like they could have been
                        // caused by incorrect results being returned from this cache. 
                        try
                        {
                            throw new InvalidOperationException(
                                $"The matching cached SnapshotSourceText with <Reiterated Version, Length> = <{text._reiteratedVersion}, {text.Length}> " +
                                $"does not match the given editorSnapshot with <{editorSnapshot.Version.ReiteratedVersionNumber}, {editorSnapshot.Length}>");
                        }
                        catch (Exception e) when (FatalError.ReportWithoutCrash(e))
                        {
                        }
                    }
                }

                text = new SnapshotSourceText(editorSnapshot, editorSnapshot.TextBuffer.GetEncodingOrUTF8());
                strongBox.Value = text;
                return text;
            }