예제 #1
0
        public void TryGetVirtualDocument_NoCSharpDocument_ReturnsFalse()
        {
            // Arrange
            using var lspDocument = new DefaultLSPDocument(Uri, Mock.Of <ITextBuffer>(), new[] { Mock.Of <VirtualDocument>() });

            // Act
            var result = lspDocument.TryGetVirtualDocument <TestVirtualDocument>(out var virtualDocument);

            // Assert
            Assert.False(result);
            Assert.Null(virtualDocument);
        }
        public override LSPDocument Create(ITextBuffer buffer)
        {
            if (buffer is null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            var uri = _fileUriProvider.GetOrCreate(buffer);
            var virtualDocuments = CreateVirtualDocuments(buffer);
            var lspDocument      = new DefaultLSPDocument(uri, buffer, virtualDocuments);

            return(lspDocument);
        }
예제 #3
0
        public void TryGetVirtualCSharpDocument_CSharpDocument_ReturnsTrue()
        {
            // Arrange
            var testVirtualDocument = new TestVirtualDocument();
            var lspDocument         = new DefaultLSPDocument(Uri, Mock.Of <ITextBuffer>(), new[] { Mock.Of <VirtualDocument>(), testVirtualDocument });

            // Act
            var result = lspDocument.TryGetVirtualDocument <TestVirtualDocument>(out var virtualDocument);

            // Assert
            Assert.True(result);
            Assert.Same(testVirtualDocument, virtualDocument);
        }
예제 #4
0
        public void TryGetVirtualDocument_NoCSharpDocument_ReturnsFalse()
        {
            // Arrange
            var virtualDocumentMock = new Mock <VirtualDocument>(MockBehavior.Strict);

            virtualDocumentMock.Setup(d => d.Dispose()).Verifiable();
            using var lspDocument = new DefaultLSPDocument(Uri, Mock.Of <ITextBuffer>(MockBehavior.Strict), new[] { virtualDocumentMock.Object });

            // Act
            var result = lspDocument.TryGetVirtualDocument <TestVirtualDocument>(out var virtualDocument);

            // Assert
            Assert.False(result);
            Assert.Null(virtualDocument);
        }
        public void UpdateVirtualDocument_UpdatesProvidedVirtualDocumentWithProvidedArgs_AndRecalcsSnapshot()
        {
            // Arrange
            var textBuffer      = new TestTextBuffer(new StringTextSnapshot(string.Empty));
            var virtualDocument = new TestVirtualDocument();

            using var document = new DefaultLSPDocument(Uri, textBuffer, new[] { virtualDocument });
            var changes          = Array.Empty <ITextChange>();
            var originalSnapshot = document.CurrentSnapshot;

            // Act
            document.UpdateVirtualDocument <TestVirtualDocument>(changes, hostDocumentVersion: 1337, state: null);

            // Assert
            Assert.Equal(1337, virtualDocument.HostDocumentVersion);
            Assert.Same(changes, virtualDocument.Changes);
            Assert.NotEqual(originalSnapshot, document.CurrentSnapshot);
        }
예제 #6
0
        public void UpdateVirtualDocument_UpdatesProvidedVirtualDocumentWithProvidedArgs_AndRecalcsSnapshot()
        {
            // Arrange
            var snapshot         = Mock.Of <ITextSnapshot>(s => s.Version == Mock.Of <ITextVersion>());
            var textBuffer       = Mock.Of <ITextBuffer>(buffer => buffer.CurrentSnapshot == snapshot);
            var virtualDocument  = new TestVirtualDocument();
            var document         = new DefaultLSPDocument(Uri, textBuffer, new[] { virtualDocument });
            var changes          = Array.Empty <ITextChange>();
            var originalSnapshot = document.CurrentSnapshot;

            // Act
            document.UpdateVirtualDocument <TestVirtualDocument>(changes, hostDocumentVersion: 1337);

            // Assert
            Assert.Equal(1337, virtualDocument.HostDocumentSyncVersion);
            Assert.Same(changes, virtualDocument.Changes);
            Assert.NotEqual(originalSnapshot, document.CurrentSnapshot);
        }
예제 #7
0
        public void TryGetVirtualCSharpDocument_CSharpDocument_ReturnsTrue()
        {
            // Arrange
            var textBuffer = new Mock <ITextBuffer>(MockBehavior.Strict);

            textBuffer.SetupGet(b => b.CurrentSnapshot).Returns((ITextSnapshot)null);
            textBuffer.Setup(b => b.ChangeContentType(It.IsAny <IContentType>(), null)).Verifiable();
            textBuffer.SetupGet(b => b.Properties).Returns(new PropertyCollection());
            var testVirtualDocument = new TestVirtualDocument(Uri, textBuffer.Object);
            var virtualDocumentMock = new Mock <VirtualDocument>(MockBehavior.Strict);

            virtualDocumentMock.Setup(d => d.Dispose()).Verifiable();
            using var lspDocument = new DefaultLSPDocument(Uri, Mock.Of <ITextBuffer>(MockBehavior.Strict), new[] { virtualDocumentMock.Object, testVirtualDocument });

            // Act
            var result = lspDocument.TryGetVirtualDocument <TestVirtualDocument>(out var virtualDocument);

            // Assert
            Assert.True(result);
            Assert.Same(testVirtualDocument, virtualDocument);
        }
        public void CurrentSnapshot_ChangesWhenTextBufferChanges()
        {
            // Arrange
            var textBuffer = new TestTextBuffer(new StringTextSnapshot(string.Empty));

            textBuffer.ChangeContentType(NotInertContentType, editTag: null);
            using var document = new DefaultLSPDocument(Uri, textBuffer, virtualDocuments: Array.Empty <VirtualDocument>());
            var originalSnapshot = document.CurrentSnapshot;

            // Act
            var edit = textBuffer.CreateEdit();

            edit.Insert(0, "New!");
            edit.Apply();

            // Assert
            var newSnapshot = document.CurrentSnapshot;

            Assert.NotSame(originalSnapshot, newSnapshot);
            Assert.Equal(1, originalSnapshot.Version);
            Assert.Equal(2, newSnapshot.Version);
        }
        public void InertTextBuffer_DoesNotCreateSnapshot()
        {
            // Arrange
            var textBuffer = new TestTextBuffer(new StringTextSnapshot(string.Empty));

            textBuffer.ChangeContentType(NotInertContentType, editTag: null);
            using var document = new DefaultLSPDocument(Uri, textBuffer, virtualDocuments: Array.Empty <VirtualDocument>());
            var originalSnapshot = document.CurrentSnapshot;

            textBuffer.ChangeContentType(TestInertContentType.Instance, editTag: null);

            // Act
            var edit = textBuffer.CreateEdit();

            edit.Insert(0, "New!");
            edit.Apply();

            // Assert
            var newSnapshot = document.CurrentSnapshot;

            Assert.Same(originalSnapshot, newSnapshot);
        }
예제 #10
0
        public void UpdateVirtualDocument_UpdatesProvidedVirtualDocumentWithProvidedArgs_AndRecalcsSnapshot()
        {
            // Arrange
            var textVersion = new Mock <ITextVersion>(MockBehavior.Strict);

            textVersion.SetupGet(v => v.VersionNumber).Returns(0);
            var snapshot        = Mock.Of <ITextSnapshot>(s => s.Version == textVersion.Object, MockBehavior.Strict);
            var textBuffer      = Mock.Of <ITextBuffer>(buffer => buffer.CurrentSnapshot == snapshot, MockBehavior.Strict);
            var virtualDocument = new TestVirtualDocument();

            using var document = new DefaultLSPDocument(Uri, textBuffer, new[] { virtualDocument });
            var changes          = Array.Empty <ITextChange>();
            var originalSnapshot = document.CurrentSnapshot;

            // Act
            document.UpdateVirtualDocument <TestVirtualDocument>(changes, hostDocumentVersion: 1337);

            // Assert
            Assert.Equal(1337, virtualDocument.HostDocumentVersion);
            Assert.Same(changes, virtualDocument.Changes);
            Assert.NotEqual(originalSnapshot, document.CurrentSnapshot);
        }
        public DefaultLSPDocumentManagerTest()
        {
            var contentType = Mock.Of <IContentType>(contentType =>
                                                     contentType.IsOfType("inert") == false &&
                                                     contentType.IsOfType("test") == true &&
                                                     contentType.TypeName == "test",
                                                     MockBehavior.Strict);

            ChangeListeners     = Enumerable.Empty <Lazy <LSPDocumentChangeListener, IContentTypeMetadata> >();
            JoinableTaskContext = new JoinableTaskContext();
            TextBuffer          = new TestTextBuffer(new StringTextSnapshot(string.Empty));
            TextBuffer.ChangeContentType(contentType, editTag: null);
            var snapshot = TextBuffer.CurrentSnapshot;

            Uri         = new Uri("C:/path/to/file.razor");
            UriProvider = Mock.Of <FileUriProvider>(provider => provider.GetOrCreate(TextBuffer) == Uri, MockBehavior.Strict);
            Mock.Get(UriProvider).Setup(p => p.Remove(It.IsAny <ITextBuffer>())).Verifiable();
            var testVirtualDocument = new TestVirtualDocument();
            var lspDocument         = new DefaultLSPDocument(Uri, TextBuffer, new[] { testVirtualDocument });

            LSPDocumentSnapshot = lspDocument.CurrentSnapshot;
            LSPDocument         = lspDocument;
            LSPDocumentFactory  = Mock.Of <LSPDocumentFactory>(factory => factory.Create(TextBuffer) == LSPDocument, MockBehavior.Strict);
        }