private static async Task <object[]> RunGetDocumentSymbolsAsync( TestLspServer testLspServer, bool hierarchicalSupport ) { var document = testLspServer.GetCurrentSolution().Projects.First().Documents.First(); var request = new LSP.DocumentSymbolParams { TextDocument = CreateTextDocumentIdentifier(new Uri(document.FilePath)) }; var clientCapabilities = new LSP.ClientCapabilities() { TextDocument = new LSP.TextDocumentClientCapabilities() { DocumentSymbol = new LSP.DocumentSymbolSetting() { HierarchicalDocumentSymbolSupport = hierarchicalSupport } } }; return(await testLspServer.ExecuteRequestAsync <LSP.DocumentSymbolParams, object[]>( LSP.Methods.TextDocumentDocumentSymbolName, request, clientCapabilities, null, CancellationToken.None )); }
private static async Task <TestLspServer> CreateTestLspServerAsync(TestWorkspace workspace, LSP.ClientCapabilities?clientCapabilities, WellKnownLspServerKinds serverKind) { var solution = workspace.CurrentSolution; foreach (var document in workspace.Documents) { if (document.IsSourceGenerated) { continue; } solution = solution.WithDocumentFilePath(document.Id, GetDocumentFilePathFromName(document.Name)); var documentText = await solution.GetRequiredDocument(document.Id).GetTextAsync(CancellationToken.None); solution = solution.WithDocumentText(document.Id, SourceText.From(documentText.ToString(), System.Text.Encoding.UTF8)); } foreach (var project in workspace.Projects) { // Ensure all the projects have a valid file path. solution = solution.WithProjectFilePath(project.Id, GetDocumentFilePathFromName(project.FilePath)); } workspace.ChangeSolution(solution); // Important: We must wait for workspace creation operations to finish. // Otherwise we could have a race where workspace change events triggered by creation are changing the state // created by the initial test steps. This can interfere with the expected test state. await WaitForWorkspaceOperationsAsync(workspace); return(await TestLspServer.CreateAsync(workspace, clientCapabilities ?? new LSP.ClientCapabilities(), serverKind)); }
private static async Task AssertServerQueueClosed(TestLspServer server) { await server.GetQueueAccessor().WaitForProcessingToStopAsync().ConfigureAwait(false); Assert.True(server.GetServerAccessor().HasShutdownStarted()); Assert.True(server.GetQueueAccessor().IsComplete()); }
private static async Task <LSP.DocumentHighlight[]> RunGetDocumentHighlightAsync( TestLspServer testLspServer, LSP.Location caret ) { var results = await testLspServer.ExecuteRequestAsync < LSP.TextDocumentPositionParams, LSP.DocumentHighlight[] >( LSP.Methods.TextDocumentDocumentHighlightName, CreateTextDocumentPositionParams(caret), new LSP.ClientCapabilities(), null, CancellationToken.None ); Array.Sort( results, (h1, h2) => { var compareKind = h1.Kind.CompareTo(h2.Kind); var compareRange = CompareRange(h1.Range, h2.Range); return(compareKind != 0 ? compareKind : compareRange); } ); return(results); }
private static async Task <Solution> GetLSPSolution(TestLspServer testLspServer, Uri uri) { var result = await testLspServer.ExecuteRequestAsync <Uri, Solution>(nameof(GetLSPSolutionHandler), uri, new ClientCapabilities(), null, CancellationToken.None); Contract.ThrowIfNull(result); return(result); }
private static async Task InsertTextAsync( TestLspServer testLspServer, Document document, int position, string text) { var sourceText = await document.GetTextAsync(); var lineInfo = sourceText.Lines.GetLinePositionSpan(new TextSpan(position, 0)); await testLspServer.ExecuteRequestAsync <DidChangeTextDocumentParams, object>( Methods.TextDocumentDidChangeName, new DidChangeTextDocumentParams { TextDocument = ProtocolConversions.DocumentToVersionedTextDocumentIdentifier(document), ContentChanges = new TextDocumentContentChangeEvent[] { new TextDocumentContentChangeEvent { Range = new LSP.Range { Start = ProtocolConversions.LinePositionToPosition(lineInfo.Start), End = ProtocolConversions.LinePositionToPosition(lineInfo.End), }, Text = text, }, }, }, new LSP.ClientCapabilities(), clientName : null, CancellationToken.None); }
private static async Task <Solution> GetLSPSolution(TestLspServer testLspServer, 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); }
private static async Task <T> GetCompletionItemToResolveAsync <T>( TestLspServer testLspServer, Dictionary <string, IList <LSP.Location> > locations, string label, LSP.ClientCapabilities clientCapabilities = null) where T : LSP.CompletionItem { var completionParams = CreateCompletionParams( locations["caret"].Single(), LSP.VSCompletionInvokeKind.Explicit, "\0", LSP.CompletionTriggerKind.Invoked); clientCapabilities ??= new LSP.VSClientCapabilities { SupportsVisualStudioExtensions = true }; var completionList = await RunGetCompletionsAsync(testLspServer, completionParams, clientCapabilities); if (clientCapabilities.HasCompletionListDataCapability()) { var vsCompletionList = Assert.IsAssignableFrom <VSCompletionList>(completionList); Assert.NotNull(vsCompletionList.Data); } var serverCompletionItem = completionList.Items.FirstOrDefault(item => item.Label == label); var clientCompletionItem = ConvertToClientCompletionItem((T)serverCompletionItem); return(clientCompletionItem); }
private static async Task <LSP.CompletionItem> RunResolveCompletionItemAsync(TestLspServer testLspServer, LSP.CompletionItem completionItem, LSP.ClientCapabilities clientCapabilities = null) { clientCapabilities ??= new LSP.VSClientCapabilities { SupportsVisualStudioExtensions = true }; return(await testLspServer.ExecuteRequestAsync <LSP.CompletionItem, LSP.CompletionItem>(LSP.Methods.TextDocumentCompletionResolveName, completionItem, clientCapabilities, null, CancellationToken.None)); }
private static async Task AssertFileInMainWorkspaceAsync(TestLspServer testLspServer, Uri fileUri) { var lspDocument = await testLspServer.GetManager().GetLspDocumentAsync(new LSP.TextDocumentIdentifier { Uri = fileUri }, CancellationToken.None).ConfigureAwait(false); Assert.Equal(testLspServer.TestWorkspace, lspDocument !.Project.Solution.Workspace); }
private Task <TestLspServer> CreateTsTestLspServerAsync(string workspaceXml) { var(clientStream, serverStream) = FullDuplexStream.CreatePair(); var testWorkspace = TestWorkspace.Create(workspaceXml, composition: Composition); var languageServerTarget = CreateLanguageServer(serverStream, serverStream, testWorkspace); return(TestLspServer.CreateAsync(testWorkspace, new ClientCapabilities(), languageServerTarget, clientStream)); }
private static Task <LSP.CompletionList> RunGetCompletionsAsync(TestLspServer testLspServer, LSP.CompletionParams completionParams) { var clientCapabilities = new LSP.VSClientCapabilities { SupportsVisualStudioExtensions = true }; return(RunGetCompletionsAsync(testLspServer, completionParams, clientCapabilities)); }
private static CompletionListCache GetCompletionListCache(TestLspServer testLspServer) { var dispatchAccessor = testLspServer.GetDispatcherAccessor(); var handler = (CompletionHandler)dispatchAccessor.GetHandler <LSP.CompletionParams, LSP.CompletionList>(LSP.Methods.TextDocumentCompletionName); Assert.NotNull(handler); return(handler.GetTestAccessor().GetCache()); }
private static async Task <LSP.CompletionList> RunGetCompletionsAsync( TestLspServer testLspServer, LSP.CompletionParams completionParams, LSP.VSClientCapabilities clientCapabilities) { return(await testLspServer.ExecuteRequestAsync <LSP.CompletionParams, LSP.CompletionList>(LSP.Methods.TextDocumentCompletionName, completionParams, clientCapabilities, null, CancellationToken.None)); }
private static async Task <LSP.Hover> RunGetHoverAsync(TestLspServer testLspServer, LSP.Location caret) { var result = await testLspServer.ExecuteRequestAsync <LSP.TextDocumentPositionParams, LSP.Hover>(LSP.Methods.TextDocumentHoverName, CreateTextDocumentPositionParams(caret), CancellationToken.None); Contract.ThrowIfNull(result); return(result); }
private static async Task AssertFileInMiscWorkspaceAsync(TestLspServer testLspServer, Uri fileUri) { var lspDocument = await testLspServer.GetManager().GetLspDocumentAsync(new LSP.TextDocumentIdentifier { Uri = fileUri }, CancellationToken.None); Assert.Equal(testLspServer.GetManagerAccessor().GetLspMiscellaneousFilesWorkspace(), lspDocument !.Project.Solution.Workspace); }
private static async Task <LSP.VSInternalCodeAction> RunGetCodeActionResolveAsync( TestLspServer testLspServer, VSInternalCodeAction unresolvedCodeAction) { var result = (VSInternalCodeAction)await testLspServer.ExecuteRequestAsync <LSP.CodeAction, LSP.CodeAction>( LSP.Methods.CodeActionResolveName, unresolvedCodeAction, CancellationToken.None); return(result); }
private static async Task <LSP.CompletionList> RunGetCompletionsAsync(TestLspServer testLspServer, LSP.CompletionParams completionParams) { var clientCapabilities = new LSP.VSClientCapabilities { SupportsVisualStudioExtensions = true }; return(await testLspServer.ExecuteRequestAsync <LSP.CompletionParams, LSP.CompletionList>(LSP.Methods.TextDocumentCompletionName, completionParams, clientCapabilities, null, CancellationToken.None)); }
private static Solution GetLSPSolution(TestLspServer testLspServer, Uri uri) { var lspDocument = testLspServer.GetManager().GetLspDocument(new TextDocumentIdentifier { Uri = uri }); Contract.ThrowIfNull(lspDocument); return(lspDocument.Project.Solution); }
private static async Task <Solution> GetLSPSolutionAsync(TestLspServer testLspServer, Uri uri) { var lspDocument = await testLspServer.GetManager().GetLspDocumentAsync(new TextDocumentIdentifier { Uri = uri }, CancellationToken.None).ConfigureAwait(false); Contract.ThrowIfNull(lspDocument); return(lspDocument.Project.Solution); }
private static async Task <LSP.TextEdit[]> RunFormatDocumentAsync( TestLspServer testLspServer, Uri uri, bool insertSpaces = true, int tabSize = 4) { return(await testLspServer.ExecuteRequestAsync <LSP.DocumentFormattingParams, LSP.TextEdit[]>(LSP.Methods.TextDocumentFormattingName, CreateDocumentFormattingParams(uri, insertSpaces, tabSize), new LSP.ClientCapabilities(), null, CancellationToken.None)); }
internal static async Task <LSP.VSReferenceItem[]> RunFindAllReferencesAsync(TestLspServer testLspServer, LSP.Location caret, IProgress <object> progress = null) { var vsClientCapabilities = new LSP.VSClientCapabilities { SupportsVisualStudioExtensions = true }; return(await testLspServer.ExecuteRequestAsync <LSP.ReferenceParams, LSP.VSReferenceItem[]>(LSP.Methods.TextDocumentReferencesName, CreateReferenceParams(caret, progress), vsClientCapabilities, null, CancellationToken.None)); }
private static async Task <LSP.VSInternalDocumentOnAutoInsertResponseItem?> RunOnAutoInsertAsync( TestLspServer testLspServer, string characterTyped, LSP.Location locationTyped, bool insertSpaces, int tabSize) { return(await testLspServer.ExecuteRequestAsync <LSP.VSInternalDocumentOnAutoInsertParams, LSP.VSInternalDocumentOnAutoInsertResponseItem?>(VSInternalMethods.OnAutoInsertName, CreateDocumentOnAutoInsertParams(characterTyped, locationTyped, insertSpaces, tabSize), CancellationToken.None)); }
private static async Task <LSP.VSCodeAction> RunGetCodeActionResolveAsync( TestLspServer testLspServer, VSCodeAction unresolvedCodeAction, LSP.ClientCapabilities clientCapabilities = null) { var result = await testLspServer.ExecuteRequestAsync <LSP.VSCodeAction, LSP.VSCodeAction>( LSP.MSLSPMethods.TextDocumentCodeActionResolveName, unresolvedCodeAction, clientCapabilities, null, CancellationToken.None); return(result); }
private static Task <Solution> GetLSPSolution(TestLspServer testLspServer, Uri uri) { return(testLspServer.ExecuteRequestAsync <Uri, Solution>( nameof(GetLSPSolutionHandler), uri, new ClientCapabilities(), null, CancellationToken.None )); }
private static Task <LSP.SymbolInformation[]?> RunGetWorkspaceSymbolsAsync(TestLspServer testLspServer, string query, IProgress <LSP.SymbolInformation[]>?progress = null) { var request = new LSP.WorkspaceSymbolParams { Query = query, PartialResultToken = progress }; return(testLspServer.ExecuteRequestAsync <LSP.WorkspaceSymbolParams, LSP.SymbolInformation[]>(LSP.Methods.WorkspaceSymbolName, request, new LSP.ClientCapabilities(), null, CancellationToken.None)); }
private static async Task <TReturn> RunGetDocumentSymbolsAsync <TReturn>(TestLspServer testLspServer) { var document = testLspServer.GetCurrentSolution().Projects.First().Documents.First(); var request = new LSP.DocumentSymbolParams { TextDocument = CreateTextDocumentIdentifier(new Uri(document.FilePath)) }; return(await testLspServer.ExecuteRequestAsync <LSP.DocumentSymbolParams, TReturn>(LSP.Methods.TextDocumentDocumentSymbolName, request, CancellationToken.None)); }
private static async Task <LSP.TextEdit[]> RunFormatDocumentOnTypeAsync( TestLspServer testLspServer, string characterTyped, LSP.Location locationTyped, bool insertSpaces = true, int tabSize = 4) { return(await testLspServer.ExecuteRequestAsync <LSP.DocumentOnTypeFormattingParams, LSP.TextEdit[]>(LSP.Methods.TextDocumentOnTypeFormattingName, CreateDocumentOnTypeFormattingParams( characterTyped, locationTyped, insertSpaces, tabSize), CancellationToken.None)); }
private static List <Task <TestResponse?> > StartTestRun(TestLspServer testLspServer, TestRequest[] requests, CancellationToken cancellationToken = default) { var waitables = new List <Task <TestResponse?> >(); foreach (var request in requests) { waitables.Add(testLspServer.ExecuteRequestAsync <TestRequest, TestResponse>(request.MethodName, request, cancellationToken)); } return(waitables); }
private static async Task <LSP.FoldingRange[]> RunGetFoldingRangeAsync(TestLspServer testLspServer) { var document = testLspServer.GetCurrentSolution().Projects.First().Documents.First(); var request = new LSP.FoldingRangeParams() { TextDocument = CreateTextDocumentIdentifier(new Uri(document.FilePath)) }; return(await testLspServer.ExecuteRequestAsync <LSP.FoldingRangeParams, LSP.FoldingRange[]>(LSP.Methods.TextDocumentFoldingRangeName, request, CancellationToken.None)); }