public async Task TestResolveCompletionItemAsync() { var markup = @"class A { void M() { {|caret:|} } }"; var(solution, locations) = CreateTestSolution(markup); var tags = new string[] { "Class", "Internal" }; var completionParams = CreateCompletionParams(locations["caret"].Single()); var completionItem = CreateCompletionItem("A", LSP.CompletionItemKind.Class, tags, completionParams); var description = new ClassifiedTextElement(CreateClassifiedTextRunForClass("A")); var clientCapabilities = new LSP.VSClientCapabilities { SupportsVisualStudioExtensions = true }; var expected = CreateResolvedCompletionItem("A", LSP.CompletionItemKind.Class, null, completionParams, description, "class A", null); var results = (LSP.VSCompletionItem) await RunResolveCompletionItemAsync(solution, completionItem, clientCapabilities); AssertJsonEquals(expected, results); }
public async Task TestGetCompletionsDoesNotIncludeUnimportedTypesAsync() { var markup = @"class A { void M() { {|caret:|} } }"; var(solution, locations) = CreateTestSolution(markup); // Make sure the unimported types option is on by default. solution = solution.WithOptions(solution.Options .WithChangedOption(CompletionOptions.ShowItemsFromUnimportedNamespaces, LanguageNames.CSharp, true) .WithChangedOption(CompletionServiceOptions.IsExpandedCompletion, true)); var expected = CreateCompletionItem("A", LSP.CompletionItemKind.Class, new string[] { "Class", "Internal" }, CreateCompletionParams(locations["caret"].Single())); var clientCapabilities = new LSP.VSClientCapabilities { SupportsVisualStudioExtensions = true }; var results = (LSP.CompletionItem[]) await RunGetCompletionsAsync(solution, locations["caret"].Single(), clientCapabilities); Assert.False(results.Any(item => "Console" == item.Label)); }
public async Task TestResolveCompletionItemAsync() { var markup = @"class A { void M() { {|caret:|} } }"; using var testLspServer = CreateTestLspServer(markup, out var locations); var tags = new string[] { "Class", "Internal" }; var completionParams = CreateCompletionParams(locations["caret"].Single(), LSP.VSCompletionInvokeKind.Explicit, "\0", LSP.CompletionTriggerKind.Invoked); var document = testLspServer.GetCurrentSolution().Projects.First().Documents.First(); var completionItem = await CreateCompletionItemAsync( "A", LSP.CompletionItemKind.Class, tags, completionParams, document, commitCharacters : CompletionRules.Default.DefaultCommitCharacters).ConfigureAwait(false); var description = new ClassifiedTextElement(CreateClassifiedTextRunForClass("A")); var clientCapabilities = new LSP.VSClientCapabilities { SupportsVisualStudioExtensions = true }; var expected = CreateResolvedCompletionItem(completionItem, description, "class A", null); var results = (LSP.VSCompletionItem) await RunResolveCompletionItemAsync(testLspServer, completionItem, clientCapabilities).ConfigureAwait(false); AssertJsonEquals(expected, results); }
public async Task TestResolveCompletionItemAsync() { var markup = @"class A { void M() { {|caret:|} } }"; using var workspace = CreateTestWorkspace(markup, out var locations); var tags = new string[] { "Class", "Internal" }; var completionParams = CreateCompletionParams(locations["caret"].Single(), "\0", LSP.CompletionTriggerKind.Invoked); var commitCharacters = new string[] { " ", "{", "}", "[", "]", "(", ")", ".", ",", ":", ";", "+", "-", "*", "/", "%", "&", "|", "^", "!", "~", "=", "<", ">", "?", "@", "#", "'", "\"", "\\" }; var completionItem = CreateCompletionItem ("A", LSP.CompletionItemKind.Class, tags, completionParams, commitCharacters: commitCharacters); var description = new ClassifiedTextElement(CreateClassifiedTextRunForClass("A")); var clientCapabilities = new LSP.VSClientCapabilities { SupportsVisualStudioExtensions = true }; var expected = CreateResolvedCompletionItem( "A", LSP.CompletionItemKind.Class, null, completionParams, description, "class A", null, commitCharacters); var results = (LSP.VSCompletionItem) await RunResolveCompletionItemAsync(workspace.CurrentSolution, completionItem, clientCapabilities); AssertJsonEquals(expected, results); }
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 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.CompletionList> RunGetCompletionsAsync(Solution solution, LSP.CompletionParams completionParams) { var clientCapabilities = new LSP.VSClientCapabilities { SupportsVisualStudioExtensions = true }; return(await GetLanguageServer(solution).ExecuteRequestAsync <LSP.CompletionParams, LSP.CompletionList>(LSP.Methods.TextDocumentCompletionName, completionParams, clientCapabilities, null, CancellationToken.None)); }
private static async Task <LSP.VSReferenceItem[]> RunFindAllReferencesAsync(Solution solution, LSP.Location caret) { var vsClientCapabilities = new LSP.VSClientCapabilities { SupportsVisualStudioExtensions = true }; return(await GetLanguageServer(solution).ExecuteRequestAsync <LSP.ReferenceParams, LSP.VSReferenceItem[]>(LSP.Methods.TextDocumentReferencesName, solution, CreateReferenceParams(caret), vsClientCapabilities, null, CancellationToken.None)); }
internal static async Task <LSP.VSReferenceItem[]> RunFindAllReferencesAsync(Handler.RequestExecutionQueue queue, Solution solution, LSP.Location caret, IProgress <object> progress = null) { var vsClientCapabilities = new LSP.VSClientCapabilities { SupportsVisualStudioExtensions = true }; return(await GetLanguageServer(solution).ExecuteRequestAsync <LSP.ReferenceParams, LSP.VSReferenceItem[]>(queue, LSP.Methods.TextDocumentReferencesName, CreateReferenceParams(caret, progress), vsClientCapabilities, 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 }; var results = await testLspServer.ExecuteRequestAsync <LSP.ReferenceParams, LSP.ReferenceItem[]>(LSP.Methods.TextDocumentReferencesName, CreateReferenceParams(caret, progress), vsClientCapabilities, null, CancellationToken.None); return(results?.Cast <LSP.VSReferenceItem>()?.ToArray()); }
public async Task TestResolveOverridesCompletionItemAsync() { var markup = @"abstract class A { public abstract void M(); } class B : A { override {|caret:|} }"; using var testLspServer = CreateTestLspServer(markup, out var locations); var tags = new string[] { "Method", "Public" }; var completionParams = CreateCompletionParams( locations["caret"].Single(), LSP.VSCompletionInvokeKind.Explicit, "\0", LSP.CompletionTriggerKind.Invoked ); var completionList = await RunGetCompletionsAsync(testLspServer, completionParams); var serverCompletionItem = completionList.Items.FirstOrDefault( item => item.Label == "M()" ); var completionResultId = ((CompletionResolveData)serverCompletionItem.Data).ResultId.Value; var document = testLspServer.GetCurrentSolution().Projects.First().Documents.First(); var clientCompletionItem = ConvertToClientCompletionItem(serverCompletionItem); var clientCapabilities = new LSP.VSClientCapabilities { SupportsVisualStudioExtensions = true }; var results = (LSP.VSCompletionItem) await RunResolveCompletionItemAsync( testLspServer, clientCompletionItem, clientCapabilities ) .ConfigureAwait(false); Assert.NotNull(results.TextEdit); Assert.Null(results.InsertText); Assert.Equal( @"public override void M() { throw new System.NotImplementedException(); }", results.TextEdit.NewText ); }
public async Task TestResolveCompletionItemFromListAsync() { var markup = @"class A { void M() { {|caret:|} } }"; using var testLspServer = CreateTestLspServer(markup, out var locations); var tags = new string[] { "Class", "Internal" }; var completionParams = CreateCompletionParams( locations["caret"].Single(), LSP.VSCompletionInvokeKind.Explicit, "\0", LSP.CompletionTriggerKind.Invoked); var clientCapabilities = new LSP.VSClientCapabilities { SupportsVisualStudioExtensions = true, TextDocument = new TextDocumentClientCapabilities() { Completion = new VSCompletionSetting() { CompletionList = new VSCompletionListSetting() { Data = true, } } } }; var completionList = await RunGetCompletionsAsync(testLspServer, completionParams, clientCapabilities); var serverCompletionItem = completionList.Items.FirstOrDefault(item => item.Label == "A"); var completionResultId = ((CompletionResolveData)serverCompletionItem.Data).ResultId.Value; var document = testLspServer.GetCurrentSolution().Projects.First().Documents.First(); var clientCompletionItem = ConvertToClientCompletionItem(serverCompletionItem); var description = new ClassifiedTextElement(CreateClassifiedTextRunForClass("A")); var expected = CreateResolvedCompletionItem(clientCompletionItem, description, "class A", null); var results = (LSP.VSCompletionItem) await RunResolveCompletionItemAsync( testLspServer, clientCompletionItem, clientCapabilities).ConfigureAwait(false); AssertJsonEquals(expected, results); var vsCompletionList = Assert.IsAssignableFrom <VSCompletionList>(completionList); Assert.NotNull(vsCompletionList.Data); }
public async Task TestGetCompletionsAsync_PromotesCommitCharactersToListAsync() { var clientCapabilities = new LSP.VSClientCapabilities { SupportsVisualStudioExtensions = true, TextDocument = new LSP.TextDocumentClientCapabilities() { Completion = new LSP.VSCompletionSetting() { CompletionList = new LSP.VSCompletionListSetting() { CommitCharacters = true, } } } }; var markup = @"class A { void M() { {|caret:|} } }"; using var testLspServer = CreateTestLspServer(markup, out var locations); var completionParams = CreateCompletionParams( locations["caret"].Single(), invokeKind: LSP.VSCompletionInvokeKind.Explicit, triggerCharacter: "\0", triggerKind: LSP.CompletionTriggerKind.Invoked); var document = testLspServer.GetCurrentSolution().Projects.First().Documents.First(); var expected = await CreateCompletionItemAsync(label : "A", kind : LSP.CompletionItemKind.Class, tags : new string[] { "Class", "Internal" }, request : completionParams, document : document, commitCharacters : CompletionRules.Default.DefaultCommitCharacters, insertText : "A").ConfigureAwait(false); var expectedCommitCharacters = expected.CommitCharacters; // Null out the commit characters since we're expecting the commit characters will be lifted onto the completion list. expected.CommitCharacters = null; var results = await RunGetCompletionsAsync(testLspServer, completionParams, clientCapabilities).ConfigureAwait(false); AssertJsonEquals(expected, results.Items.First()); var vsCompletionList = Assert.IsAssignableFrom <LSP.VSCompletionList>(results); Assert.Equal(expectedCommitCharacters, vsCompletionList.CommitCharacters.Value.First); }
public async Task TestResolveOverridesCompletionItem_SnippetsEnabledAsync() { var markup = @"abstract class A { public abstract void M(); } class B : A { override {|caret:|} }"; using var testLspServer = CreateTestLspServer(markup, out var locations); var tags = new string[] { "Method", "Public" }; var completionParams = CreateCompletionParams( locations["caret"].Single(), LSP.VSCompletionInvokeKind.Explicit, "\0", LSP.CompletionTriggerKind.Invoked); var document = testLspServer.GetCurrentSolution().Projects.First().Documents.First(); var completionItem = await CreateCompletionItemAsync( label : "M()", LSP.CompletionItemKind.Method, tags, completionParams, document, commitCharacters : CompletionRules.Default.DefaultCommitCharacters).ConfigureAwait(false); // Explicitly enable snippets. This allows us to set the cursor with $0. Currently only applies to C# in Razor docs. var clientCapabilities = new LSP.VSClientCapabilities { SupportsVisualStudioExtensions = true, TextDocument = new LSP.TextDocumentClientCapabilities { Completion = new CompletionSetting { CompletionItem = new CompletionItemSetting { SnippetSupport = true } } } }; var results = (LSP.VSCompletionItem) await RunResolveCompletionItemAsync( testLspServer, completionItem, clientCapabilities).ConfigureAwait(false); Assert.NotNull(results.TextEdit); Assert.Null(results.InsertText); Assert.Equal(@"public override void M() { throw new System.NotImplementedException();$0 }", results.TextEdit.NewText); }
private static async Task <LSP.VSReferenceItem[]> RunFindAllReferencesAsync(Solution solution, LSP.Location caret) { var vsClientCapabilities = new LSP.VSClientCapabilities { SupportsVisualStudioExtensions = true }; var progress = new ProgressCollector <LSP.VSReferenceItem>(); var queue = CreateRequestQueue(solution); await GetLanguageServer(solution).ExecuteRequestAsync <LSP.ReferenceParams, LSP.VSReferenceItem[]>(queue, LSP.Methods.TextDocumentReferencesName, CreateReferenceParams(caret, progress), vsClientCapabilities, null, CancellationToken.None); return(progress.GetItems()); }
public async Task TestResolveOverridesCompletionItem_SnippetsEnabledAsync() { var markup = @"abstract class A { public abstract void M(); } class B : A { override {|caret:|} }"; using var testLspServer = CreateTestLspServer(markup, out var locations); // Explicitly enable snippets. This allows us to set the cursor with $0. Currently only applies to C# in Razor docs. var clientCapabilities = new LSP.VSClientCapabilities { SupportsVisualStudioExtensions = true, TextDocument = new LSP.TextDocumentClientCapabilities { Completion = new CompletionSetting { CompletionItem = new CompletionItemSetting { SnippetSupport = true } } } }; var clientCompletionItem = await GetCompletionItemToResolveAsync <LSP.VSCompletionItem>( testLspServer, locations, label : "M()", clientCapabilities).ConfigureAwait(false); var results = (LSP.VSCompletionItem) await RunResolveCompletionItemAsync( testLspServer, clientCompletionItem, clientCapabilities).ConfigureAwait(false); Assert.NotNull(results.TextEdit); Assert.Null(results.InsertText); Assert.Equal(@"public override void M() { throw new System.NotImplementedException();$0 }", results.TextEdit.NewText); }
public async Task TestGetCompletionsAsync() { var markup = @"class A { void M() { {|caret:|} } }"; var(solution, locations) = CreateTestSolution(markup); var expected = CreateCompletionItem("A", LSP.CompletionItemKind.Class, new string[] { "Class", "Internal" }, CreateCompletionParams(locations["caret"].Single())); var clientCapabilities = new LSP.VSClientCapabilities { SupportsVisualStudioExtensions = true }; var results = (LSP.CompletionItem[]) await RunGetCompletionsAsync(solution, locations["caret"].Single(), clientCapabilities); AssertJsonEquals(expected, results.First()); }
public async Task TestGetCompletionsAsync() { var markup = @"class A { void M() { {|caret:|} } }"; using var workspace = CreateTestWorkspace(markup, out var locations); var expected = CreateCompletionItem("A", LSP.CompletionItemKind.Class, new string[] { "Class", "Internal" }, CreateCompletionParams(locations["caret"].Single())); var clientCapabilities = new LSP.VSClientCapabilities { SupportsVisualStudioExtensions = true }; var results = await RunGetCompletionsAsync(workspace.CurrentSolution, locations["caret"].Single(), clientCapabilities).ConfigureAwait(false); AssertJsonEquals(expected, results.First()); }
public async Task TestResolveCompletionItemFromListAsync() { var markup = @"class A { void M() { {|caret:|} } }"; using var testLspServer = CreateTestLspServer(markup, out var locations); var clientCapabilities = new LSP.VSClientCapabilities { SupportsVisualStudioExtensions = true, TextDocument = new TextDocumentClientCapabilities() { Completion = new VSCompletionSetting() { CompletionList = new VSCompletionListSetting() { Data = true, } } } }; var clientCompletionItem = await GetCompletionItemToResolveAsync <LSP.VSCompletionItem>( testLspServer, locations, label : "A", clientCapabilities).ConfigureAwait(false); var description = new ClassifiedTextElement(CreateClassifiedTextRunForClass("A")); var expected = CreateResolvedCompletionItem(clientCompletionItem, description, "class A", null); var results = (LSP.VSCompletionItem) await RunResolveCompletionItemAsync( testLspServer, clientCompletionItem, clientCapabilities).ConfigureAwait(false); AssertJsonEquals(expected, results); }
public async Task TestGetCompletionsDoesNotIncludeSnippetsAsync() { var markup = @"class A { {|caret:|} }"; using var workspace = CreateTestWorkspace(markup, out var locations); var solution = workspace.CurrentSolution; solution = solution.WithOptions(solution.Options .WithChangedOption(CompletionOptions.SnippetsBehavior, LanguageNames.CSharp, SnippetsRule.AlwaysInclude)); var clientCapabilities = new LSP.VSClientCapabilities { SupportsVisualStudioExtensions = true }; var results = await RunGetCompletionsAsync(solution, locations["caret"].Single(), clientCapabilities); Assert.False(results.Any(item => "ctor" == item.Label)); }
private static async Task <LSP.CompletionList> RunGetCompletionsAsync( TestLspServer testLspServer, LSP.CompletionParams completionParams, LSP.VSClientCapabilities clientCapabilities) { var completionList = await testLspServer.ExecuteRequestAsync <LSP.CompletionParams, LSP.CompletionList>(LSP.Methods.TextDocumentCompletionName, completionParams, clientCapabilities, null, CancellationToken.None); // Emulate client behavior of promoting "Data" completion list properties onto completion items. if (clientCapabilities.HasCompletionListDataCapability() && completionList is VSCompletionList vsCompletionList && vsCompletionList.Data != null) { foreach (var completionItem in completionList.Items) { Assert.Null(completionItem.Data); completionItem.Data = vsCompletionList.Data; } } return(completionList); }