public void TryGetVirtualDocument_NoCSharpDocument_ReturnsFalse()
        {
            // Arrange
            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);
        }
        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);
        }
        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 <TextChange>();
            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);
        }