diff --git a/lib/Main.js b/lib/Main.js index 723b513d..0cc2dd64 100644 --- a/lib/Main.js +++ b/lib/Main.js @@ -8,15 +8,12 @@ */ const {CompositeDisposable} = require('atom'); -const packageDeps = require('atom-package-deps'); - const fs = require('fs'); const process = require('process'); const Proxy = require('./Proxy'); const AtomConfig = require('./AtomConfig'); const PhpInvoker = require('./PhpInvoker'); -const ConfigTester = require('./ConfigTester'); const ServerManager = require('./ServerManager'); const ProjectManager = require('./ProjectManager'); const ComposerService = require('./ComposerService'); @@ -28,7 +25,7 @@ const functions = { * * @var {String} */ - serverVersionSpecification: '4.3.1', + serverVersionSpecification: '5.0.0-RC', /** * The name of the package. @@ -115,52 +112,10 @@ const functions = { */ linterProvider: null, - /** - * Tests the user's configuration. - */ - testConfig() { - const configTester = new ConfigTester(this.getPhpInvoker()); - - atom.notifications.addInfo('Serenata - Testing Configuration', { - dismissable: true, - detail: 'Now testing your configuration... \n \n' + - - `If you've selected Docker, this may take a while the first time as the Docker image has to be ` + - `fetched first.` - }); - - const callback = () => { - return configTester.test().then(wasSuccessful => { - if (!wasSuccessful) { - const errorMessage = - `PHP is not configured correctly. Please visit the settings screen to correct this error. ` + - `If you are using a relative path to PHP, make sure it is in your PATH variable.`; - - return atom.notifications.addError('Serenata - Failure', {dismissable: true, detail: errorMessage}); - - } else { - return atom.notifications.addSuccess('Serenata - Success', { - dismissable: true, - detail: 'Your setup is working correctly.' - }); - } - }); - }; - - return this.busySignalService.reportBusyWhile('Testing your configuration...', callback, { - waitingFor : 'computer', - revealTooltip : false - }); - }, - /** * Registers any commands that are available to the user. */ registerCommands() { - atom.commands.add('atom-workspace', { 'php-ide-serenata:test-configuration': () => { - return this.testConfig(); - }}); - return atom.commands.add('atom-workspace', { 'php-ide-serenata:sort-use-statements': () => { const activeTextEditor = atom.workspace.getActiveTextEditor(); @@ -170,118 +125,6 @@ const functions = { }}); }, - /** - * @return {Promise} - */ - installServerIfNecessary() { - return new Promise((resolve, reject) => { - let notification; - if (this.getServerManager().isInstalled()) { - resolve(); - return; - } - - const message = - 'The server isn\'t installed yet or is outdated. I can install the latest version for you ' + - 'automatically.\n \n' + - - 'First time using this package? Please visit the package settings to set up PHP correctly first.'; - - return notification = atom.notifications.addInfo('Serenata - Server Installation', { - detail : message, - dismissable : true, - - buttons: [ - { - text: 'Open package settings', - onDidClick: () => { - return atom.workspace.open(`atom://config/packages/${this.packageName}`); - } - }, - - { - text: 'Test my setup', - onDidClick: () => { - return this.testConfig(); - } - }, - - { - text: 'Ready, install the server', - onDidClick: () => { - notification.dismiss(); - - const callback = () => { - const promise = this.installServer(); - - promise.catch(() => { - return reject(new Error('Server installation failed')); - }); - - return promise.then(() => { - return resolve(); - }); - }; - - if (this.busySignalService) { - return this.busySignalService.reportBusyWhile('Installing the server...', callback, { - waitingFor : 'computer', - revealTooltip : false - }); - - } else { - return console.warn( - 'Busy signal service not loaded yet whilst installing server, not showing ' + - 'loading spinner' - ); - } - } - }, - - { - text: 'No, go away', - onDidClick: () => { - notification.dismiss(); - return reject(); - } - } - ] - }); - }); - }, - - /** - * @return {Promise} - */ - installServer() { - let message = - 'The server is being downloaded and installed. To do this, Composer is automatically downloaded and ' + - 'installed into a temporary folder.\n \n' + - - 'Progress and output is sent to the developer tools console, in case you\'d like to monitor it.\n \n' + - - 'You will be notified once the install finishes (or fails).'; - - atom.notifications.addInfo('Serenata - Installing Server', {'detail': message, dismissable: true}); - - const successHandler = () => atom.notifications.addSuccess('Serenata - Server Installation Succeeded', {dismissable: true}); - - const failureHandler = function() { - message = - 'Installation of the server failed. This can happen for a variety of reasons, such as an outdated ' + - 'PHP version or missing extensions.\n \n' + - - 'Logs in the developer tools will likely provide you with more information about what is wrong. You ' + - 'can open it via the menu View → Developer → Toggle Developer Tools.\n \n' + - - 'Additionally, the README provides more information about requirements and troubleshooting.'; - - return atom.notifications.addError('Serenata - Server Installation Failed', {detail: message, dismissable: true}); - }; - - return this.getServerManager().install().then(successHandler, failureHandler); - }, - /** * Shows a notification informing about support. */ @@ -355,24 +198,6 @@ const functions = { }); }, - /** - * Activates the package. - */ - activate() { - return packageDeps.install(this.packageName, true).then(() => { - const promise = this.installServerIfNecessary(); - - promise.then(() => { - return this.doActivate(); - }); - - promise.catch(() => { - }); - - return promise; - }); - }, - /** * @return {Service} */ @@ -487,6 +312,7 @@ const SerenataClient = require('./SerenataClient'); const client = new SerenataClient( functions.getProxy(), functions.getProjectManager(), + functions.getServerManager(), functions.getPhpInvoker(), functions.getConfiguration() ); diff --git a/lib/SerenataClient.js b/lib/SerenataClient.js index 5f307ebf..d839be49 100644 --- a/lib/SerenataClient.js +++ b/lib/SerenataClient.js @@ -2,6 +2,7 @@ 'use strict'; +const packageDeps = require('atom-package-deps'); const {AutoLanguageClient} = require('atom-languageclient'); const MethodAnnotationProvider = require('./Annotations/MethodAnnotationProvider'); const PropertyAnnotationProvider = require('./Annotations/PropertyAnnotationProvider'); @@ -10,14 +11,18 @@ module.exports = class SerenataClient extends AutoLanguageClient { - constructor(proxy, projectManager, phpInvoker, config) { + constructor(proxy, projectManager, serenataServerManager, phpInvoker, config) { super(); + this.packageName = 'php-ide-serenata'; + this.serverVersionSpecification = '5.0.0-RC'; + this.proxy = proxy; this.config = config; this.connection = null; this.annotationProviders = []; this.refactoringProviders = []; + this.serenataServerManager = serenataServerManager; this.projectManager = projectManager; this.phpInvoker = phpInvoker; this.indexingProgressBusyMessage = null; @@ -39,7 +44,7 @@ class SerenataClient extends AutoLanguageClient return 'socket'; } - activate() { + async activate() { this.registerConfigListeners(); // Necessary up front as we can only send intention providers once. If we wait until refactoring is activated, @@ -61,7 +66,113 @@ class SerenataClient extends AutoLanguageClient return super.deactivate(); } + async installServerIfNecessary() { + return new Promise((resolve, reject) => { + if (this.serenataServerManager.isInstalled()) { + resolve(); + return; + } + + const message = + 'The server isn\'t installed yet or is outdated. I can install the latest version for you ' + + 'automatically.\n \n' + + + 'First time using this package? Please visit the package settings to set up PHP correctly first.'; + + let notification = atom.notifications.addInfo('Serenata - Server Installation', { + detail : message, + dismissable : true, + + buttons: [ + { + text: 'Open package settings', + onDidClick: () => { + atom.workspace.open(`atom://config/packages/${this.packageName}`); + } + }, + + { + text: 'Test my setup', + onDidClick: () => { + this.testConfig(); + } + }, + + { + text: 'Ready, install the server', + onDidClick: () => { + notification.dismiss(); + + const callback = async () => { + try { + await this.installServer(); + } catch (e) { + reject(new Error('Server installation failed')); + return; + } + + resolve(); + }; + + if (this.busySignalService) { + this.busySignalService.reportBusyWhile('Installing the server...', callback, { + waitingFor : 'computer', + revealTooltip : false + }); + } else { + console.warn( + 'Busy signal service not loaded yet whilst installing server, not showing ' + + 'loading spinner' + ); + } + } + }, + + { + text: 'No, go away', + onDidClick: () => { + notification.dismiss(); + reject(); + } + } + ] + }); + }); + } + + async installServer() { + const message = + 'The server is being downloaded and installed. To do this, Composer is automatically downloaded and ' + + 'installed into a temporary folder.\n \n' + + + 'Progress and output is sent to the developer tools console, in case you\'d like to monitor it.\n \n' + + + 'You will be notified once the install finishes (or fails).'; + + atom.notifications.addInfo('Serenata - Installing Server', {'detail': message, dismissable: true}); + + try { + await this.serenataServerManager.install(); + } catch (e) { + const message = + 'Installation of the server failed. This can happen for a variety of reasons, such as an outdated ' + + 'PHP version or missing extensions.\n \n' + + + 'Logs in the developer tools will likely provide you with more information about what is wrong. You ' + + 'can open it via the menu View → Developer → Toggle Developer Tools.\n \n' + + + 'Additionally, the README provides more information about requirements and troubleshooting.'; + + atom.notifications.addError('Serenata - Server Installation Failed', {detail: message, dismissable: true}); + } + + atom.notifications.addSuccess('Serenata - Server Installation Succeeded', {dismissable: true}); + } + async startServerProcess() { + await packageDeps.install(this.packageName, true); + await this.installServerIfNecessary(); + let server; [this.socket, server] = await this.proxy.getSocketConnection(); @@ -419,6 +530,10 @@ class SerenataClient extends AutoLanguageClient } registerCommands() { + atom.commands.add('atom-workspace', { 'php-ide-serenata:test-configuration': () => { + this.testConfig(); + }}); + atom.commands.add('atom-workspace', { 'php-ide-serenata:restart': () => { this.restartAllServers(); }}); @@ -460,4 +575,39 @@ class SerenataClient extends AutoLanguageClient this.restartAllServers(); }}); } + + testConfig() { + const ConfigTester = require('./ConfigTester'); + const configTester = new ConfigTester(this.phpInvoker); + + atom.notifications.addInfo('Serenata - Testing Configuration', { + dismissable: true, + detail: 'Now testing your configuration... \n \n' + + + `If you're running through a container, this may take a while the first time as the container ` + + `image has to be fetched first.` + }); + + const callback = async () => { + const wasSuccessful = await configTester.test(); + + if (!wasSuccessful) { + const errorMessage = + `PHP is not configured correctly. Please visit the settings screen to correct this error. ` + + `If you are using a relative path to PHP, make sure it is in your PATH variable.`; + + atom.notifications.addError('Serenata - Failure', {dismissable: true, detail: errorMessage}); + } else { + atom.notifications.addSuccess('Serenata - Success', { + dismissable: true, + detail: 'Your configuration is working correctly.' + }); + } + }; + + return this.busySignalService.reportBusyWhile('Testing...', callback, { + waitingFor : 'computer', + revealTooltip : false + }); + } };