|
| 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 path from 'path'; |
| 7 | +import * as vscode from 'vscode'; |
| 8 | +import { beforeAll, afterAll, test, expect, beforeEach } from '@jest/globals'; |
| 9 | +import testAssetWorkspace from './testAssets/testAssetWorkspace'; |
| 10 | +import * as integrationHelpers from '../../lsptoolshost/integrationTests/integrationHelpers'; |
| 11 | + |
| 12 | +integrationHelpers.describeIfDevKit(`Razor References ${testAssetWorkspace.description}`, function () { |
| 13 | + beforeAll(async function () { |
| 14 | + if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) { |
| 15 | + return; |
| 16 | + } |
| 17 | + |
| 18 | + await integrationHelpers.activateCSharpExtension(); |
| 19 | + }); |
| 20 | + |
| 21 | + beforeEach(async function () { |
| 22 | + await integrationHelpers.openFileInWorkspaceAsync(path.join('Pages', 'Definition.razor')); |
| 23 | + }); |
| 24 | + |
| 25 | + afterAll(async () => { |
| 26 | + await testAssetWorkspace.cleanupWorkspace(); |
| 27 | + }); |
| 28 | + |
| 29 | + test('Go To Definition', async () => { |
| 30 | + if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) { |
| 31 | + return; |
| 32 | + } |
| 33 | + |
| 34 | + const position = new vscode.Position(6, 41); |
| 35 | + |
| 36 | + await integrationHelpers.waitForExpectedResult<vscode.Location[]>( |
| 37 | + async () => |
| 38 | + await vscode.commands.executeCommand( |
| 39 | + 'vscode.executeDefinitionProvider', |
| 40 | + vscode.window.activeTextEditor!.document.uri, |
| 41 | + position |
| 42 | + ), |
| 43 | + 1000, |
| 44 | + 100, |
| 45 | + (locations) => { |
| 46 | + expect(locations.length).toBe(1); |
| 47 | + const definitionLocation = locations[0]; |
| 48 | + |
| 49 | + expect(definitionLocation.uri.path).toBe(vscode.window.activeTextEditor!.document.uri.path); |
| 50 | + expect(definitionLocation.range.start.line).toBe(11); |
| 51 | + expect(definitionLocation.range.start.character).toBe(16); |
| 52 | + expect(definitionLocation.range.end.line).toBe(11); |
| 53 | + expect(definitionLocation.range.end.character).toBe(28); |
| 54 | + } |
| 55 | + ); |
| 56 | + }); |
| 57 | + |
| 58 | + test('Find All References', async () => { |
| 59 | + if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) { |
| 60 | + return; |
| 61 | + } |
| 62 | + |
| 63 | + const position = new vscode.Position(6, 41); |
| 64 | + await integrationHelpers.waitForExpectedResult<vscode.Location[]>( |
| 65 | + async () => |
| 66 | + await vscode.commands.executeCommand( |
| 67 | + 'vscode.executeReferenceProvider', |
| 68 | + vscode.window.activeTextEditor!.document.uri, |
| 69 | + position |
| 70 | + ), |
| 71 | + 1000, |
| 72 | + 100, |
| 73 | + (locations) => { |
| 74 | + expect(locations.length).toBe(3); |
| 75 | + |
| 76 | + let definitionLocation = locations[0]; |
| 77 | + expect(definitionLocation.uri.path).toBe(vscode.window.activeTextEditor!.document.uri.path); |
| 78 | + expect(definitionLocation.range.start.line).toBe(6); |
| 79 | + expect(definitionLocation.range.start.character).toBe(33); |
| 80 | + expect(definitionLocation.range.end.line).toBe(6); |
| 81 | + expect(definitionLocation.range.end.character).toBe(45); |
| 82 | + |
| 83 | + definitionLocation = locations[1]; |
| 84 | + expect(definitionLocation.uri.path).toBe(vscode.window.activeTextEditor!.document.uri.path); |
| 85 | + expect(definitionLocation.range.start.line).toBe(11); |
| 86 | + expect(definitionLocation.range.start.character).toBe(16); |
| 87 | + expect(definitionLocation.range.end.line).toBe(11); |
| 88 | + expect(definitionLocation.range.end.character).toBe(28); |
| 89 | + |
| 90 | + definitionLocation = locations[2]; |
| 91 | + expect(definitionLocation.uri.path).toBe(vscode.window.activeTextEditor!.document.uri.path); |
| 92 | + expect(definitionLocation.range.start.line).toBe(15); |
| 93 | + expect(definitionLocation.range.start.character).toBe(8); |
| 94 | + expect(definitionLocation.range.end.line).toBe(15); |
| 95 | + expect(definitionLocation.range.end.character).toBe(20); |
| 96 | + } |
| 97 | + ); |
| 98 | + }); |
| 99 | + |
| 100 | + test('Go To Implementation', async () => { |
| 101 | + if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) { |
| 102 | + return; |
| 103 | + } |
| 104 | + |
| 105 | + const position = new vscode.Position(18, 18); |
| 106 | + |
| 107 | + await integrationHelpers.waitForExpectedResult<vscode.Location[]>( |
| 108 | + async () => |
| 109 | + await vscode.commands.executeCommand( |
| 110 | + 'vscode.executeImplementationProvider', |
| 111 | + vscode.window.activeTextEditor!.document.uri, |
| 112 | + position |
| 113 | + ), |
| 114 | + 1000, |
| 115 | + 100, |
| 116 | + (locations) => { |
| 117 | + expect(locations.length).toBe(1); |
| 118 | + const definitionLocation = locations[0]; |
| 119 | + |
| 120 | + expect(definitionLocation.uri.path).toBe(vscode.window.activeTextEditor!.document.uri.path); |
| 121 | + expect(definitionLocation.range.start.line).toBe(23); |
| 122 | + expect(definitionLocation.range.start.character).toBe(10); |
| 123 | + expect(definitionLocation.range.end.line).toBe(23); |
| 124 | + expect(definitionLocation.range.end.character).toBe(19); |
| 125 | + } |
| 126 | + ); |
| 127 | + }); |
| 128 | + |
| 129 | + test('Find All References - CSharp', async () => { |
| 130 | + if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) { |
| 131 | + return; |
| 132 | + } |
| 133 | + const position = new vscode.Position(5, 28); |
| 134 | + await integrationHelpers.openFileInWorkspaceAsync(path.join('Pages', 'References.razor.cs')); |
| 135 | + |
| 136 | + await integrationHelpers.waitForExpectedResult<vscode.Location[]>( |
| 137 | + async () => { |
| 138 | + return await vscode.commands.executeCommand( |
| 139 | + 'vscode.executeReferenceProvider', |
| 140 | + vscode.window.activeTextEditor!.document.uri, |
| 141 | + position |
| 142 | + ); |
| 143 | + }, |
| 144 | + 1000, |
| 145 | + 100, |
| 146 | + (locations) => { |
| 147 | + expect(locations.length).toBe(3); |
| 148 | + |
| 149 | + const sortedLocations = integrationHelpers.sortLocations(locations); |
| 150 | + |
| 151 | + const razorFile = integrationHelpers.getFilePath(path.join('Pages', 'References.razor')); |
| 152 | + const csharpFile = integrationHelpers.getFilePath(path.join('Pages', 'References.razor.cs')); |
| 153 | + |
| 154 | + integrationHelpers.expectPath(razorFile, sortedLocations[0].uri); |
| 155 | + integrationHelpers.expectPath(csharpFile, sortedLocations[1].uri); |
| 156 | + integrationHelpers.expectPath(csharpFile, sortedLocations[2].uri); |
| 157 | + } |
| 158 | + ); |
| 159 | + }); |
| 160 | +}); |
0 commit comments