Support custom memory limit (#102)

pull/105/head
Jens Hausdorf 2017-04-10 22:36:10 +02:00 committed by Felix Becker
parent 7ce298c7c8
commit e84459db39
2 changed files with 26 additions and 0 deletions

View File

@ -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]?$"
}
}
}
}
}

View File

@ -12,6 +12,19 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
const conf = vscode.workspace.getConfiguration('php');
const executablePath = conf.get<string>('executablePath') || 'php';
const memoryLimit = conf.get<string>('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<void>
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 + '');