pull/22/head
Felix Becker 2016-10-12 10:26:08 +02:00
parent 1ba3596923
commit 5963e58ab1
3 changed files with 87 additions and 79 deletions

View File

@ -51,6 +51,7 @@
"vscode": "^0.11.17" "vscode": "^0.11.17"
}, },
"dependencies": { "dependencies": {
"mz": "^2.4.0",
"semver": "^5.3.0", "semver": "^5.3.0",
"vscode": "^0.11.18", "vscode": "^0.11.18",
"vscode-languageclient": "^2.5.0" "vscode-languageclient": "^2.5.0"

View File

@ -1,22 +1,29 @@
'use strict';
import * as path from 'path'; import * as path from 'path';
import { spawn, execFile, ChildProcess } from 'child_process'; import { spawn, execFile, ChildProcess } from 'mz/child_process';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { LanguageClient, LanguageClientOptions, StreamInfo } from 'vscode-languageclient'; import { LanguageClient, LanguageClientOptions, StreamInfo } from 'vscode-languageclient';
import * as semver from 'semver'; import * as semver from 'semver';
import * as net from 'net'; import * as net from 'net';
export function activate(context: vscode.ExtensionContext) { export async function activate(context: vscode.ExtensionContext): Promise<void> {
const conf = vscode.workspace.getConfiguration('php'); const conf = vscode.workspace.getConfiguration('php');
const executablePath = conf.get<string>('executablePath') || 'php'; const executablePath = conf.get<string>('executablePath') || 'php';
// Check path (if PHP is available and version is ^7.0.0). // Check path (if PHP is available and version is ^7.0.0)
execFile(executablePath, ['--version'], (err: NodeJS.ErrnoException, stdout: Buffer, stderr: Buffer) => { let stdout: string;
if (err) { try {
[stdout] = await execFile(executablePath, ['--version']);
} catch (err) {
if (err.code === 'ENOENT') { if (err.code === 'ENOENT') {
vscode.window.showErrorMessage('PHP executable not found. You need PHP 7 installed and in your PATH'); const selected = await vscode.window.showErrorMessage(
'PHP executable not found. Install PHP 7 and add it to your PATH or set the php.executablePath setting',
'Open settings'
);
if (selected === 'Open settings') {
await vscode.commands.executeCommand('workbench.action.openGlobalSettings');
}
} else { } else {
vscode.window.showErrorMessage('Error spawning PHP: ' + err.message); vscode.window.showErrorMessage('Error spawning PHP: ' + err.message);
console.error(err); console.error(err);
@ -25,7 +32,7 @@ export function activate(context: vscode.ExtensionContext) {
} }
// Parse version and discard OS info like 7.0.8--0ubuntu0.16.04.2 // Parse version and discard OS info like 7.0.8--0ubuntu0.16.04.2
const match = stdout.toString().match(/^PHP ([^\s]+)/); const match = stdout.match(/^PHP ([^\s]+)/);
if (!match) { if (!match) {
vscode.window.showErrorMessage('Error parsing PHP version. Please check the output of php --version'); vscode.window.showErrorMessage('Error parsing PHP version. Please check the output of php --version');
return; return;
@ -36,7 +43,7 @@ export function activate(context: vscode.ExtensionContext) {
version = version.replace(/(\d+.\d+.\d+)/, '$1-'); version = version.replace(/(\d+.\d+.\d+)/, '$1-');
} }
if (semver.lt(version, '7.0.0')) { if (semver.lt(version, '7.0.0')) {
vscode.window.showErrorMessage('The language server needs at least PHP 7 installed and in your PATH. Version found: ' + version); vscode.window.showErrorMessage('The language server needs at least PHP 7 installed. Version found: ' + version);
return; return;
} }
@ -76,22 +83,21 @@ export function activate(context: vscode.ExtensionContext) {
}); });
// Options to control the language client // Options to control the language client
let clientOptions: LanguageClientOptions = { const clientOptions: LanguageClientOptions = {
// Register the server for php documents // Register the server for php documents
documentSelector: ['php'] documentSelector: ['php'],
// synchronize: { synchronize: {
// // Synchronize the setting section 'php' to the server // Synchronize the setting section 'php' to the server
// configurationSection: 'php', configurationSection: 'php'
// // Notify the server about file changes to composer.json files contain in the workspace // Notify the server about file changes to composer.json files contain in the workspace
// fileEvents: workspace.createFileSystemWatcher('**/composer.json') // fileEvents: vscode.workspace.createFileSystemWatcher('**/composer.json')
// } }
}; };
// Create the language client and start the client. // Create the language client and start the client.
const disposable = new LanguageClient('PHP Language Client', serverOptions, clientOptions).start(); const disposable = new LanguageClient('PHP Language Server', serverOptions, clientOptions).start();
// Push the disposable to the context's subscriptions so that the // Push the disposable to the context's subscriptions so that the
// client can be deactivated on extension deactivation // client can be deactivated on extension deactivation
context.subscriptions.push(disposable); context.subscriptions.push(disposable);
});
} }

View File

@ -1,5 +1,6 @@
{ {
"dependencies": { "dependencies": {
"mz": "registry:npm/mz#2.4.0+20160911015431",
"semver": "registry:npm/semver#5.0.0+20160723033700" "semver": "registry:npm/semver#5.0.0+20160723033700"
} }
} }