public async Task HandleRequestAsync_NonNullOriginalTextEdit_DoesNotRemapTextEdit()
        {
            // Arrange
            var originalEdit = new TextEdit()
            {
                NewText = "original"
            };
            var mappedEdit = new TextEdit()
            {
                NewText = "mapped"
            };

            DocumentMappingProvider.AddMapping(originalEdit, mappedEdit);

            var requestedCompletionItem = new CompletionItem()
            {
                TextEdit = originalEdit,
            };

            AssociateRequest(LanguageServerKind.CSharp, requestedCompletionItem, CompletionRequestContextCache, LoggerProvider);
            var resolvedCompletionItem = new CompletionItem()
            {
                InsertText = "DateTime",
                TextEdit   = originalEdit,
            };
            var requestInvoker = CreateRequestInvoker((method, serverContentType, completionItem) => resolvedCompletionItem);
            var handler        = new CompletionResolveHandler(requestInvoker, DocumentMappingProvider, FormattingOptionsProvider, CompletionRequestContextCache, LoggerProvider);

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

            // Assert
            Assert.Same(originalEdit, result.TextEdit);
        }
        public async Task HandleRequestAsync_InvokesHtmlLanguageServer()
        {
            // Arrange
            var called       = false;
            var originalData = new object();
            var request      = new CompletionItem()
            {
                InsertText = "strong",
            };

            AssociateRequest(LanguageServerKind.Html, request, CompletionRequestContextCache, originalData);
            var expectedResponse = new CompletionItem()
            {
                InsertText = "strong",
                Data       = originalData,
                Detail     = "Some documentation"
            };
            var requestInvoker = CreateRequestInvoker((method, serverContentType, completionItem) =>
            {
                Assert.Equal(Methods.TextDocumentCompletionResolveName, method);
                Assert.Equal(RazorLSPConstants.HtmlLSPContentTypeName, serverContentType);
                Assert.Same(originalData, completionItem.Data);
                called = true;
                return(expectedResponse);
            });

            var handler = new CompletionResolveHandler(requestInvoker, DocumentMappingProvider, FormattingOptionsProvider, CompletionRequestContextCache, LoggerProvider);

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

            // Assert
            Assert.True(called);
            Assert.Same(expectedResponse, result);
        }
        public async Task HandleRequestAsync_NullInsertTextAndTextEdit_RemapsAdditionalTextEdits()
        {
            // Arrange
            var originalEdit = new TextEdit()
            {
                NewText = "original"
            };
            var mappedEdit = new TextEdit()
            {
                NewText = "mapped"
            };

            DocumentMappingProvider.AddMapping(originalEdit, mappedEdit);
            var requestedCompletionItem = new CompletionItem();

            AssociateRequest(LanguageServerKind.CSharp, requestedCompletionItem, CompletionRequestContextCache, LoggerProvider);
            var resolvedCompletionItem = new CompletionItem()
            {
                AdditionalTextEdits = new[] { originalEdit },
            };
            var requestInvoker = CreateRequestInvoker((method, languageServerName, completionItem) => resolvedCompletionItem);
            var handler        = new CompletionResolveHandler(requestInvoker, DocumentManager, DocumentMappingProvider, FormattingOptionsProvider, CompletionRequestContextCache, LoggerProvider);

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

            // Assert
            Assert.Equal(new[] { mappedEdit }, result.AdditionalTextEdits);
        }
        public async Task HandleRequestAsync_ResolvedNullTextEdit_Noops()
        {
            // Arrange
            var requestedCompletionItem = new CompletionItem();

            AssociateRequest(LanguageServerKind.CSharp, requestedCompletionItem, CompletionRequestContextCache, LoggerProvider);
            var resolvedCompletionItem = new CompletionItem()
            {
                InsertText = "DateTime",
            };
            var requestInvoker = CreateRequestInvoker((method, serverContentType, completionItem) => resolvedCompletionItem);
            var handler        = new CompletionResolveHandler(requestInvoker, DocumentMappingProvider, FormattingOptionsProvider, CompletionRequestContextCache, LoggerProvider);

            // Act & Assert
            var result = await handler.HandleRequestAsync(requestedCompletionItem, new ClientCapabilities(), CancellationToken.None).ConfigureAwait(false);
        }
        public async Task HandleRequestAsync_InvokesCSharpLanguageServer()
        {
            // Arrange
            var called       = false;
            var originalData = new object();
            var request      = new CompletionItem()
            {
                InsertText = "DateTime",
                Data       = new CompletionResolveData()
                {
                    LanguageServerKind = LanguageServerKind.CSharp, OriginalData = originalData
                }
            };
            var expectedResponse = new CompletionItem()
            {
                InsertText = "DateTime",
                Data       = originalData,
                Detail     = "Some documentation"
            };

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

            requestInvoker
            .Setup(r => r.ReinvokeRequestOnServerAsync <CompletionItem, CompletionItem>(It.IsAny <string>(), LanguageServerKind.CSharp, It.IsAny <CompletionItem>(), It.IsAny <CancellationToken>()))
            .Callback <string, LanguageServerKind, CompletionItem, CancellationToken>((method, serverKind, completionItem, ct) =>
            {
                Assert.Equal(Methods.TextDocumentCompletionResolveName, method);
                Assert.Equal(LanguageServerKind.CSharp, serverKind);
                Assert.Same(originalData, completionItem.Data);
                called = true;
            })
            .Returns(Task.FromResult <CompletionItem>(expectedResponse));

            var handler = new CompletionResolveHandler(requestInvoker.Object);

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

            // Assert
            Assert.True(called);
            Assert.Same(expectedResponse, result);
        }
        public async Task HandleRequestAsync_DoesNotInvokeHtmlLanguageServer()
        {
            // Arrange
            var originalData = new object();
            var request      = new CompletionItem()
            {
                InsertText = "div",
                Data       = new CompletionResolveData()
                {
                    LanguageServerKind = LanguageServerKind.Html, OriginalData = originalData
                }
            };

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

            var handler = new CompletionResolveHandler(requestInvoker.Object);

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

            // Assert (Does not throw with MockBehavior.Strict)
            Assert.Equal("div", result.InsertText);
            Assert.Same(originalData, result.Data);
        }