Exemple #1
0
        public Task <VSInternalDocumentOnAutoInsertResponseItem?> OnAutoInsertAsync(VSInternalDocumentOnAutoInsertParams request, CancellationToken cancellationToken)
        {
            if (request is null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            return(ExecuteRequestAsync <VSInternalDocumentOnAutoInsertParams, VSInternalDocumentOnAutoInsertResponseItem?>(VSInternalMethods.OnAutoInsertName, request, ClientCapabilities, cancellationToken));
        }
Exemple #2
0
        public async Task HandleRequestAsync_InvokesHTMLServer_RemapsEdits()
        {
            // Arrange
            var invokedServer  = false;
            var requestInvoker = new Mock <LSPRequestInvoker>(MockBehavior.Strict);

            requestInvoker
            .Setup(r => r.ReinvokeRequestOnServerAsync <VSInternalDocumentOnAutoInsertParams, VSInternalDocumentOnAutoInsertResponseItem>(
                       It.IsAny <ITextBuffer>(),
                       VSInternalMethods.OnAutoInsertName,
                       It.IsAny <string>(),
                       It.IsAny <VSInternalDocumentOnAutoInsertParams>(),
                       It.IsAny <CancellationToken>()))
            .Callback <ITextBuffer, string, string, VSInternalDocumentOnAutoInsertParams, CancellationToken>((textBuffer, method, serverContentType, formattingParams, ct) => invokedServer = true)
            .Returns(Task.FromResult(new ReinvocationResponse <VSInternalDocumentOnAutoInsertResponseItem>(
                                         "LanguageClientName",
                                         new VSInternalDocumentOnAutoInsertResponseItem()
            {
                TextEdit = new TextEdit()
                {
                    Range = new Range(), NewText = "sometext"
                }, TextEditFormat = InsertTextFormat.Snippet
            })));

            var projectionUri    = new Uri(Uri.AbsoluteUri + "__virtual.html");
            var projectionResult = new ProjectionResult()
            {
                Uri          = projectionUri,
                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);
            var handler = new OnAutoInsertHandler(DocumentManager, requestInvoker.Object, projectionProvider.Object, documentMappingProvider.Object, LoggerProvider);
            var request = new VSInternalDocumentOnAutoInsertParams()
            {
                Character    = "=",
                TextDocument = new TextDocumentIdentifier()
                {
                    Uri = Uri
                },
                Options = new FormattingOptions()
                {
                    OtherOptions = new Dictionary <string, object>()
                },
                Position = new Position(1, 4)
            };

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

            // Assert
            Assert.True(invokedServer);
            Assert.NotNull(response);
        }
        public async Task HandleRequestAsync_RazorProjection_DoesNotInvokeServer()
        {
            // Arrange
            var invokedServer  = false;
            var requestInvoker = new Mock <LSPRequestInvoker>(MockBehavior.Strict);

            requestInvoker
            .Setup(r => r.ReinvokeRequestOnServerAsync <VSInternalDocumentOnAutoInsertParams, VSInternalDocumentOnAutoInsertResponseItem>(
                       It.IsAny <ITextBuffer>(),
                       It.IsAny <string>(),
                       It.IsAny <string>(),
                       It.IsAny <VSInternalDocumentOnAutoInsertParams>(),
                       It.IsAny <CancellationToken>()))
            .Callback <ITextBuffer, string, string, VSInternalDocumentOnAutoInsertParams, CancellationToken>((textBuffer, method, clientName, formattingParams, ct) => invokedServer = true)
            .Returns(Task.FromResult(new ReinvocationResponse <VSInternalDocumentOnAutoInsertResponseItem>("LanguageClientName", new VSInternalDocumentOnAutoInsertResponseItem()
            {
                TextEdit = new TextEdit()
            })));

            var projectionResult = new ProjectionResult()
            {
                LanguageKind = RazorLanguageKind.Razor,
            };
            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 = Mock.Of <LSPDocumentMappingProvider>(MockBehavior.Strict);

            var handler = new OnAutoInsertHandler(DocumentManager, requestInvoker.Object, projectionProvider.Object, documentMappingProvider, LoggerProvider);
            var request = new VSInternalDocumentOnAutoInsertParams()
            {
                Character    = ">",
                TextDocument = new TextDocumentIdentifier()
                {
                    Uri = Uri
                },
                Options = new FormattingOptions()
                {
                    OtherOptions = new Dictionary <string, object>()
                },
                Position = new Position(0, 0)
            };

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

            // Assert
            Assert.False(invokedServer);
            Assert.Null(response);
        }
        public Task <VSInternalDocumentOnAutoInsertResponseItem?> GetDocumentOnAutoInsertAsync(VSInternalDocumentOnAutoInsertParams autoInsertParams, CancellationToken cancellationToken)
        {
            Contract.ThrowIfNull(_clientCapabilities, $"{nameof(InitializeAsync)} has not been called.");

            return(RequestDispatcher.ExecuteRequestAsync <VSInternalDocumentOnAutoInsertParams, VSInternalDocumentOnAutoInsertResponseItem?>(Queue, VSInternalMethods.OnAutoInsertName,
                                                                                                                                             autoInsertParams, _clientCapabilities, ClientName, cancellationToken));
        }