|
| 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 { |
| 10 | + activateCSharpExtension, |
| 11 | + closeAllEditorsAsync, |
| 12 | + openFileInWorkspaceAsync, |
| 13 | + sortLocations, |
| 14 | +} from './integrationHelpers'; |
| 15 | +import { describe, beforeAll, beforeEach, afterAll, test, expect, afterEach } from '@jest/globals'; |
| 16 | + |
| 17 | +describe(`[${testAssetWorkspace.description}] Test Find References`, () => { |
| 18 | + beforeAll(async () => { |
| 19 | + await activateCSharpExtension(); |
| 20 | + }); |
| 21 | + |
| 22 | + beforeEach(async () => { |
| 23 | + await openFileInWorkspaceAsync(path.join('src', 'app', 'reference.cs')); |
| 24 | + }); |
| 25 | + |
| 26 | + afterAll(async () => { |
| 27 | + await testAssetWorkspace.cleanupWorkspace(); |
| 28 | + }); |
| 29 | + |
| 30 | + afterEach(async () => { |
| 31 | + await closeAllEditorsAsync(); |
| 32 | + }); |
| 33 | + |
| 34 | + test('Finds references in same file', async () => { |
| 35 | + const requestPosition = new vscode.Position(13, 23); |
| 36 | + const referenceList = await getReferences(requestPosition); |
| 37 | + |
| 38 | + expect(referenceList.length).toEqual(2); |
| 39 | + expect(referenceList[0].uri.path).toContain('reference.cs'); |
| 40 | + expect(referenceList[0].range).toStrictEqual(new vscode.Range(6, 20, 6, 23)); |
| 41 | + |
| 42 | + expect(referenceList[1].uri.path).toContain('reference.cs'); |
| 43 | + expect(referenceList[1].range).toStrictEqual(new vscode.Range(13, 22, 13, 25)); |
| 44 | + }); |
| 45 | + |
| 46 | + test('Finds references in other files', async () => { |
| 47 | + const requestPosition = new vscode.Position(14, 17); |
| 48 | + const referenceList = await getReferences(requestPosition); |
| 49 | + |
| 50 | + expect(referenceList.length).toEqual(2); |
| 51 | + expect(referenceList[0].uri.path).toContain('definition.cs'); |
| 52 | + expect(referenceList[0].range).toStrictEqual(new vscode.Range(4, 25, 4, 35)); |
| 53 | + |
| 54 | + expect(referenceList[1].uri.path).toContain('reference.cs'); |
| 55 | + expect(referenceList[1].range).toStrictEqual(new vscode.Range(14, 17, 14, 27)); |
| 56 | + }); |
| 57 | +}); |
| 58 | + |
| 59 | +async function getReferences(position: vscode.Position): Promise<vscode.Location[]> { |
| 60 | + const referenceList = <vscode.Location[]>( |
| 61 | + await vscode.commands.executeCommand( |
| 62 | + 'vscode.executeReferenceProvider', |
| 63 | + vscode.window.activeTextEditor!.document.uri, |
| 64 | + position |
| 65 | + ) |
| 66 | + ); |
| 67 | + |
| 68 | + return sortLocations(referenceList); |
| 69 | +} |
0 commit comments