private TrackingLSPDocumentManager CreateDocumentManager(int hostDocumentVersion = 0)
        {
            var testVirtualDocUri            = RazorVirtualHtmlUri;
            var testVirtualDocument          = new TestVirtualDocumentSnapshot(RazorUri, hostDocumentVersion);
            var htmlVirtualDocument          = new HtmlVirtualDocumentSnapshot(testVirtualDocUri, Mock.Of <ITextSnapshot>(MockBehavior.Strict), hostDocumentVersion);
            LSPDocumentSnapshot testDocument = new TestLSPDocumentSnapshot(RazorUri, hostDocumentVersion, testVirtualDocument, htmlVirtualDocument);
            var documentManager = new Mock <TrackingLSPDocumentManager>(MockBehavior.Strict);

            documentManager.Setup(manager => manager.TryGetDocument(It.IsAny <Uri>(), out testDocument))
            .Returns(true);
            return(documentManager.Object);
        }
Ejemplo n.º 2
0
        public override VirtualDocumentSnapshot Update(IReadOnlyList <TextChange> changes, long hostDocumentVersion)
        {
            if (changes is null)
            {
                throw new ArgumentNullException(nameof(changes));
            }

            _hostDocumentSyncVersion = hostDocumentVersion;
            TextBuffer.SetHostDocumentSyncVersion(_hostDocumentSyncVersion.Value);

            if (changes.Count == 0)
            {
                // Even though nothing changed here, we want the synchronizer to be aware of the host document version change.
                // So, let's make an empty edit to invoke the text buffer Changed events.
                TextBuffer.MakeEmptyEdit();

                _currentSnapshot = UpdateSnapshot();
                return(_currentSnapshot);
            }

            using var edit = TextBuffer.CreateEdit(EditOptions.None, reiteratedVersionNumber: null, InviolableEditTag.Instance);
            for (var i = 0; i < changes.Count; i++)
            {
                var change = changes[i];

                if (change.IsDelete())
                {
                    edit.Delete(change.Span.Start, change.Span.Length);
                }
                else if (change.IsReplace())
                {
                    edit.Replace(change.Span.Start, change.Span.Length, change.NewText);
                }
                else if (change.IsInsert())
                {
                    edit.Insert(change.Span.Start, change.NewText);
                }
                else
                {
                    throw new InvalidOperationException("Unknown edit type when updating LSP HTML buffer.");
                }
            }

            edit.Apply();
            _currentSnapshot = UpdateSnapshot();

            return(_currentSnapshot);
        }
        public HtmlVirtualDocument(Uri uri, ITextBuffer textBuffer)
        {
            if (uri is null)
            {
                throw new ArgumentNullException(nameof(uri));
            }

            if (textBuffer is null)
            {
                throw new ArgumentNullException(nameof(textBuffer));
            }

            Uri              = uri;
            TextBuffer       = textBuffer;
            _currentSnapshot = UpdateSnapshot();
        }
        public override VirtualDocumentSnapshot Update(IReadOnlyList <TextChange> changes, long hostDocumentVersion)
        {
            if (changes is null)
            {
                throw new ArgumentNullException(nameof(changes));
            }

            _hostDocumentSyncVersion = hostDocumentVersion;

            if (changes.Count == 0)
            {
                _currentSnapshot = UpdateSnapshot();
                return(_currentSnapshot);
            }

            using var edit = TextBuffer.CreateEdit(EditOptions.None, reiteratedVersionNumber: null, InviolableEditTag.Instance);
            for (var i = 0; i < changes.Count; i++)
            {
                var change = changes[i];

                if (change.IsDelete())
                {
                    edit.Delete(change.Span.Start, change.Span.Length);
                }
                else if (change.IsReplace())
                {
                    edit.Replace(change.Span.Start, change.Span.Length, change.NewText);
                }
                else if (change.IsInsert())
                {
                    edit.Insert(change.Span.Start, change.NewText);
                }
                else
                {
                    throw new InvalidOperationException("Unknown edit type when updating LSP HTML buffer.");
                }
            }

            edit.Apply();
            _currentSnapshot = UpdateSnapshot();

            return(_currentSnapshot);
        }