Check PHP version and display error message
parent
688a732917
commit
93f0135082
|
@ -2,3 +2,4 @@ out/
|
|||
node_modules/
|
||||
vendor/
|
||||
composer.lock
|
||||
typings/
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
"vscode": "^0.11.17"
|
||||
},
|
||||
"dependencies": {
|
||||
"semver": "^5.3.0",
|
||||
"vscode-languageclient": "^2.4.2-next.13"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,39 @@
|
|||
'use strict';
|
||||
|
||||
import * as path from 'path';
|
||||
import { spawn } from 'child_process';
|
||||
import { ExtensionContext } from 'vscode';
|
||||
import { LanguageClient, LanguageClientOptions } from 'vscode-languageclient';
|
||||
import { spawn, execFile, ChildProcess } from 'child_process';
|
||||
import * as vscode from 'vscode';
|
||||
import { LanguageClient, LanguageClientOptions, StreamInfo } from 'vscode-languageclient';
|
||||
import * as semver from 'semver';
|
||||
|
||||
export function activate(context: ExtensionContext) {
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
|
||||
// Check if PHP is available and version is ^7.0.0
|
||||
execFile('php', ['--version'], (err: NodeJS.ErrnoException, stdout: Buffer, stderr: Buffer) => {
|
||||
|
||||
if (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
vscode.window.showErrorMessage('PHP executable not found. You need PHP 7 installed and in your PATH');
|
||||
} else {
|
||||
vscode.window.showErrorMessage('Error spawning PHP: ' + err.message);
|
||||
console.error(err);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let version = stdout.toString().match(/^PHP ([^\s]+)/)[1];
|
||||
// Convert PHP prerelease format like 7.0.0rc1 to 7.0.0-rc1
|
||||
if (!/^\d+.\d+.\d+$/.test(version)) {
|
||||
version = version.replace(/(\d+.\d+.\d+)/, '$1-');
|
||||
}
|
||||
if (!semver.satisfies(version, '^7.0.0')) {
|
||||
vscode.window.showErrorMessage('The language server needs at least PHP 7 installed and in your PATH. Version found: ' + version);
|
||||
return;
|
||||
}
|
||||
|
||||
const serverOptions = (): Promise<ChildProcess | StreamInfo> => {
|
||||
// The server is implemented in PHP
|
||||
const serverPath = context.asAbsolutePath(path.join('vendor', 'felixfbecker', 'language-server', 'bin', 'php-language-server.php'));
|
||||
|
||||
const serverOptions = () => {
|
||||
const childProcess = spawn('php', [serverPath]);
|
||||
childProcess.stderr.on('data', (chunk: Buffer) => {
|
||||
console.error(chunk + '');
|
||||
|
@ -39,4 +62,5 @@ export function activate(context: ExtensionContext) {
|
|||
// Push the disposable to the context's subscriptions so that the
|
||||
// client can be deactivated on extension deactivation
|
||||
context.subscriptions.push(disposable);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
"moduleResolution": "node",
|
||||
"outDir": "out",
|
||||
"noLib": true,
|
||||
"noImplicitAny": true,
|
||||
"sourceMap": true,
|
||||
"rootDir": "src"
|
||||
},
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"semver": "registry:npm/semver#5.0.0+20160723033700"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue