From 9e5703d749c7b9b90d275e0b2cd4824df355e976 Mon Sep 17 00:00:00 2001 From: jens1o Date: Mon, 10 Apr 2017 14:02:02 +0200 Subject: [PATCH] :rocket: Support custom memory limit --- package.json | 12 ++++++++++++ src/extension.ts | 16 +++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index b7c2119..56dbb59 100644 --- a/package.json +++ b/package.json @@ -54,5 +54,17 @@ "mz": "^2.4.0", "semver": "^5.3.0", "vscode-languageclient": "^3.0.3" + }, + "contributes": { + "configuration": { + "title": "PHP-Intellisense", + "properties": { + "phpintellisense.memoryLimit": { + "type": "string", + "default": "-1", + "description": "The memory limit of the php language server. [Number][K|M|G]. Use '-1' to allow unlimited use of the RAM(default)." + } + } + } } } diff --git a/src/extension.ts b/src/extension.ts index 6701735..dccd93a 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -12,6 +12,20 @@ export async function activate(context: vscode.ExtensionContext): Promise const conf = vscode.workspace.getConfiguration('php'); const executablePath = conf.get('executablePath') || 'php'; + const specificSettings = vscode.workspace.getConfiguration('phpintellisense'); + + const memoryLimit = specificSettings.get('memoryLimit') || '-1'; + + if (memoryLimit !== '-1' && !memoryLimit.match('~^(\d+)(K|M|G|)$~')) { + const selected = await vscode.window.showErrorMessage( + 'The memory limit you\'d provided is not numeric, nor "-1" nor valid php shorthand notation!', + 'Open settings' + ); + if (selected === 'Open settings') { + await vscode.commands.executeCommand('workbench.action.openGlobalSettings'); + } + } + // Check path (if PHP is available and version is ^7.0.0) let stdout: string; try { @@ -51,7 +65,7 @@ export async function activate(context: vscode.ExtensionContext): Promise const serverOptions = () => new Promise((resolve, reject) => { function spawnServer(...args: string[]): ChildProcess { // The server is implemented in PHP - args.unshift(context.asAbsolutePath(path.join('vendor', 'felixfbecker', 'language-server', 'bin', 'php-language-server.php'))); + args.unshift(context.asAbsolutePath(path.join('vendor', 'felixfbecker', 'language-server', 'bin', 'php-language-server.php') + ' --memory-limit=' + memoryLimit)); const childProcess = spawn(executablePath, args); childProcess.stderr.on('data', (chunk: Buffer) => { console.error(chunk + '');