public async Task HandleRequestAsync_ProjectionNotFound_ReturnsNull()
        {
            // Arrange
            var documentManager = new TestDocumentManager();

            documentManager.AddDocument(Uri, Mock.Of <LSPDocumentSnapshot>(MockBehavior.Strict));
            var requestInvoker     = Mock.Of <LSPRequestInvoker>(MockBehavior.Strict);
            var projectionProvider = new Mock <LSPProjectionProvider>(MockBehavior.Strict).Object;

            Mock.Get(projectionProvider).Setup(projectionProvider => projectionProvider.GetProjectionAsync(It.IsAny <LSPDocumentSnapshot>(), It.IsAny <Position>(), CancellationToken.None))
            .Returns(Task.FromResult <ProjectionResult>(null));
            var documentMappingProvider = Mock.Of <LSPDocumentMappingProvider>(MockBehavior.Strict);
            var implementationHandler   = new GoToImplementationHandler(requestInvoker, documentManager, projectionProvider, documentMappingProvider, LoggerProvider);
            var implementationRequest   = new TextDocumentPositionParams()
            {
                TextDocument = new TextDocumentIdentifier()
                {
                    Uri = Uri
                },
                Position = new Position(0, 1)
            };

            // Act
            var result = await implementationHandler.HandleRequestAsync(implementationRequest, new ClientCapabilities(), CancellationToken.None).ConfigureAwait(false);

            // Assert
            Assert.Null(result);
        }
예제 #2
0
        public async Task HandleRequestAsync_ProjectionNotFound_ReturnsNull()
        {
            // Arrange
            var documentManager = new TestDocumentManager();

            documentManager.AddDocument(Uri, Mock.Of <LSPDocumentSnapshot>());
            var requestInvoker          = Mock.Of <LSPRequestInvoker>();
            var projectionProvider      = Mock.Of <LSPProjectionProvider>();
            var documentMappingProvider = Mock.Of <LSPDocumentMappingProvider>();
            var implementationHandler   = new GoToImplementationHandler(requestInvoker, documentManager, projectionProvider, documentMappingProvider);
            var implementationRequest   = new TextDocumentPositionParams()
            {
                TextDocument = new TextDocumentIdentifier()
                {
                    Uri = Uri
                },
                Position = new Position(0, 1)
            };

            // Act
            var result = await implementationHandler.HandleRequestAsync(implementationRequest, new ClientCapabilities(), CancellationToken.None).ConfigureAwait(false);

            // Assert
            Assert.Null(result);
        }
