Skip to content

Commit 33d6c79

Browse files
committed
Fix command enablement by using specific activation contexts for O#, Roslyn standalone, and Roslyn devkit
1 parent c372c4d commit 33d6c79

File tree

5 files changed

+123
-25
lines changed

5 files changed

+123
-25
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 { expect, test, beforeAll, afterAll, describe } from '@jest/globals';
7+
import * as vscode from 'vscode';
8+
import { activateCSharpExtension } from './integrationHelpers';
9+
import testAssetWorkspace from './testAssets/activeTestAssetWorkspace';
10+
11+
describe(`Command Enablement: ${testAssetWorkspace.description}`, function () {
12+
beforeAll(async function () {
13+
const activation = await activateCSharpExtension();
14+
await testAssetWorkspace.restore();
15+
await testAssetWorkspace.waitForIdle(activation.eventStream);
16+
});
17+
18+
afterAll(async () => {
19+
await testAssetWorkspace.cleanupWorkspace();
20+
});
21+
22+
test('Only expected commands are available', async function () {
23+
const commands = await vscode.commands.getCommands(true);
24+
25+
// Ensure the O# commands are available.
26+
expect(commands).toContain('o.restart');
27+
expect(commands).toContain('o.pickProjectAndStart');
28+
expect(commands).toContain('o.fixAll.solution');
29+
expect(commands).toContain('o.fixAll.project');
30+
expect(commands).toContain('o.fixAll.document');
31+
expect(commands).toContain('o.reanalyze.allProjects');
32+
expect(commands).toContain('o.reanalyze.currentProject');
33+
expect(commands).toContain('dotnet.generateAssets');
34+
expect(commands).toContain('dotnet.restore.project');
35+
expect(commands).toContain('dotnet.restore.all');
36+
expect(commands).toContain('dotnet.test.runTestsInContext');
37+
expect(commands).toContain('dotnet.test.debugTestsInContext');
38+
expect(commands).toContain('csharp.listProcess');
39+
expect(commands).toContain('csharp.listRemoteProcess');
40+
expect(commands).toContain('csharp.listRemoteDockerProcess');
41+
expect(commands).toContain('csharp.attachToProcess');
42+
expect(commands).toContain('csharp.reportIssue');
43+
expect(commands).toContain('csharp.showDecompilationTerms');
44+
45+
// Ensure the non-O# commands are not available.
46+
expect(commands).not.toContain('dotnet.openSolution');
47+
expect(commands).not.toContain('dotnet.restartServer');
48+
});
49+
});

