From e84459db397aac1035f68d9965b1d801cd4958db Mon Sep 17 00:00:00 2001 From: Jens Hausdorf Date: Mon, 10 Apr 2017 22:36:10 +0200 Subject: [PATCH] Support custom memory limit (#102) --- package.json | 12 ++++++++++++ src/extension.ts | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/package.json b/package.json index 5fa7ac3..c4ff1e2 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": { + "properties": { + "php.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).", + "pattern": "^\\d+[KMG]?$" + } + } + } } } diff --git a/src/extension.ts b/src/extension.ts index 706bc14..f17616b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -12,6 +12,19 @@ export async function activate(context: vscode.ExtensionContext): Promise const conf = vscode.workspace.getConfiguration('php'); const executablePath = conf.get('executablePath') || 'php'; + const memoryLimit = conf.get('memoryLimit') || '-1'; + + if (memoryLimit !== '-1' && !/^\d+[KMG]?$/.exec(memoryLimit)) { + 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'); + } + return; + } + // Check path (if PHP is available and version is ^7.0.0) let stdout: string; try { @@ -52,6 +65,7 @@ export async function activate(context: vscode.ExtensionContext): Promise 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.push('--memory-limit=' + memoryLimit); const childProcess = spawn(executablePath, args); childProcess.stderr.on('data', (chunk: Buffer) => { console.error(chunk + '');