diff --git a/extensions/php/package.json b/extensions/php/package.json index 47da015b8f1..7f1aa550478 100644 --- a/extensions/php/package.json +++ b/extensions/php/package.json @@ -94,7 +94,22 @@ "fileMatch": "composer.json", "url": "https://getcomposer.org/schema.json" } - ] + ], + "commands": [ + { + "title": "%command.untrustValidationExecutable%", + "category": "%commands.categroy.php%", + "command": "php.untrustValidationExecutable" + } + ], + "menus": { + "commandPalette": [ + { + "command": "php.untrustValidationExecutable", + "when": "php.untrustValidationExecutableContext" + } + ] + } }, "scripts": { "compile": "gulp compile-extension:php", diff --git a/extensions/php/package.nls.json b/extensions/php/package.nls.json index 1bd4beebcc8..e97deb5196f 100644 --- a/extensions/php/package.nls.json +++ b/extensions/php/package.nls.json @@ -3,5 +3,7 @@ "configuration.validate.enable": "Enable/disable built-in PHP validation.", "configuration.validate.executablePath": "Points to the PHP executable.", "configuration.validate.run": "Whether the linter is run on save or on type.", - "configuration.title": "PHP" + "configuration.title": "PHP", + "commands.categroy.php": "PHP", + "command.untrustValidationExecutable": "Don't trust PHP validation executable" } \ No newline at end of file diff --git a/extensions/php/src/features/validationProvider.ts b/extensions/php/src/features/validationProvider.ts index 3e4d3714578..8d32ba876bc 100644 --- a/extensions/php/src/features/validationProvider.ts +++ b/extensions/php/src/features/validationProvider.ts @@ -115,6 +115,7 @@ export default class PHPValidationProvider { this.diagnosticCollection.delete(textDocument.uri); delete this.delayers[textDocument.uri.toString()]; }, null, subscriptions); + subscriptions.push(vscode.commands.registerCommand('php.untrustValidationExecutable', this.untrustValidationExecutable, this)); } public dispose(): void { @@ -140,6 +141,9 @@ export default class PHPValidationProvider { } this.trigger = RunTrigger.from(section.get('validate.run', RunTrigger.strings.onSave)); } + if (this.executableIsUserDefined !== true && this.workspaceStore.get(CheckedExecutablePath, undefined) !== void 0) { + vscode.commands.executeCommand('setContext', 'php.untrustValidationExecutableContext', true); + } this.delayers = Object.create(null); if (this.pauseValidation) { this.pauseValidation = oldExecutable === this.executable; @@ -161,6 +165,11 @@ export default class PHPValidationProvider { } } + private untrustValidationExecutable() { + this.workspaceStore.update(CheckedExecutablePath, undefined); + vscode.commands.executeCommand('setContext', 'php.untrustValidationExecutableContext', false); + } + private triggerValidate(textDocument: vscode.TextDocument): void { if (textDocument.languageId !== 'php' || this.pauseValidation || !this.validationEnabled) { return; @@ -193,19 +202,14 @@ export default class PHPValidationProvider { title: localize('php.no', 'No'), isCloseAffordance: true, id: 'no' - }, - { - title: localize('php.more', 'Learn More'), - id: 'more' } ).then(selected => { if (!selected || selected.id === 'no') { this.pauseValidation = true; } else if (selected.id === 'yes') { this.workspaceStore.update(CheckedExecutablePath, this.executable); + vscode.commands.executeCommand('setContext', 'php.untrustValidationExecutableContext', true); trigger(); - } else if (selected.id === 'more') { - vscode.commands.executeCommand('vscode.open', vscode.Uri.parse('https://go.microsoft.com/fwlink/?linkid=839878')); } }); return;