package.json

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,49 +2008,49 @@
20082008
"command": "o.restart",
20092009
"title": "%command.o.restart%",
20102010
"category": "OmniSharp",
2011-
"enablement": "config.dotnet.server.useOmnisharp"
2011+
"enablement": "dotnet.server.activationContext == 'OmniSharp'"
20122012
},
20132013
{
20142014
"command": "o.pickProjectAndStart",
20152015
"title": "%command.o.pickProjectAndStart%",
20162016
"category": "OmniSharp",
2017-
"enablement": "config.dotnet.server.useOmnisharp"
2017+
"enablement": "dotnet.server.activationContext == 'OmniSharp'"
20182018
},
20192019
{
20202020
"command": "dotnet.openSolution",
20212021
"title": "%command.dotnet.openSolution%",
20222022
"category": ".NET",
2023-
"enablement": "!config.dotnet.server.useOmnisharp && dotnet.server.activatedStandalone"
2023+
"enablement": "dotnet.server.activationContext == 'Roslyn'"
20242024
},
20252025
{
20262026
"command": "o.fixAll.solution",
20272027
"title": "%command.o.fixAll.solution%",
20282028
"category": "OmniSharp",
2029-
"enablement": "config.dotnet.server.useOmnisharp"
2029+
"enablement": "dotnet.server.activationContext == 'OmniSharp'"
20302030
},
20312031
{
20322032
"command": "o.fixAll.project",
20332033
"title": "%command.o.fixAll.project%",
20342034
"category": "OmniSharp",
2035-
"enablement": "config.dotnet.server.useOmnisharp"
2035+
"enablement": "dotnet.server.activationContext == 'OmniSharp'"
20362036
},
20372037
{
20382038
"command": "o.fixAll.document",
20392039
"title": "%command.o.fixAll.document%",
20402040
"category": "OmniSharp",
2041-
"enablement": "config.dotnet.server.useOmnisharp"
2041+
"enablement": "dotnet.server.activationContext == 'OmniSharp'"
20422042
},
20432043
{
20442044
"command": "o.reanalyze.allProjects",
20452045
"title": "%command.o.reanalyze.allProjects%",
20462046
"category": "OmniSharp",
2047-
"enablement": "config.dotnet.server.useOmnisharp"
2047+
"enablement": "dotnet.server.activationContext == 'OmniSharp'"
20482048
},
20492049
{
20502050
"command": "o.reanalyze.currentProject",
20512051
"title": "%command.o.reanalyze.currentProject%",
20522052
"category": "OmniSharp",
2053-
"enablement": "config.dotnet.server.useOmnisharp"
2053+
"enablement": "dotnet.server.activationContext == 'OmniSharp'"
20542054
},
20552055
{
20562056
"command": "dotnet.generateAssets",
@@ -2061,18 +2061,13 @@
20612061
"command": "dotnet.restore.project",
20622062
"title": "%command.dotnet.restore.project%",
20632063
"category": ".NET",
2064-
"enablement": "dotnet.server.activatedStandalone"
2064+
"enablement": "dotnet.server.activationContext == 'Roslyn' || dotnet.server.activationContext == 'OmniSharp'"
20652065
},
20662066
{
20672067
"command": "dotnet.restore.all",
20682068
"title": "%command.dotnet.restore.all%",
20692069
"category": ".NET",
2070-
"enablement": "dotnet.server.activatedStandalone"
2071-
},
2072-
{
2073-
"command": "csharp.downloadDebugger",
2074-
"title": "%command.csharp.downloadDebugger%",
2075-
"category": "Debug"
2070+
"enablement": "dotnet.server.activationContext == 'Roslyn' || dotnet.server.activationContext == 'OmniSharp'"
20762071
},
20772072
{
20782073
"command": "csharp.listProcess",
@@ -2103,7 +2098,7 @@
21032098
"command": "csharp.showDecompilationTerms",
21042099
"title": "%command.csharp.showDecompilationTerms%",
21052100
"category": "CSharp",
2106-
"enablement": "config.dotnet.server.useOmnisharp"
2101+
"enablement": "dotnet.server.activationContext == 'OmniSharp'"
21072102
},
21082103
{
21092104
"command": "extension.showRazorCSharpWindow",
@@ -2124,19 +2119,19 @@
21242119
"command": "dotnet.test.runTestsInContext",
21252120
"title": "%command.dotnet.test.runTestsInContext%",
21262121
"category": ".NET",
2127-
"enablement": "dotnet.server.activatedStandalone"
2122+
"enablement": "dotnet.server.activationContext == 'Roslyn' || dotnet.server.activationContext == 'OmniSharp'"
21282123
},
21292124
{
21302125
"command": "dotnet.test.debugTestsInContext",
21312126
"title": "%command.dotnet.test.debugTestsInContext%",
21322127
"category": ".NET",
2133-
"enablement": "dotnet.server.activatedStandalone"
2128+
"enablement": "dotnet.server.activationContext == 'Roslyn' || dotnet.server.activationContext == 'OmniSharp'"
21342129
},
21352130
{
21362131
"command": "dotnet.restartServer",
21372132
"title": "%command.dotnet.restartServer%",
21382133
"category": ".NET",
2139-
"enablement": "!config.dotnet.server.useOmnisharp"
2134+
"enablement": "dotnet.server.activationContext != 'OmniSharp'"
21402135
}
21412136
],
21422137
"keybindings": [
@@ -5638,15 +5633,15 @@
56385633
"commandPalette": [
56395634
{
56405635
"command": "dotnet.test.runTestsInContext",
5641-
"when": "editorLangId == csharp && dotnet.server.activatedStandalone"
5636+
"when": "editorLangId == csharp && dotnet.server.activationContext == 'Roslyn' || dotnet.server.activationContext == 'OmniSharp'"
56425637
},
56435638
{
56445639
"command": "dotnet.test.debugTestsInContext",
5645-
"when": "editorLangId == csharp && dotnet.server.activatedStandalone"
5640+
"when": "editorLangId == csharp && dotnet.server.activationContext == 'Roslyn' || dotnet.server.activationContext == 'OmniSharp'"
56465641
},
56475642
{
56485643
"command": "o.restart",
5649-
"when": "config.dotnet.server.useOmnisharp"
5644+
"when": "dotnet.server.activationContext == 'OmniSharp'"
56505645
},
56515646
{
56525647
"command": "csharp.listProcess",
@@ -5678,12 +5673,12 @@
56785673
"editor/context": [
56795674
{
56805675
"command": "dotnet.test.runTestsInContext",
5681-
"when": "editorLangId == csharp && dotnet.server.activatedStandalone",
5676+
"when": "editorLangId == csharp && dotnet.server.activationContext == 'Roslyn' || dotnet.server.activationContext == 'OmniSharp'",
56825677
"group": "2_dotnet@1"
56835678
},
56845679
{
56855680
"command": "dotnet.test.debugTestsInContext",
5686-
"when": "editorLangId == csharp && dotnet.server.activatedStandalone",
5681+
"when": "editorLangId == csharp && dotnet.server.activationContext == 'Roslyn' || dotnet.server.activationContext == 'OmniSharp'",
56875682
"group": "2_dotnet@2"
56885683
}
56895684
]

src/lsptoolshost/roslynLanguageServer.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,14 +518,19 @@ export class RoslynLanguageServer {
518518
_channel.appendLine('Activating C# + C# Dev Kit...');
519519
}
520520

521+
// Set command enablement to use DevKit commands.
522+
vscode.commands.executeCommand('setContext', 'dotnet.server.activationContext', 'RoslynDevKit');
523+
521524
const csharpDevKitArgs = this.getCSharpDevKitExportArgs();
522525
args = args.concat(csharpDevKitArgs);
523526

524527
await this.setupDevKitEnvironment(env, csharpDevkitExtension);
525528
} else {
526529
// C# Dev Kit is not installed - continue C#-only activation.
527530
_channel.appendLine('Activating C# standalone...');
528-
vscode.commands.executeCommand('setContext', 'dotnet.server.activatedStandalone', true);
531+
532+
// Set command enablement to use roslyn standalone commands.
533+
vscode.commands.executeCommand('setContext', 'dotnet.server.activationContext', 'Roslyn');
529534
_wasActivatedWithCSharpDevkit = false;
530535
}
531536

src/main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ export async function activate(
184184
roslynLanguageServerEvents
185185
);
186186
} else {
187+
// Set command enablement to use O# commands.
188+
vscode.commands.executeCommand('setContext', 'dotnet.server.activationContext', 'OmniSharp');
189+
187190
const dotnetChannelObserver = new DotNetChannelObserver(dotnetChannel);
188191
const dotnetLoggerObserver = new DotnetLoggerObserver(dotnetChannel);
189192
eventStream.subscribe(dotnetChannelObserver.post);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 { expect, test, beforeAll, afterAll, describe } from '@jest/globals';
7+
import * as vscode from 'vscode';
8+
import { activateCSharpExtension } from './integrationHelpers';
9+
import testAssetWorkspace from './testAssets/testAssetWorkspace';
10+
11+
describe(`Command Enablement: ${testAssetWorkspace.description}`, function () {
12+
beforeAll(async function () {
13+
await activateCSharpExtension();
14+
});
15+
16+
afterAll(async () => {
17+
await testAssetWorkspace.cleanupWorkspace();
18+
});
19+
20+
test('Only expected commands are available', async function () {
21+
const commands = await vscode.commands.getCommands(true);
22+
23+
// Ensure the standalone Roslyn commands are available.
24+
expect(commands).toContain('dotnet.openSolution');
25+
expect(commands).toContain('dotnet.restartServer');
26+
expect(commands).toContain('dotnet.generateAssets');
27+
expect(commands).toContain('dotnet.restore.project');
28+
expect(commands).toContain('dotnet.restore.all');
29+
expect(commands).toContain('dotnet.test.runTestsInContext');
30+
expect(commands).toContain('dotnet.test.debugTestsInContext');
31+
expect(commands).toContain('csharp.listProcess');
32+
expect(commands).toContain('csharp.listRemoteProcess');
33+
expect(commands).toContain('csharp.listRemoteDockerProcess');
34+
expect(commands).toContain('csharp.attachToProcess');
35+
expect(commands).toContain('csharp.reportIssue');
36+
37+
// Ensure the O#-only commands are not available.
38+
expect(commands).not.toContain('o.restart');
39+
expect(commands).not.toContain('o.pickProjectAndStart');
40+
expect(commands).not.toContain('o.fixAll.solution');
41+
expect(commands).not.toContain('o.fixAll.project');
42+
expect(commands).not.toContain('o.fixAll.document');
43+
expect(commands).not.toContain('o.reanalyze.allProjects');
44+
expect(commands).not.toContain('o.reanalyze.currentProject');
45+
});
46+
});

0 commit comments

Comments
 (0)