Skip to content

Commit 316abdf

Browse files
authored
Support activating the extension with limited support in untrusted workspaces (#8435)
2 parents c3fda44 + 9cbe2de commit 316abdf

File tree

16 files changed

+221
-64
lines changed

16 files changed

+221
-64
lines changed

.vscode/launch.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,38 @@
1111
"outFiles": ["${workspaceRoot}/dist/*.js"],
1212
"preLaunchTask": "packageDev"
1313
},
14+
{
15+
"name": "[Untrusted] Run Integration Test",
16+
"type": "extensionHost",
17+
"request": "launch",
18+
"runtimeExecutable": "${execPath}",
19+
"args": [
20+
// Launch VSCode using a specific profile to ensure that user settings are not used.
21+
// This profile must be imported into vscode before running this launch configuration.
22+
// The profile can be found under /test/csharp-test-profile.
23+
"--profile",
24+
"csharp-test-profile",
25+
"${workspaceRoot}/test/untrustedWorkspace/integrationTests/testAssets/empty/.vscode/empty.code-workspace",
26+
"--extensionDevelopmentPath=${workspaceRoot}",
27+
"--extensionTestsPath=${workspaceRoot}/out/test/untrustedWorkspace/integrationTests",
28+
"--log",
29+
"ms-dotnettools.csharp:trace"
30+
],
31+
"env": {
32+
"CODE_EXTENSIONS_PATH": "${workspaceRoot}",
33+
},
34+
"sourceMaps": true,
35+
"outFiles": [
36+
"${workspaceRoot}/dist/*.js",
37+
"${workspaceRoot}/out/test/**/*.js"
38+
],
39+
"resolveSourceMapLocations": [
40+
"${workspaceFolder}/**",
41+
"!**/node_modules/**"
42+
],
43+
"preLaunchTask": "packageDev",
44+
"internalConsoleOptions": "openOnSessionStart"
45+
},
1446
{
1547
"name": "[Roslyn] Run Current File Integration Tests",
1648
"type": "extensionHost",

azure-pipelines/test-matrix.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ jobs:
3131
RazorCohostTests:
3232
npmCommand: test:integration:razor:cohost
3333
isIntegration: true
34+
UntrustedWorkspaceTest:
35+
npmCommand: test:integration:untrusted
36+
isIntegration: true
3437
pool: ${{ parameters.pool }}
3538
${{ if parameters.containerName }}:
3639
container: ${{ parameters.containerName }}
@@ -41,4 +44,4 @@ jobs:
4144
installAdditionalLinuxDependencies: ${{ parameters.installAdditionalLinuxDependencies }}
4245
npmCommand: $(npmCommand)
4346
testVSCodeVersion: ${{ parameters.testVSCodeVersion }}
44-
isIntegration: $(isIntegration)
47+
isIntegration: $(isIntegration)

jest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const config: Config = {
1313
'<rootDir>/test/omnisharp/omnisharpUnitTests/jest.config.ts',
1414
'<rootDir>/test/razor/razorIntegrationTests/jest.config.ts',
1515
'<rootDir>/test/razor/razorTests/jest.config.ts',
16+
'<rootDir>/test/untrustedWorkspace/integrationTests/jest.config.ts',
1617
],
1718
// Reporters are a global jest configuration property and cannot be set in the project jest config.
1819
// This configuration will create a 'junit.xml' file in the output directory, no matter which test project is running.

l10n/bundle.l10n.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
2+
"Reload C# Extension": "Reload C# Extension",
3+
"Workspace trust has changed. Would you like to reload the C# extension?": "Workspace trust has changed. Would you like to reload the C# extension?",
24
"How to setup Remote Debugging": "How to setup Remote Debugging",
35
"The C# extension for Visual Studio Code is incompatible on {0} {1} with the VS Code Remote Extensions. To see avaliable workarounds, click on '{2}'.": "The C# extension for Visual Studio Code is incompatible on {0} {1} with the VS Code Remote Extensions. To see avaliable workarounds, click on '{2}'.",
46
"The C# extension for Visual Studio Code is incompatible on {0} {1}.": "The C# extension for Visual Studio Code is incompatible on {0} {1}.",

package.json

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"capabilities": {
3434
"virtualWorkspaces": false,
3535
"untrustedWorkspaces": {
36-
"supported": false
36+
"supported": "limited"
3737
}
3838
},
3939
"extensionKind": [
@@ -75,6 +75,7 @@
7575
"test:integration:razor": "npm run package && gulp test:integration:razor",
7676
"test:integration:razor:cohost": "npm run package && gulp test:integration:razor:cohost",
7777
"test:integration:devkit": "npm run package && gulp test:integration:devkit",
78+
"test:integration:untrusted": "npm run package && gulp test:integration:untrusted",
7879
"profiling": "npm run package && gulp profiling",
7980
"test:artifacts": "npm run compileDev && gulp test:artifacts",
8081
"omnisharptest": "npm run package && gulp omnisharptest",
@@ -1814,139 +1815,145 @@
18141815
"command": "o.restart",
18151816
"title": "%command.o.restart%",
18161817
"category": "OmniSharp",
1817-
"enablement": "dotnet.server.activationContext == 'OmniSharp'"
1818+
"enablement": "isWorkspaceTrusted && dotnet.server.activationContext == 'OmniSharp'"
18181819
},
18191820
{
18201821
"command": "o.pickProjectAndStart",
18211822
"title": "%command.o.pickProjectAndStart%",
18221823
"category": "OmniSharp",
1823-
"enablement": "dotnet.server.activationContext == 'OmniSharp'"
1824+
"enablement": "isWorkspaceTrusted && dotnet.server.activationContext == 'OmniSharp'"
18241825
},
18251826
{
18261827
"command": "dotnet.openSolution",
18271828
"title": "%command.dotnet.openSolution%",
18281829
"category": ".NET",
1829-
"enablement": "dotnet.server.activationContext == 'Roslyn'"
1830+
"enablement": "isWorkspaceTrusted && dotnet.server.activationContext == 'Roslyn'"
18301831
},
18311832
{
18321833
"command": "o.fixAll.solution",
18331834
"title": "%command.o.fixAll.solution%",
18341835
"category": "OmniSharp",
1835-
"enablement": "dotnet.server.activationContext == 'OmniSharp'"
1836+
"enablement": "isWorkspaceTrusted && dotnet.server.activationContext == 'OmniSharp'"
18361837
},
18371838
{
18381839
"command": "o.fixAll.project",
18391840
"title": "%command.o.fixAll.project%",
18401841
"category": "OmniSharp",
1841-
"enablement": "dotnet.server.activationContext == 'OmniSharp'"
1842+
"enablement": "isWorkspaceTrusted && dotnet.server.activationContext == 'OmniSharp'"
18421843
},
18431844
{
18441845
"command": "o.fixAll.document",
18451846
"title": "%command.o.fixAll.document%",
18461847
"category": "OmniSharp",
1847-
"enablement": "dotnet.server.activationContext == 'OmniSharp'"
1848+
"enablement": "isWorkspaceTrusted && dotnet.server.activationContext == 'OmniSharp'"
18481849
},
18491850
{
18501851
"command": "o.reanalyze.allProjects",
18511852
"title": "%command.o.reanalyze.allProjects%",
18521853
"category": "OmniSharp",
1853-
"enablement": "dotnet.server.activationContext == 'OmniSharp'"
1854+
"enablement": "isWorkspaceTrusted && dotnet.server.activationContext == 'OmniSharp'"
18541855
},
18551856
{
18561857
"command": "o.reanalyze.currentProject",
18571858
"title": "%command.o.reanalyze.currentProject%",
18581859
"category": "OmniSharp",
1859-
"enablement": "dotnet.server.activationContext == 'OmniSharp'"
1860+
"enablement": "isWorkspaceTrusted && dotnet.server.activationContext == 'OmniSharp'"
18601861
},
18611862
{
18621863
"command": "dotnet.generateAssets",
18631864
"title": "%command.dotnet.generateAssets.currentProject%",
18641865
"category": ".NET",
1865-
"enablement": "dotnet.server.activationContext == 'RoslynDevKit' || dotnet.server.activationContext == 'Roslyn' || dotnet.server.activationContext == 'OmniSharp'"
1866+
"enablement": "isWorkspaceTrusted && (dotnet.server.activationContext == 'RoslynDevKit' || dotnet.server.activationContext == 'Roslyn' || dotnet.server.activationContext == 'OmniSharp')"
18661867
},
18671868
{
18681869
"command": "dotnet.restore.project",
18691870
"title": "%command.dotnet.restore.project%",
18701871
"category": ".NET",
1871-
"enablement": "dotnet.server.activationContext == 'Roslyn' || dotnet.server.activationContext == 'OmniSharp'"
1872+
"enablement": "isWorkspaceTrusted && (dotnet.server.activationContext == 'Roslyn' || dotnet.server.activationContext == 'OmniSharp')"
18721873
},
18731874
{
18741875
"command": "dotnet.restore.all",
18751876
"title": "%command.dotnet.restore.all%",
18761877
"category": ".NET",
1877-
"enablement": "dotnet.server.activationContext == 'Roslyn' || dotnet.server.activationContext == 'OmniSharp'"
1878+
"enablement": "isWorkspaceTrusted && (dotnet.server.activationContext == 'Roslyn' || dotnet.server.activationContext == 'OmniSharp')"
18781879
},
18791880
{
18801881
"command": "csharp.listProcess",
18811882
"title": "%command.csharp.listProcess%",
1882-
"category": "CSharp"
1883+
"category": "CSharp",
1884+
"enablement": "isWorkspaceTrusted"
18831885
},
18841886
{
18851887
"command": "csharp.listRemoteProcess",
18861888
"title": "%command.csharp.listRemoteProcess%",
1887-
"category": "CSharp"
1889+
"category": "CSharp",
1890+
"enablement": "isWorkspaceTrusted"
18881891
},
18891892
{
18901893
"command": "csharp.listRemoteDockerProcess",
18911894
"title": "%command.csharp.listRemoteDockerProcess%",
1892-
"category": "CSharp"
1895+
"category": "CSharp",
1896+
"enablement": "isWorkspaceTrusted"
18931897
},
18941898
{
18951899
"command": "csharp.attachToProcess",
18961900
"title": "%command.csharp.attachToProcess%",
1897-
"category": "Debug"
1901+
"category": "Debug",
1902+
"enablement": "isWorkspaceTrusted"
18981903
},
18991904
{
19001905
"command": "csharp.reportIssue",
19011906
"title": "%command.csharp.reportIssue%",
1902-
"category": "CSharp"
1907+
"category": "CSharp",
1908+
"enablement": "isWorkspaceTrusted"
19031909
},
19041910
{
19051911
"command": "csharp.showDecompilationTerms",
19061912
"title": "%command.csharp.showDecompilationTerms%",
19071913
"category": "CSharp",
1908-
"enablement": "dotnet.server.activationContext == 'OmniSharp'"
1914+
"enablement": "isWorkspaceTrusted && dotnet.server.activationContext == 'OmniSharp'"
19091915
},
19101916
{
19111917
"command": "csharp.recordLanguageServerTrace",
19121918
"title": "%command.csharp.recordLanguageServerTrace%",
19131919
"category": "CSharp",
1914-
"enablement": "dotnet.server.activationContext == 'Roslyn' || dotnet.server.activationContext == 'RoslynDevKit'"
1920+
"enablement": "isWorkspaceTrusted && (dotnet.server.activationContext == 'Roslyn' || dotnet.server.activationContext == 'RoslynDevKit')"
19151921
},
19161922
{
19171923
"command": "extension.showRazorCSharpWindow",
19181924
"title": "%command.extension.showRazorCSharpWindow%",
19191925
"category": "Razor",
1920-
"enablement": "razor.mode == 'lsp'"
1926+
"enablement": "isWorkspaceTrusted && razor.mode == 'lsp'"
19211927
},
19221928
{
19231929
"command": "extension.showRazorHtmlWindow",
19241930
"title": "%command.extension.showRazorHtmlWindow%",
19251931
"category": "Razor",
1926-
"enablement": "razor.mode == 'lsp'"
1932+
"enablement": "isWorkspaceTrusted && razor.mode == 'lsp'"
19271933
},
19281934
{
19291935
"command": "razor.reportIssue",
19301936
"title": "%command.razor.reportIssue%",
1931-
"category": "Razor"
1937+
"category": "Razor",
1938+
"enablement": "isWorkspaceTrusted"
19321939
},
19331940
{
19341941
"command": "dotnet.test.runTestsInContext",
19351942
"title": "%command.dotnet.test.runTestsInContext%",
19361943
"category": ".NET",
1937-
"enablement": "dotnet.server.activationContext == 'Roslyn' || dotnet.server.activationContext == 'OmniSharp'"
1944+
"enablement": "isWorkspaceTrusted && (dotnet.server.activationContext == 'Roslyn' || dotnet.server.activationContext == 'OmniSharp')"
19381945
},
19391946
{
19401947
"command": "dotnet.test.debugTestsInContext",
19411948
"title": "%command.dotnet.test.debugTestsInContext%",
19421949
"category": ".NET",
1943-
"enablement": "dotnet.server.activationContext == 'Roslyn' || dotnet.server.activationContext == 'OmniSharp'"
1950+
"enablement": "isWorkspaceTrusted && (dotnet.server.activationContext == 'Roslyn' || dotnet.server.activationContext == 'OmniSharp')"
19441951
},
19451952
{
19461953
"command": "dotnet.restartServer",
19471954
"title": "%command.dotnet.restartServer%",
19481955
"category": ".NET",
1949-
"enablement": "dotnet.server.activationContext == 'Roslyn'"
1956+
"enablement": "isWorkspaceTrusted && dotnet.server.activationContext == 'Roslyn'"
19501957
}
19511958
],
19521959
"keybindings": [

src/activateOmniSharp.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export function activateOmniSharp(
5858
const coreClrDebugPromise = getCoreClrDebugPromise(omnisharpLangServicePromise);
5959

6060
const exports: OmnisharpExtensionExports = {
61+
isLimitedActivation: false,
6162
initializationFinished: async () => {
6263
const langService = await omnisharpLangServicePromise;
6364
await langService!.server.waitForInitialize();

src/activateRoslyn.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export function activateRoslyn(
8787

8888
const languageServerExport = new RoslynLanguageServerExport(roslynLanguageServerStartedPromise);
8989
const exports: CSharpExtensionExports = {
90+
isLimitedActivation: false,
9091
initializationFinished: async () => {
9192
await coreClrDebugPromise;
9293
await razorLanguageServerStartedPromise;

src/csharpExtensionExports.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ import { GlobalBrokeredServiceContainer } from '@microsoft/servicehub-framework'
1111
import { PartialResultParams, ProtocolRequestType, RequestType } from 'vscode-languageclient/node';
1212
import { LanguageServerEvents } from './lsptoolshost/server/languageServerEvents';
1313

14+
export interface LimitedExtensionExports {
15+
isLimitedActivation: true;
16+
}
17+
1418
export interface OmnisharpExtensionExports {
19+
isLimitedActivation: false;
1520
initializationFinished: () => Promise<void>;
1621
getAdvisor: () => Promise<Advisor>;
1722
getTestManager: () => Promise<TestManager>;
@@ -20,6 +25,7 @@ export interface OmnisharpExtensionExports {
2025
}
2126

2227
export interface CSharpExtensionExports {
28+
isLimitedActivation: false;
2329
initializationFinished: () => Promise<void>;
2430
logDirectory: string;
2531
profferBrokeredServices: (container: GlobalBrokeredServiceContainer) => void;

0 commit comments

Comments
 (0)