Skip to content

Commit 27cf6a3

Browse files
committed
Implement workspace trust for php-language-features
1 parent 6437567 commit 27cf6a3

File tree

3 files changed

+46
-23
lines changed

3 files changed

+46
-23
lines changed

extensions/php-language-features/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@
99
"engines": {
1010
"vscode": "0.10.x"
1111
},
12+
"enableProposedApi": true,
1213
"activationEvents": [
1314
"onLanguage:php"
1415
],
1516
"main": "./out/phpMain",
1617
"categories": [
1718
"Programming Languages"
1819
],
20+
"workspaceTrust": {
21+
"request": "onDemand",
22+
"description": "The extension requires workspace trust when the `php.validate.executablePath` setting will load a version of PHP in the workspace."
23+
},
1924
"contributes": {
2025
"configuration": {
2126
"title": "%configuration.title%",

extensions/php-language-features/src/features/validationProvider.ts

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ export default class PHPValidationProvider {
140140
vscode.commands.executeCommand('setContext', 'php.untrustValidationExecutableContext', true);
141141
}
142142

143+
const trustEnabled = vscode.workspace.getConfiguration().get('security.workspace.trust.enabled');
144+
if (trustEnabled) {
145+
vscode.workspace.requestWorkspaceTrust();
146+
}
147+
143148
this.delayers = Object.create(null);
144149
if (this.pauseValidation) {
145150
this.pauseValidation = oldExecutable === this.config.executable;
@@ -173,9 +178,6 @@ export default class PHPValidationProvider {
173178
return;
174179
}
175180

176-
interface MessageItem extends vscode.MessageItem {
177-
id: string;
178-
}
179181

180182
let trigger = () => {
181183
let key = textDocument.uri.toString();
@@ -187,35 +189,50 @@ export default class PHPValidationProvider {
187189
delayer.trigger(() => this.doValidate(textDocument));
188190
};
189191

190-
if (this.config!.executableIsUserDefined !== undefined && !this.config!.executableIsUserDefined) {
192+
const trustEnabled = vscode.workspace.getConfiguration().get('security.workspace.trust.enabled');
193+
if (trustEnabled) {
194+
if (vscode.workspace.isTrusted) {
195+
trigger();
196+
}
197+
} else if (this.config!.executableIsUserDefined !== undefined && !this.config!.executableIsUserDefined) {
191198
const checkedExecutablePath = this.workspaceStore.get<string | undefined>(Setting.CheckedExecutablePath, undefined);
192199
if (!checkedExecutablePath || checkedExecutablePath !== this.config!.executable) {
193-
const selected = await vscode.window.showInformationMessage<MessageItem>(
194-
localize('php.useExecutablePath', 'Do you allow {0} (defined as a workspace setting) to be executed to lint PHP files?', this.config!.executable),
195-
{
196-
title: localize('php.yes', 'Allow'),
197-
id: 'yes'
198-
},
199-
{
200-
title: localize('php.no', 'Disallow'),
201-
isCloseAffordance: true,
202-
id: 'no'
203-
}
204-
);
205-
206-
if (!selected || selected.id === 'no') {
207-
this.pauseValidation = true;
208-
} else if (selected.id === 'yes') {
200+
if (await this.showCustomTrustDialog()) {
209201
this.workspaceStore.update(Setting.CheckedExecutablePath, this.config!.executable);
210202
vscode.commands.executeCommand('setContext', 'php.untrustValidationExecutableContext', true);
211-
trigger();
203+
} else {
204+
this.pauseValidation = true;
205+
return;
212206
}
207+
}
213208

214-
return;
209+
trigger();
210+
}
211+
}
212+
213+
private async showCustomTrustDialog(): Promise<boolean> {
214+
interface MessageItem extends vscode.MessageItem {
215+
id: string;
216+
}
217+
218+
const selected = await vscode.window.showInformationMessage<MessageItem>(
219+
localize('php.useExecutablePath', 'Do you allow {0} (defined as a workspace setting) to be executed to lint PHP files?', this.config!.executable),
220+
{
221+
title: localize('php.yes', 'Allow'),
222+
id: 'yes'
223+
},
224+
{
225+
title: localize('php.no', 'Disallow'),
226+
isCloseAffordance: true,
227+
id: 'no'
215228
}
229+
);
230+
231+
if (selected && selected.id === 'yes') {
232+
return true;
216233
}
217234

218-
trigger();
235+
return false;
219236
}
220237

221238
private doValidate(textDocument: vscode.TextDocument): Promise<void> {

extensions/php-language-features/src/typings/refs.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55

66
/// <reference path='../../../../src/vs/vscode.d.ts'/>
77
/// <reference types='@types/node'/>
8+
/// <reference path='../../../../src/vs/vscode.proposed.d.ts'/>

0 commit comments

Comments
 (0)