Implement workspace trust for php-language-features
This commit is contained in:
parent
643756788f
commit
27cf6a3807
3 changed files with 47 additions and 24 deletions
|
@ -9,6 +9,7 @@
|
|||
"engines": {
|
||||
"vscode": "0.10.x"
|
||||
},
|
||||
"enableProposedApi": true,
|
||||
"activationEvents": [
|
||||
"onLanguage:php"
|
||||
],
|
||||
|
@ -16,6 +17,10 @@
|
|||
"categories": [
|
||||
"Programming Languages"
|
||||
],
|
||||
"workspaceTrust": {
|
||||
"request": "onDemand",
|
||||
"description": "The extension requires workspace trust when the `php.validate.executablePath` setting will load a version of PHP in the workspace."
|
||||
},
|
||||
"contributes": {
|
||||
"configuration": {
|
||||
"title": "%configuration.title%",
|
||||
|
|
|
@ -140,6 +140,11 @@ export default class PHPValidationProvider {
|
|||
vscode.commands.executeCommand('setContext', 'php.untrustValidationExecutableContext', true);
|
||||
}
|
||||
|
||||
const trustEnabled = vscode.workspace.getConfiguration().get('security.workspace.trust.enabled');
|
||||
if (trustEnabled) {
|
||||
vscode.workspace.requestWorkspaceTrust();
|
||||
}
|
||||
|
||||
this.delayers = Object.create(null);
|
||||
if (this.pauseValidation) {
|
||||
this.pauseValidation = oldExecutable === this.config.executable;
|
||||
|
@ -173,9 +178,6 @@ export default class PHPValidationProvider {
|
|||
return;
|
||||
}
|
||||
|
||||
interface MessageItem extends vscode.MessageItem {
|
||||
id: string;
|
||||
}
|
||||
|
||||
let trigger = () => {
|
||||
let key = textDocument.uri.toString();
|
||||
|
@ -187,35 +189,50 @@ export default class PHPValidationProvider {
|
|||
delayer.trigger(() => this.doValidate(textDocument));
|
||||
};
|
||||
|
||||
if (this.config!.executableIsUserDefined !== undefined && !this.config!.executableIsUserDefined) {
|
||||
const trustEnabled = vscode.workspace.getConfiguration().get('security.workspace.trust.enabled');
|
||||
if (trustEnabled) {
|
||||
if (vscode.workspace.isTrusted) {
|
||||
trigger();
|
||||
}
|
||||
} else if (this.config!.executableIsUserDefined !== undefined && !this.config!.executableIsUserDefined) {
|
||||
const checkedExecutablePath = this.workspaceStore.get<string | undefined>(Setting.CheckedExecutablePath, undefined);
|
||||
if (!checkedExecutablePath || checkedExecutablePath !== this.config!.executable) {
|
||||
const selected = await vscode.window.showInformationMessage<MessageItem>(
|
||||
localize('php.useExecutablePath', 'Do you allow {0} (defined as a workspace setting) to be executed to lint PHP files?', this.config!.executable),
|
||||
{
|
||||
title: localize('php.yes', 'Allow'),
|
||||
id: 'yes'
|
||||
},
|
||||
{
|
||||
title: localize('php.no', 'Disallow'),
|
||||
isCloseAffordance: true,
|
||||
id: 'no'
|
||||
}
|
||||
);
|
||||
|
||||
if (!selected || selected.id === 'no') {
|
||||
this.pauseValidation = true;
|
||||
} else if (selected.id === 'yes') {
|
||||
if (await this.showCustomTrustDialog()) {
|
||||
this.workspaceStore.update(Setting.CheckedExecutablePath, this.config!.executable);
|
||||
vscode.commands.executeCommand('setContext', 'php.untrustValidationExecutableContext', true);
|
||||
trigger();
|
||||
} else {
|
||||
this.pauseValidation = true;
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
trigger();
|
||||
}
|
||||
}
|
||||
|
||||
private async showCustomTrustDialog(): Promise<boolean> {
|
||||
interface MessageItem extends vscode.MessageItem {
|
||||
id: string;
|
||||
}
|
||||
|
||||
trigger();
|
||||
const selected = await vscode.window.showInformationMessage<MessageItem>(
|
||||
localize('php.useExecutablePath', 'Do you allow {0} (defined as a workspace setting) to be executed to lint PHP files?', this.config!.executable),
|
||||
{
|
||||
title: localize('php.yes', 'Allow'),
|
||||
id: 'yes'
|
||||
},
|
||||
{
|
||||
title: localize('php.no', 'Disallow'),
|
||||
isCloseAffordance: true,
|
||||
id: 'no'
|
||||
}
|
||||
);
|
||||
|
||||
if (selected && selected.id === 'yes') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private doValidate(textDocument: vscode.TextDocument): Promise<void> {
|
||||
|
|
|
@ -5,3 +5,4 @@
|
|||
|
||||
/// <reference path='../../../../src/vs/vscode.d.ts'/>
|
||||
/// <reference types='@types/node'/>
|
||||
/// <reference path='../../../../src/vs/vscode.proposed.d.ts'/>
|
||||
|
|
Loading…
Reference in a new issue