|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import * as vscode from 'vscode'; |
| 7 | +import * as path from 'path'; |
| 8 | +import testAssetWorkspace from './testAssets/testAssetWorkspace'; |
| 9 | +import { activateCSharpExtension, closeAllEditorsAsync, openFileInWorkspaceAsync } from './integrationHelpers'; |
| 10 | +import { describe, beforeAll, beforeEach, afterAll, test, expect, afterEach } from '@jest/globals'; |
| 11 | + |
| 12 | +describe(`[${testAssetWorkspace.description}] Signature Help Tests`, () => { |
| 13 | + beforeAll(async () => { |
| 14 | + await activateCSharpExtension(); |
| 15 | + }); |
| 16 | + |
| 17 | + beforeEach(async () => { |
| 18 | + await openFileInWorkspaceAsync(path.join('src', 'app', 'sigHelp.cs')); |
| 19 | + }); |
| 20 | + |
| 21 | + afterAll(async () => { |
| 22 | + await testAssetWorkspace.cleanupWorkspace(); |
| 23 | + }); |
| 24 | + |
| 25 | + afterEach(async () => { |
| 26 | + await closeAllEditorsAsync(); |
| 27 | + }); |
| 28 | + |
| 29 | + test('Includes label when no documentation', async function () { |
| 30 | + const signatureHelp = await getSignatureHelp(new vscode.Position(19, 24)); |
| 31 | + expect(signatureHelp.signatures[0].label).toEqual(`void sigHelp.noDocMethod()`); |
| 32 | + expect(signatureHelp.signatures[0].documentation).toBe(undefined); |
| 33 | + }); |
| 34 | + |
| 35 | + test('Includes method and parameter documentation', async function () { |
| 36 | + const signatureHelp = await getSignatureHelp(new vscode.Position(18, 19)); |
| 37 | + expect(signatureHelp.signatures[0].label).toEqual( |
| 38 | + `void sigHelp.DoWork(int Int1, float Float1, double Double1)` |
| 39 | + ); |
| 40 | + expect(signatureHelp.signatures[0].documentation).toEqual(`DoWork is some method.`); |
| 41 | + |
| 42 | + expect(signatureHelp.signatures[0].parameters[0].label).toEqual(`Int1`); |
| 43 | + expect(signatureHelp.signatures[0].parameters[1].label).toEqual(`Float1`); |
| 44 | + |
| 45 | + expect(<string>signatureHelp.signatures[0].parameters[0].documentation).toEqual(`Used to indicate status.`); |
| 46 | + expect(<string>signatureHelp.signatures[0].parameters[1].documentation).toEqual(`Used to specify context.`); |
| 47 | + }); |
| 48 | + |
| 49 | + test('Identifies active parameter if there is no comma', async function () { |
| 50 | + const signatureHelp = await getSignatureHelp(new vscode.Position(18, 19)); |
| 51 | + expect(signatureHelp.signatures[0].parameters[signatureHelp.activeParameter].label).toEqual(`Int1`); |
| 52 | + }); |
| 53 | + |
| 54 | + test('Identifies active parameter based on comma', async function () { |
| 55 | + const signatureHelp = await getSignatureHelp(new vscode.Position(18, 21)); |
| 56 | + expect(signatureHelp.signatures[0].parameters[signatureHelp.activeParameter].label).toEqual(`Float1`); |
| 57 | + }); |
| 58 | + |
| 59 | + test('Identifies active parameter based on comma for multiple commas', async function () { |
| 60 | + const signatureHelp = await getSignatureHelp(new vscode.Position(18, 28)); |
| 61 | + expect(signatureHelp.signatures[0].parameters[signatureHelp.activeParameter].label).toEqual(`Double1`); |
| 62 | + }); |
| 63 | + |
| 64 | + test('Uses inner documentation from inside nested method call', async function () { |
| 65 | + const signatureHelp = await getSignatureHelp(new vscode.Position(20, 24)); |
| 66 | + expect(signatureHelp.signatures[0].label).toEqual(`string sigHelp.Inner()`); |
| 67 | + expect(signatureHelp.signatures[0].documentation).toEqual(`Inner`); |
| 68 | + }); |
| 69 | + |
| 70 | + test('Uses outer documentation from outside nested method call', async function () { |
| 71 | + const signatureHelp = await getSignatureHelp(new vscode.Position(20, 18)); |
| 72 | + expect(signatureHelp.signatures[0].label).toEqual(`string sigHelp.Outer(string s)`); |
| 73 | + expect(signatureHelp.signatures[0].documentation).toEqual(`Outer`); |
| 74 | + }); |
| 75 | +}); |
| 76 | + |
| 77 | +async function getSignatureHelp(position: vscode.Position): Promise<vscode.SignatureHelp> { |
| 78 | + return <vscode.SignatureHelp>( |
| 79 | + await vscode.commands.executeCommand( |
| 80 | + 'vscode.executeSignatureHelpProvider', |
| 81 | + vscode.window.activeTextEditor!.document.uri, |
| 82 | + position |
| 83 | + ) |
| 84 | + ); |
| 85 | +} |
0 commit comments