Skip to content

Commit 746dd5a

Browse files
authored
Add FAR across razor and cs files (#8250)
2 parents 2498b23 + 94812e7 commit 746dd5a

11 files changed

+227
-121
lines changed

tasks/testTasks.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ function createIntegrationTestSubTasks() {
7676

7777
for (const projectName of razorIntegrationTestProjects) {
7878
gulp.task(`test:integration:razor:${projectName}`, async () =>
79-
runIntegrationTest(
79+
// Run DevKit tests because razor doesn't gracefully handle roslyn restarting
80+
// in tests. DevKit prevents that behavior by handling project restore without
81+
// requiring it.
82+
runDevKitIntegrationTests(
8083
projectName,
8184
path.join('razor', 'razorIntegrationTests'),
8285
`Razor Test Integration ${projectName}`

test/lsptoolshost/integrationTests/integrationHelpers.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,19 @@ export function usingDevKit(): boolean {
6060
}
6161

6262
export async function openFileInWorkspaceAsync(relativeFilePath: string): Promise<vscode.Uri> {
63+
const uri = getFilePath(relativeFilePath);
64+
await vscode.commands.executeCommand('vscode.open', uri);
65+
return uri;
66+
}
67+
68+
export function getFilePath(relativeFilePath: string): vscode.Uri {
6369
const root = vscode.workspace.workspaceFolders![0].uri.fsPath;
6470
const filePath = path.join(root, relativeFilePath);
6571
if (!existsSync(filePath)) {
6672
throw new Error(`File ${filePath} does not exist`);
6773
}
6874

69-
const uri = vscode.Uri.file(filePath);
70-
await vscode.commands.executeCommand('vscode.open', uri);
71-
return uri;
75+
return vscode.Uri.file(filePath);
7276
}
7377

7478
export async function closeAllEditorsAsync(): Promise<void> {
@@ -255,6 +259,16 @@ export async function expectText(document: vscode.TextDocument, expectedLines: s
255259
expect(document.getText()).toBe(expectedText);
256260
}
257261

262+
export function expectPath(expected: vscode.Uri, actual: vscode.Uri) {
263+
if (isLinux()) {
264+
expect(actual.path).toBe(expected.path);
265+
} else {
266+
const actualPath = actual.path.toLowerCase();
267+
const expectedPath = expected.path.toLocaleLowerCase();
268+
expect(actualPath).toBe(expectedPath);
269+
}
270+
}
271+
258272
export const describeIfCSharp = describeIf(!usingDevKit());
259273
export const describeIfDevKit = describeIf(usingDevKit());
260274
export const describeIfNotMacOS = describeIf(!isMacOS());
@@ -281,3 +295,7 @@ function isWindows() {
281295
const currentPlatform = platform();
282296
return currentPlatform === 'win32';
283297
}
298+
299+
function isLinux() {
300+
return !(isMacOS() || isWindows());
301+
}

test/razor/razorIntegrationTests/definition.integration.test.ts

-114
This file was deleted.

test/razor/razorIntegrationTests/formatting.integration.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { beforeAll, afterAll, test, expect, beforeEach } from '@jest/globals';
99
import testAssetWorkspace from './testAssets/testAssetWorkspace';
1010
import * as integrationHelpers from '../../lsptoolshost/integrationTests/integrationHelpers';
1111

12-
integrationHelpers.describeIfWindows(`Razor Formatting ${testAssetWorkspace.description}`, function () {
12+
integrationHelpers.describeIfDevKit(`Razor Formatting ${testAssetWorkspace.description}`, function () {
1313
beforeAll(async function () {
1414
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) {
1515
return;

test/razor/razorIntegrationTests/hover.integration.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { beforeAll, afterAll, test, expect, beforeEach } from '@jest/globals';
99
import testAssetWorkspace from './testAssets/testAssetWorkspace';
1010
import * as integrationHelpers from '../../lsptoolshost/integrationTests/integrationHelpers';
1111

12-
integrationHelpers.describeIfWindows(`Razor Hover ${testAssetWorkspace.description}`, function () {
12+
integrationHelpers.describeIfDevKit(`Razor Hover ${testAssetWorkspace.description}`, function () {
1313
beforeAll(async function () {
1414
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) {
1515
return;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
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+
});

test/razor/razorIntegrationTests/rename.integration.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { beforeAll, afterAll, test, expect, beforeEach } from '@jest/globals';
99
import testAssetWorkspace from './testAssets/testAssetWorkspace';
1010
import * as integrationHelpers from '../../lsptoolshost/integrationTests/integrationHelpers';
1111

12-
integrationHelpers.describeIfWindows(`Razor Rename ${testAssetWorkspace.description}`, function () {
12+
integrationHelpers.describeIfDevKit(`Razor Rename ${testAssetWorkspace.description}`, function () {
1313
beforeAll(async function () {
1414
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) {
1515
return;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"folders": [
3+
{
4+
"path": ".."
5+
}
6+
],
7+
"settings": {
8+
"dotnet.defaultSolution": "RazorApp.sln",
9+
"dotnet.server.useOmnisharp": false,
10+
"omnisharp.enableLspDriver": false,
11+
"razor.server.trace": "Trace",
12+
"dotnet.preferCSharpExtension": false
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@page "/references"
2+
3+
<PageTitle>Counter</PageTitle>
4+
5+
<h1>Counter</h1>
6+
7+
<p role="status">Current count: @currentCount</p>
8+
9+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
10+
11+

0 commit comments

Comments
 (0)