예제 #1
0
        internal static async Task <LSP.VSInternalReferenceItem[]> RunFindAllReferencesAsync(TestLspServer testLspServer, LSP.Location caret, IProgress <object> progress = null)
        {
            var vsClientCapabilities = new LSP.VSInternalClientCapabilities
            {
                SupportsVisualStudioExtensions = true
            };

            var results = await testLspServer.ExecuteRequestAsync <LSP.ReferenceParams, LSP.VSInternalReferenceItem[]>(LSP.Methods.TextDocumentReferencesName,
                                                                                                                       CreateReferenceParams(caret, progress), vsClientCapabilities, null, CancellationToken.None);

            return(results?.Cast <LSP.VSInternalReferenceItem>()?.ToArray());
        }
예제 #2
0
        public async Task TestGetCompletionsAsync_PromotesCommitCharactersToListAsync()
        {
            var clientCapabilities = new LSP.VSInternalClientCapabilities
            {
                SupportsVisualStudioExtensions = true,
                TextDocument = new LSP.TextDocumentClientCapabilities()
                {
                    Completion = new LSP.VSInternalCompletionSetting()
                    {
                        CompletionList = new LSP.VSInternalCompletionListSetting()
                        {
                            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.VSInternalCompletionInvokeKind.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.VSInternalCompletionList>(results);

            Assert.Equal(expectedCommitCharacters, vsCompletionList.CommitCharacters.Value.First);
        }
예제 #3
0
        public async Task TestResolveOverridesCompletionItem_SnippetsEnabledAsync()
        {
            var markup =
                @"abstract class A
{
    public abstract void M();
}

class B : A
{
    override {|caret:|}
}";

            // Explicitly enable snippets. This allows us to set the cursor with $0. Currently only applies to C# in Razor docs.
            var clientCapabilities = new LSP.VSInternalClientCapabilities
            {
                SupportsVisualStudioExtensions = true,
                TextDocument = new LSP.TextDocumentClientCapabilities
                {
                    Completion = new CompletionSetting
                    {
                        CompletionItem = new CompletionItemSetting
                        {
                            SnippetSupport = true
                        }
                    }
                }
            };

            using var testLspServer = await CreateTestLspServerAsync(markup, clientCapabilities);

            var clientCompletionItem = await GetCompletionItemToResolveAsync <LSP.VSInternalCompletionItem>(
                testLspServer,
                label : "M()").ConfigureAwait(false);

            var results = (LSP.VSInternalCompletionItem) await RunResolveCompletionItemAsync(
                testLspServer, clientCompletionItem).ConfigureAwait(false);

            Assert.NotNull(results.TextEdit);
            Assert.Null(results.InsertText);
            Assert.Equal(@"public override void M()
    {
        throw new System.NotImplementedException();$0
    }", results.TextEdit.NewText);
        }
예제 #4
0
        public async Task TestResolveCompletionItemFromListAsync()
        {
            var markup =
                @"class A
{
    void M()
    {
        {|caret:|}
    }
}";

            var clientCapabilities = new LSP.VSInternalClientCapabilities
            {
                SupportsVisualStudioExtensions = true,
                TextDocument = new TextDocumentClientCapabilities()
                {
                    Completion = new VSInternalCompletionSetting()
                    {
                        CompletionList = new VSInternalCompletionListSetting()
                        {
                            Data = true,
                        }
                    }
                }
            };

            using var testLspServer = await CreateTestLspServerAsync(markup, clientCapabilities);

            var clientCompletionItem = await GetCompletionItemToResolveAsync <LSP.VSInternalCompletionItem>(
                testLspServer,
                label : "A").ConfigureAwait(false);

            var description = new ClassifiedTextElement(CreateClassifiedTextRunForClass("A"));
            var expected    = CreateResolvedCompletionItem(clientCompletionItem, description, "class A", null);

            var results = (LSP.VSInternalCompletionItem) await RunResolveCompletionItemAsync(
                testLspServer, clientCompletionItem).ConfigureAwait(false);

            AssertJsonEquals(expected, results);
        }