Beispiel #1
0
 private static async Task ExecuteDidOpen(TestLspServer testLspServer, Uri documentUri)
 {
     var didOpenParams = new LSP.DidOpenTextDocumentParams
     {
         TextDocument = new LSP.TextDocumentItem
         {
             Uri  = documentUri,
             Text = "// hi there"
         }
     };
     await testLspServer.ExecuteRequestAsync <LSP.DidOpenTextDocumentParams, object>(Methods.TextDocumentDidOpenName, didOpenParams, CancellationToken.None);
 }
Beispiel #2
0
 private static async Task DidOpen(
     TestLspServer testLspServer,
     LSP.DidOpenTextDocumentParams didOpenParams
     )
 {
     await testLspServer.ExecuteRequestAsync <LSP.DidOpenTextDocumentParams, object>(
         Methods.TextDocumentDidOpenName,
         didOpenParams,
         new LSP.ClientCapabilities(),
         null,
         CancellationToken.None
         );
 }
Beispiel #3
0
        public async Task NonMutatingRequestsOperateOnTheSameSolutionAfterMutation()
        {
            using var testLspServer = CreateTestLspServer("class C { {|caret:|} }", out var locations);

            var expectedSolution = testLspServer.GetCurrentSolution();

            // solution should be the same because no mutations have happened
            var solution = await GetLSPSolution(NonMutatingRequestHandler.MethodName);

            Assert.Equal(expectedSolution, solution);

            // Open a document, to get a forked solution
            await ExecuteDidOpen();

            // solution should be different because there has been a mutation
            solution = await GetLSPSolution(NonMutatingRequestHandler.MethodName);

            Assert.NotEqual(expectedSolution, solution);

            expectedSolution = solution;

            // solution should be the same because no mutations have happened
            solution = await GetLSPSolution(NonMutatingRequestHandler.MethodName);

            Assert.Equal(expectedSolution, solution);

            // Apply some random change to the workspace that the LSP server doesn't "see"
            testLspServer.TestWorkspace.SetCurrentSolution(s => s.WithProjectName(s.Projects.First().Id, "NewName"), WorkspaceChangeKind.ProjectChanged);

            expectedSolution = testLspServer.GetCurrentSolution();

            // solution should be different because there has been a workspace change
            solution = await GetLSPSolution(NonMutatingRequestHandler.MethodName);

            Assert.NotEqual(expectedSolution, solution);

            expectedSolution = solution;

            // solution should be the same because no mutations have happened
            solution = await GetLSPSolution(NonMutatingRequestHandler.MethodName);

            Assert.Equal(expectedSolution, solution);

            return;

            async Task <Solution> GetLSPSolution(string methodName)
            {
                var request  = new TestRequest(methodName);
                var response = await testLspServer.ExecuteRequestAsync <TestRequest, TestResponse>(request.MethodName, request, new LSP.ClientCapabilities(), null, CancellationToken.None);

                return(response.Solution);
            }

            async Task ExecuteDidOpen()
            {
                var didOpenParams = new LSP.DidOpenTextDocumentParams
                {
                    TextDocument = new LSP.TextDocumentItem
                    {
                        Uri  = locations["caret"].First().Uri,
                        Text = "// hi there"
                    }
                };
                await testLspServer.ExecuteRequestAsync <LSP.DidOpenTextDocumentParams, object>(Methods.TextDocumentDidOpenName, didOpenParams, new LSP.ClientCapabilities(), null, CancellationToken.None);
            }
        }
Beispiel #4
0
 public Task InvokeTextDocumentDidOpenAsync(LSP.DidOpenTextDocumentParams request)
 => NotifyWithParametersAsync("textDocument/didOpen", request);
 private static async Task DidOpen(RequestExecutionQueue queue, Solution solution, LSP.DidOpenTextDocumentParams didOpenParams)
 {
     await GetLanguageServer(solution).ExecuteRequestAsync <LSP.DidOpenTextDocumentParams, object>(queue, Methods.TextDocumentDidOpenName,
                                                                                                   didOpenParams, new LSP.ClientCapabilities(), null, CancellationToken.None);
 }