예제 #3
0
        public async Task HandleRequestAsync_HtmlProjection_ReturnsNull()
        {
            // Arrange
            var documentManager = new TestDocumentManager();

            documentManager.AddDocument(Uri, Mock.Of <LSPDocumentSnapshot>());
            var requestInvoker = Mock.Of <LSPRequestInvoker>();

            var projectionResult = new ProjectionResult()
            {
                LanguageKind = RazorLanguageKind.Html,
            };
            var projectionProvider = new Mock <LSPProjectionProvider>();

            projectionProvider.Setup(p => p.GetProjectionAsync(It.IsAny <LSPDocumentSnapshot>(), It.IsAny <Position>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(projectionResult));

            var documentMappingProvider = Mock.Of <LSPDocumentMappingProvider>();
            var implementationHandler   = new GoToImplementationHandler(requestInvoker, documentManager, projectionProvider.Object, documentMappingProvider);
            var implementationRequest   = new TextDocumentPositionParams()
            {
                TextDocument = new TextDocumentIdentifier()
                {
                    Uri = Uri
                },
                Position = new Position(0, 1)
            };

            // Act
            var result = await implementationHandler.HandleRequestAsync(implementationRequest, new ClientCapabilities(), CancellationToken.None).ConfigureAwait(false);

            // Assert
            Assert.Null(result);
        }
        public async Task HandleRequestAsync_HtmlProjection_InvokesHtmlLanguageServer()
        {
            // Arrange
            var invokedLSPRequest   = false;
            var invokedRemapRequest = false;
            var expectedLocation    = GetLocation(5, 5, 5, 5, Uri);
            var documentManager     = new TestDocumentManager();

            documentManager.AddDocument(Uri, Mock.Of <LSPDocumentSnapshot>(MockBehavior.Strict));

            var virtualHtmlUri = new Uri("C:/path/to/file.razor__virtual.html");
            var htmlLocation   = GetLocation(100, 100, 100, 100, virtualHtmlUri);
            var requestInvoker = new Mock <LSPRequestInvoker>(MockBehavior.Strict);

            requestInvoker
            .Setup(r => r.ReinvokeRequestOnServerAsync <TextDocumentPositionParams, Location[]>(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <TextDocumentPositionParams>(), It.IsAny <CancellationToken>()))
            .Callback <string, string, TextDocumentPositionParams, CancellationToken>((method, serverContentType, implementationParams, ct) =>
            {
                Assert.Equal(Methods.TextDocumentImplementationName, method);
                Assert.Equal(RazorLSPConstants.HtmlLSPContentTypeName, serverContentType);
                invokedLSPRequest = true;
            })
            .Returns(Task.FromResult(new[] { htmlLocation }));

            var projectionResult = new ProjectionResult()
            {
                LanguageKind = RazorLanguageKind.Html,
            };
            var projectionProvider = new Mock <LSPProjectionProvider>(MockBehavior.Strict);

            projectionProvider.Setup(p => p.GetProjectionAsync(It.IsAny <LSPDocumentSnapshot>(), It.IsAny <Position>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(projectionResult));

            var documentMappingProvider = new Mock <LSPDocumentMappingProvider>(MockBehavior.Strict);

            documentMappingProvider
            .Setup(d => d.RemapLocationsAsync(It.IsAny <Location[]>(), It.IsAny <CancellationToken>()))
            .Callback <Location[], CancellationToken>((locations, token) =>
            {
                Assert.Equal(htmlLocation, locations[0]);
                invokedRemapRequest = true;
            })
            .Returns(Task.FromResult(Array.Empty <Location>()));

            var implementationHandler = new GoToImplementationHandler(requestInvoker.Object, documentManager, projectionProvider.Object, documentMappingProvider.Object, LoggerProvider);
            var implementationRequest = new TextDocumentPositionParams()
            {
                TextDocument = new TextDocumentIdentifier()
                {
                    Uri = Uri
                },
                Position = new Position(10, 5)
            };

            // Act
            var result = await implementationHandler.HandleRequestAsync(implementationRequest, new ClientCapabilities(), CancellationToken.None).ConfigureAwait(false);

            // Assert
            Assert.True(invokedLSPRequest);
            Assert.True(invokedRemapRequest);

            // Actual remapping behavior is tested elsewhere.
        }
예제 #5
0
        public async Task HandleRequestAsync_CSharpProjection_ReturningVSInternalReferenceItem_InvokesCSharpLanguageServer()
        {
            // Arrange
            var invokedLSPRequest   = false;
            var invokedRemapRequest = false;
            var expectedLocation    = GetLocation(5, 5, 5, 5, Uri);

            var virtualCSharpUri = new Uri("C:/path/to/file.razor.g.cs");
            var csharpLocation   = GetVSInternalReferenceItem(100, 100, 100, 100, virtualCSharpUri);

            var requestInvoker = new Mock <LSPRequestInvoker>(MockBehavior.Strict);

            requestInvoker
            .Setup(r => r.ReinvokeRequestOnServerAsync <TextDocumentPositionParams, SumType <Location[], VSInternalReferenceItem[]> >(
                       It.IsAny <ITextBuffer>(),
                       It.IsAny <string>(),
                       It.IsAny <string>(),
                       It.IsAny <TextDocumentPositionParams>(),
                       It.IsAny <CancellationToken>()))
            .Callback <ITextBuffer, string, string, TextDocumentPositionParams, CancellationToken>((textBuffer, method, clientName, implementationParams, ct) =>
            {
                Assert.Equal(Methods.TextDocumentImplementationName, method);
                Assert.Equal(RazorLSPConstants.RazorCSharpLanguageServerName, clientName);
                invokedLSPRequest = true;
            })
            .Returns(Task.FromResult(new ReinvocationResponse <SumType <Location[], VSInternalReferenceItem[]> >("LanguageClientName", new(new[] { csharpLocation }))));

            var projectionResult = new ProjectionResult()
            {
                LanguageKind = RazorLanguageKind.CSharp,
            };
            var projectionProvider = new Mock <LSPProjectionProvider>(MockBehavior.Strict);

            projectionProvider.Setup(p => p.GetProjectionAsync(It.IsAny <LSPDocumentSnapshot>(), It.IsAny <Position>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(projectionResult));

            var documentMappingProvider = new Mock <LSPDocumentMappingProvider>(MockBehavior.Strict);

            documentMappingProvider
            .Setup(d => d.MapToDocumentRangesAsync(RazorLanguageKind.CSharp, It.IsAny <Uri>(), new[] { csharpLocation.Location.Range }, It.IsAny <CancellationToken>()))
            .Callback <RazorLanguageKind, Uri, Range[], CancellationToken>((languageKind, uri, ranges, ct) =>
            {
                Assert.Equal(csharpLocation.Location.Range, ranges[0]);
                invokedRemapRequest = true;
            })
            .Returns(Task.FromResult(new RazorMapToDocumentRangesResponse()
            {
                HostDocumentVersion = 1,
                Ranges = new[] { csharpLocation.Location.Range }
            }));

            var implementationHandler = new GoToImplementationHandler(requestInvoker.Object, DocumentManager, projectionProvider.Object, documentMappingProvider.Object, LoggerProvider);
            var implementationRequest = new TextDocumentPositionParams()
            {
                TextDocument = new TextDocumentIdentifier()
                {
                    Uri = Uri
                },
                Position = new Position(10, 5)
            };

            // Act
            var result = await implementationHandler.HandleRequestAsync(implementationRequest, new ClientCapabilities(), CancellationToken.None).ConfigureAwait(false);

            // Assert
            Assert.True(invokedLSPRequest);
            Assert.True(invokedRemapRequest);

            Assert.IsType <VSInternalReferenceItem[]>(result.Value);

            // Actual remapping behavior is tested elsewhere.
        }