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 highlightHandler = new DocumentHighlightHandler(requestInvoker, documentManager, projectionProvider, documentMappingProvider); var highlightRequest = new DocumentHighlightParams() { TextDocument = new TextDocumentIdentifier() { Uri = Uri }, Position = new Position(0, 1) }; // Act var result = await highlightHandler.HandleRequestAsync(highlightRequest, new ClientCapabilities(), CancellationToken.None).ConfigureAwait(false); // Assert Assert.Null(result); }
public async Task HandleRequestAsync_ProjectionNotFound_ReturnsNull() { // Arrange 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 highlightHandler = new DocumentHighlightHandler(requestInvoker, DocumentManager, projectionProvider, documentMappingProvider, LoggerProvider); var highlightRequest = new DocumentHighlightParams() { TextDocument = new TextDocumentIdentifier() { Uri = Uri }, Position = new Position(0, 1) }; // Act var result = await highlightHandler.HandleRequestAsync(highlightRequest, new ClientCapabilities(), CancellationToken.None).ConfigureAwait(false); // Assert Assert.Null(result); }
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 highlightHandler = new DocumentHighlightHandler(requestInvoker, documentManager, projectionProvider.Object, documentMappingProvider); var highlightRequest = new DocumentHighlightParams() { TextDocument = new TextDocumentIdentifier() { Uri = Uri }, Position = new Position(0, 1) }; // Act var result = await highlightHandler.HandleRequestAsync(highlightRequest, new ClientCapabilities(), CancellationToken.None).ConfigureAwait(false); // Assert Assert.Null(result); }
public async Task HandleRequestAsync_RemapFailure_DiscardsLocation() { // Arrange var called = false; var expectedHighlight = GetHighlight(5, 5, 5, 5); var documentManager = new TestDocumentManager(); documentManager.AddDocument(Uri, Mock.Of <LSPDocumentSnapshot>(d => d.Version == 0, MockBehavior.Strict)); var csharpHighlight = GetHighlight(100, 100, 100, 100); var requestInvoker = GetRequestInvoker <DocumentHighlightParams, DocumentHighlight[]>( new[] { csharpHighlight }, (method, serverContentType, highlightParams, ct) => { Assert.Equal(Methods.TextDocumentDocumentHighlightName, method); Assert.Equal(RazorLSPConstants.CSharpContentTypeName, serverContentType); called = true; }); var projectionResult = new ProjectionResult() { LanguageKind = RazorLanguageKind.CSharp, }; var projectionProvider = GetProjectionProvider(projectionResult); var documentMappingProvider = new Mock <LSPDocumentMappingProvider>(MockBehavior.Strict).Object; Mock.Get(documentMappingProvider).Setup(p => p.MapToDocumentRangesAsync(RazorLanguageKind.CSharp, Uri, It.IsAny <Range[]>(), CancellationToken.None)) .Returns(Task.FromResult <RazorMapToDocumentRangesResponse>(null)); var highlightHandler = new DocumentHighlightHandler(requestInvoker, documentManager, projectionProvider, documentMappingProvider); var highlightRequest = new DocumentHighlightParams() { TextDocument = new TextDocumentIdentifier() { Uri = Uri }, Position = new Position(10, 5) }; // Act var result = await highlightHandler.HandleRequestAsync(highlightRequest, new ClientCapabilities(), CancellationToken.None).ConfigureAwait(false); // Assert Assert.True(called); Assert.Empty(result); }
public async Task HandleRequestAsync_CSharpProjection_RemapsHighlightRange() { // Arrange var called = false; var expectedHighlight = GetHighlight(5, 5, 5, 5); var documentManager = new TestDocumentManager(); documentManager.AddDocument(Uri, Mock.Of <LSPDocumentSnapshot>(d => d.Version == 0)); var csharpHighlight = GetHighlight(100, 100, 100, 100); var requestInvoker = GetRequestInvoker <DocumentHighlightParams, DocumentHighlight[]>( new[] { csharpHighlight }, (method, serverKind, highlightParams, ct) => { Assert.Equal(Methods.TextDocumentDocumentHighlightName, method); Assert.Equal(LanguageServerKind.CSharp, serverKind); called = true; }); var projectionResult = new ProjectionResult() { LanguageKind = RazorLanguageKind.CSharp, }; var projectionProvider = GetProjectionProvider(projectionResult); var documentMappingProvider = GetDocumentMappingProvider(expectedHighlight.Range, 0, RazorLanguageKind.CSharp); var highlightHandler = new DocumentHighlightHandler(requestInvoker, documentManager, projectionProvider, documentMappingProvider); var highlightRequest = new DocumentHighlightParams() { TextDocument = new TextDocumentIdentifier() { Uri = Uri }, Position = new Position(10, 5) }; // Act var result = await highlightHandler.HandleRequestAsync(highlightRequest, new ClientCapabilities(), CancellationToken.None).ConfigureAwait(false); // Assert Assert.True(called); var actualHighlight = Assert.Single(result); Assert.Equal(expectedHighlight.Range, actualHighlight.Range); }
public async Task HandleRequestAsync_VersionMismatch_DiscardsLocation() { // Arrange var called = false; var expectedHighlight = GetHighlight(5, 5, 5, 5); var documentManager = new TestDocumentManager(); documentManager.AddDocument(Uri, Mock.Of <LSPDocumentSnapshot>(d => d.Version == 1)); var csharpHighlight = GetHighlight(100, 100, 100, 100); var requestInvoker = GetRequestInvoker <DocumentHighlightParams, DocumentHighlight[]>( new[] { csharpHighlight }, (method, serverContentType, highlightParams, ct) => { Assert.Equal(Methods.TextDocumentDocumentHighlightName, method); Assert.Equal(RazorLSPConstants.CSharpContentTypeName, serverContentType); called = true; }); var projectionResult = new ProjectionResult() { LanguageKind = RazorLanguageKind.CSharp, }; var projectionProvider = GetProjectionProvider(projectionResult); var documentMappingProvider = GetDocumentMappingProvider(expectedHighlight.Range, 0 /* Different from document version (1) */, RazorLanguageKind.CSharp); var highlightHandler = new DocumentHighlightHandler(requestInvoker, documentManager, projectionProvider, documentMappingProvider); var highlightRequest = new DocumentHighlightParams() { TextDocument = new TextDocumentIdentifier() { Uri = Uri }, Position = new Position(10, 5) }; // Act var result = await highlightHandler.HandleRequestAsync(highlightRequest, new ClientCapabilities(), CancellationToken.None).ConfigureAwait(false); // Assert Assert.True(called); Assert.Empty(result); }
public async Task HandleRequestAsync_HtmlProjection_RemapsHighlightRange() { // Arrange var called = false; var expectedHighlight = GetHighlight(5, 5, 5, 5); var htmlHighlight = GetHighlight(100, 100, 100, 100); var requestInvoker = GetRequestInvoker <DocumentHighlightParams, DocumentHighlight[]>( new[] { htmlHighlight }, (textBuffer, method, clientName, highlightParams, ct) => { Assert.Equal(Methods.TextDocumentDocumentHighlightName, method); Assert.Equal(RazorLSPConstants.HtmlLanguageServerName, clientName); called = true; }); var projectionResult = new ProjectionResult() { LanguageKind = RazorLanguageKind.Html, }; var projectionProvider = GetProjectionProvider(projectionResult); var documentMappingProvider = GetDocumentMappingProvider(expectedHighlight.Range, 0, RazorLanguageKind.Html); var highlightHandler = new DocumentHighlightHandler(requestInvoker, DocumentManager, projectionProvider, documentMappingProvider, LoggerProvider); var highlightRequest = new DocumentHighlightParams() { TextDocument = new TextDocumentIdentifier() { Uri = Uri }, Position = new Position(10, 5) }; // Act var result = await highlightHandler.HandleRequestAsync(highlightRequest, new ClientCapabilities(), CancellationToken.None).ConfigureAwait(false); // Assert Assert.True(called); var actualHighlight = Assert.Single(result); Assert.Equal(expectedHighlight.Range, actualHighlight.Range); }