Skip to content

Commit a6e8298

Browse files
committed
Update tests to account for adjusted command enablement
1 parent 05d9416 commit a6e8298

File tree

4 files changed

+83
-34
lines changed

4 files changed

+83
-34
lines changed

src/lsptoolshost/commands.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { createLaunchTargetForSolution } from '../shared/launchTarget';
1111
import reportIssue from '../shared/reportIssue';
1212
import { getDotnetInfo } from '../shared/utils/getDotnetInfo';
1313
import { IHostExecutableResolver } from '../shared/constants/IHostExecutableResolver';
14+
import { getCSharpDevKit } from '../utils/getCSharpDevKit';
1415

1516
export function registerCommands(
1617
context: vscode.ExtensionContext,
@@ -38,9 +39,11 @@ export function registerCommands(
3839
context.subscriptions.push(
3940
vscode.commands.registerCommand('dotnet.restartServer', async () => restartServer(languageServer))
4041
);
41-
context.subscriptions.push(
42-
vscode.commands.registerCommand('dotnet.openSolution', async () => openSolution(languageServer))
43-
);
42+
if (!getCSharpDevKit()) {
43+
context.subscriptions.push(
44+
vscode.commands.registerCommand('dotnet.openSolution', async () => openSolution(languageServer))
45+
);
46+
}
4447
context.subscriptions.push(
4548
vscode.commands.registerCommand('csharp.reportIssue', async () =>
4649
reportIssue(

test/lsptoolshost/integrationTests/commandEnablement.integration.test.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { expect, test, beforeAll, afterAll, describe } from '@jest/globals';
6+
import { expect, beforeAll, afterAll, describe } from '@jest/globals';
77
import * as vscode from 'vscode';
8-
import { activateCSharpExtension } from './integrationHelpers';
8+
import { activateCSharpExtension, testIfCSharp, testIfDevKit } from './integrationHelpers';
99
import testAssetWorkspace from './testAssets/testAssetWorkspace';
10-
import { CommonCommands, OmniSharpCommands, RoslynCommands } from './expectedCommands';
10+
import {
11+
RoslynDevKitCommands,
12+
RoslynStandaloneCommands,
13+
UnexpectedRoslynDevKitCommands,
14+
UnexpectedRoslynStandaloneCommands,
15+
} from './expectedCommands';
1116

1217
describe(`Command Enablement Tests`, () => {
1318
beforeAll(async () => {
@@ -18,19 +23,30 @@ describe(`Command Enablement Tests`, () => {
1823
await testAssetWorkspace.cleanupWorkspace();
1924
});
2025

21-
test('Roslyn commands are available', async () => {
26+
testIfCSharp('Roslyn standalone commands are available', async () => {
2227
const commands = await vscode.commands.getCommands(true);
2328

2429
// Ensure the standalone Roslyn commands are available.
25-
RoslynCommands.forEach((command) => {
30+
RoslynStandaloneCommands.forEach((command) => {
2631
expect(commands).toContain(command);
2732
});
28-
CommonCommands.forEach((command) => {
33+
34+
// Ensure other commands are not available.
35+
UnexpectedRoslynStandaloneCommands.forEach((command) => {
36+
expect(commands).not.toContain(command);
37+
});
38+
});
39+
40+
testIfDevKit('Roslyn + C# Dev Kit commands are available', async () => {
41+
const commands = await vscode.commands.getCommands(true);
42+
43+
// Ensure the Roslyn + C# Dev Kit commands are available
44+
RoslynDevKitCommands.forEach((command) => {
2945
expect(commands).toContain(command);
3046
});
3147

32-
// Ensure O# commands are not available.
33-
OmniSharpCommands.forEach((command) => {
48+
// Ensure other commands are not available.
49+
UnexpectedRoslynDevKitCommands.forEach((command) => {
3450
expect(commands).not.toContain(command);
3551
});
3652
});

test/lsptoolshost/integrationTests/expectedCommands.ts

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,26 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
export const OmniSharpCommands = [
6+
// Commands used by all activation contexts of the extension.
7+
const CommonCommands = [
8+
'dotnet.generateAssets',
9+
'csharp.listProcess',
10+
'csharp.listRemoteProcess',
11+
'csharp.listRemoteDockerProcess',
12+
'csharp.attachToProcess',
13+
'csharp.reportIssue',
14+
];
15+
16+
// Commands used by both O# and Roslyn standalone activation contexts.
17+
const CommonStandaloneCommands = [
18+
'dotnet.restore.project',
19+
'dotnet.restore.all',
20+
'dotnet.test.runTestsInContext',
21+
'dotnet.test.debugTestsInContext',
22+
];
23+
24+
// Commands used only in an O# activation context.
25+
const OmniSharpOnlyCommands = [
726
'o.restart',
827
'o.pickProjectAndStart',
928
'o.fixAll.solution',
@@ -13,17 +32,35 @@ export const OmniSharpCommands = [
1332
'o.reanalyze.currentProject',
1433
];
1534

16-
export const RoslynCommands = ['dotnet.openSolution', 'dotnet.restartServer'];
35+
// All commands used in the O# activation context.
36+
export const OmniSharpCommands = [...OmniSharpOnlyCommands, ...CommonCommands, ...CommonStandaloneCommands];
1737

18-
export const CommonCommands = [
19-
'dotnet.generateAssets',
20-
'dotnet.restore.project',
21-
'dotnet.restore.all',
22-
'dotnet.test.runTestsInContext',
23-
'dotnet.test.debugTestsInContext',
24-
'csharp.listProcess',
25-
'csharp.listRemoteProcess',
26-
'csharp.listRemoteDockerProcess',
27-
'csharp.attachToProcess',
28-
'csharp.reportIssue',
38+
// Commands used only in a Roslyn activation context.
39+
const RoslynCommonCommands = ['dotnet.restartServer'];
40+
41+
// Commands used only in a Roslyn standalone activation context.
42+
const RoslynStandaloneOnlyCommands = ['dotnet.openSolution'];
43+
44+
// All commands used in a Roslyn standalone activation context.
45+
export const RoslynStandaloneCommands = [
46+
...CommonCommands,
47+
...CommonStandaloneCommands,
48+
...RoslynCommonCommands,
49+
...RoslynStandaloneOnlyCommands,
50+
];
51+
52+
// All commands used in a Roslyn + C# Dev Kit activation context.
53+
export const RoslynDevKitCommands = [...CommonCommands, ...RoslynCommonCommands];
54+
55+
// All commands that should not be available in an O# activation context.
56+
export const UnexpectedOmniSharpCommands = [...RoslynStandaloneOnlyCommands, ...RoslynCommonCommands];
57+
58+
// All commands that should not be available in a Roslyn standalone activation context.
59+
export const UnexpectedRoslynStandaloneCommands = [...OmniSharpOnlyCommands];
60+
61+
// All commands that should not be available in a Roslyn + C# Dev Kit activation context.
62+
export const UnexpectedRoslynDevKitCommands = [
63+
...CommonStandaloneCommands,
64+
...OmniSharpOnlyCommands,
65+
...RoslynStandaloneOnlyCommands,
2966
];

test/omnisharp/omnisharpIntegrationTests/omnisharpCommands.integration.test.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ import { expect, test, beforeAll, afterAll, describe } from '@jest/globals';
77
import * as vscode from 'vscode';
88
import { activateCSharpExtension } from './integrationHelpers';
99
import testAssetWorkspace from './testAssets/activeTestAssetWorkspace';
10-
import {
11-
CommonCommands,
12-
OmniSharpCommands,
13-
RoslynCommands,
14-
} from '../../lsptoolshost/integrationTests/expectedCommands';
10+
import { OmniSharpCommands, UnexpectedOmniSharpCommands } from '../../lsptoolshost/integrationTests/expectedCommands';
1511

1612
describe(`Command Enablement: ${testAssetWorkspace.description}`, function () {
1713
beforeAll(async function () {
@@ -31,12 +27,9 @@ describe(`Command Enablement: ${testAssetWorkspace.description}`, function () {
3127
OmniSharpCommands.forEach((command) => {
3228
expect(commands).toContain(command);
3329
});
34-
CommonCommands.forEach((command) => {
35-
expect(commands).toContain(command);
36-
});
3730

38-
// Ensure Roslyn standalone commands are not available.
39-
RoslynCommands.forEach((command) => {
31+
// Ensure other commands are not available.
32+
UnexpectedOmniSharpCommands.forEach((command) => {
4033
expect(commands).not.toContain(command);
4134
});
4235
});

0 commit comments

Comments
 (0)