Ejemplo n.º 1
0
        public async Task TrySynchronizeVirtualDocumentAsync_SimultaneousDifferentSynchronizationRequests_CancelsFirst_ReturnsFalseThenTrue()
        {
            // Arrange
            var(originalLSPDocument, originalVirtualDocument) = CreateDocuments(lspDocumentVersion: 124, virtualDocumentSyncVersion: 123);
            var fileUriProvider = CreateUriProviderFor(VirtualDocumentTextBuffer, originalVirtualDocument.Uri);
            var synchronizer    = new DefaultLSPDocumentSynchronizer(fileUriProvider);

            synchronizer._synchronizationTimeout = TimeSpan.FromMilliseconds(500);
            NotifyLSPDocumentAdded(originalLSPDocument, synchronizer);

            // Act

            // Start synchronization, this will hang until we notify the buffer versions been updated because the above virtual document expects host doc version 123 but the host doc is 124
            var synchronizeTask1 = synchronizer.TrySynchronizeVirtualDocumentAsync(originalLSPDocument.Version, originalVirtualDocument, CancellationToken.None);

            // Start another synchronization that will also hang because 124 != 125. However, this synchronization request is for the same addressable virtual document (same URI)
            // therefore requesting a second synchronization with a different host doc version expectation will cancel the original synchronization request resulting it returning
            // false.
            var(newLSPDocument, newVirtualDocument) = CreateDocuments(lspDocumentVersion: 125, virtualDocumentSyncVersion: 124);
            var synchronizeTask2 = synchronizer.TrySynchronizeVirtualDocumentAsync(newLSPDocument.Version, newVirtualDocument, CancellationToken.None);

            NotifyBufferVersionUpdated(VirtualDocumentTextBuffer, newLSPDocument.Version);
            var result1 = await synchronizeTask1.ConfigureAwait(false);

            var result2 = await synchronizeTask2.ConfigureAwait(false);

            // Assert
            Assert.False(result1);
            Assert.True(result2);
        }
Ejemplo n.º 2
0
        public async Task TrySynchronizeVirtualDocumentAsync_SimultaneousEqualSynchronizationRequests_ReturnsTrue()
        {
            // Arrange
            var(lspDocument, virtualDocument) = CreateDocuments(lspDocumentVersion: 124, virtualDocumentSyncVersion: 123);
            var fileUriProvider = CreateUriProviderFor(VirtualDocumentTextBuffer, virtualDocument.Uri);
            var synchronizer    = new DefaultLSPDocumentSynchronizer(fileUriProvider);

            synchronizer._synchronizationTimeout = TimeSpan.FromMilliseconds(500);
            NotifyLSPDocumentAdded(lspDocument, synchronizer);

            // Act

            // Start synchronization, this will hang until we notify the buffer versions been updated because the above virtual document expects host doc version 123 but the host doc is 124
            var synchronizeTask1 = synchronizer.TrySynchronizeVirtualDocumentAsync(lspDocument.Version, virtualDocument, CancellationToken.None);
            var synchronizeTask2 = synchronizer.TrySynchronizeVirtualDocumentAsync(lspDocument.Version, virtualDocument, CancellationToken.None);

            NotifyBufferVersionUpdated(VirtualDocumentTextBuffer, lspDocument.Version);
            var result1 = await synchronizeTask1.ConfigureAwait(false);

            var result2 = await synchronizeTask2.ConfigureAwait(false);

            // Assert
            Assert.True(result1);
            Assert.True(result2);
        }
Ejemplo n.º 3
0
        public async Task TrySynchronizeVirtualDocumentAsync_SynchronizedDocument_ReturnsTrue()
        {
            // Arrange
            var(lspDocument, virtualDocument) = CreateDocuments(lspDocumentVersion: 123, virtualDocumentSyncVersion: 123);
            var fileUriProvider = CreateUriProviderFor(VirtualDocumentTextBuffer, virtualDocument.Uri);
            var synchronizer    = new DefaultLSPDocumentSynchronizer(fileUriProvider);

            NotifyLSPDocumentAdded(lspDocument, synchronizer);
            NotifyBufferVersionUpdated(VirtualDocumentTextBuffer, virtualDocument.HostDocumentSyncVersion.Value);

            // Act
            var result = await synchronizer.TrySynchronizeVirtualDocumentAsync(lspDocument.Version, virtualDocument, CancellationToken.None).ConfigureAwait(false);

            // Assert
            Assert.True(result);
        }
Ejemplo n.º 4
0
        public async Task TrySynchronizeVirtualDocumentAsync_Timeout_ReturnsFalse()
        {
            // Arrange
            var(lspDocument, virtualDocument) = CreateDocuments(lspDocumentVersion: 123, virtualDocumentSyncVersion: 123);
            var fileUriProvider = CreateUriProviderFor(VirtualDocumentTextBuffer, virtualDocument.Uri);
            var synchronizer    = new DefaultLSPDocumentSynchronizer(fileUriProvider);

            synchronizer._synchronizationTimeout = TimeSpan.FromMilliseconds(10);
            NotifyLSPDocumentAdded(lspDocument, synchronizer);

            // We're not going to notify that the buffer version was updated so the synchronization will wait until a timeout occurs.

            // Act
            var result = await synchronizer.TrySynchronizeVirtualDocumentAsync(lspDocument.Version, virtualDocument, CancellationToken.None).ConfigureAwait(false);

            // Assert
            Assert.False(result);
        }
Ejemplo n.º 5
0
        public async Task TrySynchronizeVirtualDocumentAsync_DocumentRemoved_CancelsActiveRequests()
        {
            // Arrange
            var(lspDocument, virtualDocument) = CreateDocuments(lspDocumentVersion: 124, virtualDocumentSyncVersion: 123);
            var fileUriProvider = CreateUriProviderFor(VirtualDocumentTextBuffer, virtualDocument.Uri);
            var synchronizer    = new DefaultLSPDocumentSynchronizer(fileUriProvider)
            {
                _synchronizationTimeout = TimeSpan.FromMilliseconds(500)
            };

            NotifyLSPDocumentAdded(lspDocument, synchronizer);

            var synchronizedTask = synchronizer.TrySynchronizeVirtualDocumentAsync(lspDocument.Version, virtualDocument, CancellationToken.None).ConfigureAwait(false);

            // Act
            NotifyLSPDocumentRemoved(lspDocument, synchronizer);
            NotifyBufferVersionUpdated(VirtualDocumentTextBuffer, lspDocument.Version);

            var result = await synchronizedTask;

            // Assert
            Assert.False(result);
        }
Ejemplo n.º 6
0
        private static void NotifyLSPDocumentAdded(LSPDocumentSnapshot lspDocument, DefaultLSPDocumentSynchronizer synchronizer)
        {
            var args = new LSPDocumentChangeEventArgs(old: null, @new: lspDocument, LSPDocumentChangeKind.Added);

            synchronizer.DocumentManager_Changed(sender: null, args);
        }
Ejemplo n.º 7
0
 private static void NotifyLSPDocumentRemoved(LSPDocumentSnapshot lspDocument, DefaultLSPDocumentSynchronizer synchronizer)
 {
     synchronizer.Changed(old: lspDocument, @new: null, virtualOld: null, virtualNew: null, LSPDocumentChangeKind.Removed);
 }