@@ -32,8 +32,9 @@ module.exports =
32
32
properties :
33
33
phpCommand :
34
34
title : ' PHP command'
35
- description : ' The path to your PHP binary (e.g. /usr/bin/php, php, ...).
36
- Requires a restart after changing.'
35
+ description : ' The path to your PHP binary (e.g. /usr/bin/php, php, ...). Requires a restart after
36
+ changing. You can also use the php-integrator-base:test-configuration command to
37
+ test it.'
37
38
type : ' string'
38
39
default : ' php'
39
40
order : 1
@@ -284,38 +285,21 @@ module.exports =
284
285
285
286
### *
286
287
* Tests the user's configuration.
287
- *
288
- * @param {bool} testServices
289
- *
290
- * @return {bool}
291
288
###
292
- testConfig : (testServices = true ) ->
289
+ testConfig : () ->
293
290
configTester = new ConfigTester (@ getConfiguration ())
294
291
295
- result = configTester .test ()
296
-
297
- if not result
298
- errorMessage =
299
- " PHP is not correctly set up and as a result PHP integrator will not work. Please visit the settings
300
- screen to correct this error. If you are not specifying an absolute path for PHP or Composer, make
301
- sure they are in your PATH.
302
-
303
- Please restart Atom after correcting the path."
304
-
305
- atom .notifications .addError (' Incorrect setup!' , {' detail' : errorMessage})
306
-
307
- return false
308
-
309
- if testServices and not @projectManagerService ?
292
+ if not configTester .test ()
310
293
errorMessage =
311
- " There is no project manager service available. Install the atom-project-manager package for project
312
- support to work in its full extent."
313
-
314
- atom .notifications .addError (' Incorrect setup!' , {' detail' : errorMessage})
294
+ " PHP is not configured correctly. Please visit the settings screen to correct this error. If you are
295
+ using a relative path to PHP, make sure it is in your PATH variable."
315
296
316
- return false
297
+ atom . notifications . addError ( ' PHP Integrator - Failure ' , { dismissable : true , detail : errorMessage})
317
298
318
- return true
299
+ atom .notifications .addSuccess ' PHP Integrator - Success' , {
300
+ dismissable : true ,
301
+ detail : ' Your setup is working correctly.'
302
+ }
319
303
320
304
### *
321
305
* Registers any commands that are available to the user.
@@ -377,12 +361,8 @@ module.exports =
377
361
378
362
@ performInitialFullIndexForCurrentProject ()
379
363
380
- atom .commands .add ' atom-workspace' , " php-integrator-base:configuration " : =>
381
- return unless @ testConfig ()
382
-
383
- atom .notifications .addSuccess ' Success' , {
384
- ' detail' : ' Your PHP integrator configuration is working correctly!'
385
- }
364
+ atom .commands .add ' atom-workspace' , " php-integrator-base:test-configuration " : =>
365
+ @ testConfig ()
386
366
387
367
atom .commands .add ' atom-workspace' , " php-integrator-base:sort-use-statements " : =>
388
368
activeTextEditor = atom .workspace .getActiveTextEditor ()
@@ -497,41 +477,93 @@ module.exports =
497
477
### *
498
478
* @return {Promise}
499
479
###
500
- updateCoreIfOutdated : () ->
501
- if @ getCoreManager (). isInstalled ()
502
- return new Promise ( resolve , reject ) ->
480
+ installCoreIfNecessary : () ->
481
+ return new Promise ( resolve , reject ) =>
482
+ if @ getCoreManager (). isInstalled ()
503
483
resolve ()
484
+ return
485
+
486
+ message =
487
+ " The core isn't installed yet or is outdated. I can install the latest version for you " +
488
+ " automatically.\n \n " +
489
+
490
+ " First time using this package? Please visit the package settings to set up PHP correctly first."
491
+
492
+ notification = atom .notifications .addInfo (' PHP Integrator - Core Installation' , {
493
+ detail : message
494
+ dismissable : true
495
+
496
+ buttons : [
497
+ {
498
+ text : ' Open package settings'
499
+ onDidClick : () =>
500
+ atom .workspace .open (' atom://config/packages/' + @packageName )
501
+ },
502
+
503
+ {
504
+ text : ' Test my setup'
505
+ onDidClick : () =>
506
+ @ testConfig ()
507
+ },
508
+
509
+ {
510
+ text : ' Ready, install the core'
511
+ onDidClick : () =>
512
+ notification .dismiss ()
513
+
514
+ promise = @ installCore ()
515
+
516
+ promise .then () =>
517
+ resolve ()
518
+
519
+ promise .catch () =>
520
+ reject (new Error (' Core installation failed' ))
521
+ },
522
+
523
+ {
524
+ text : ' No, go away'
525
+ onDidClick : () =>
526
+ notification .dismiss ()
527
+ reject ()
528
+ }
529
+ ]
530
+ })
504
531
532
+ ### *
533
+ * @return {Promise}
534
+ ###
535
+ installCore : () ->
505
536
message =
506
- " The core isn't installed yet or is outdated. A new version is in the process of being downloaded.\n \n " +
537
+ " The core is being downloaded and installed. To do this, Composer is automatically downloaded and " +
538
+ " installed into a temporary folder.\n \n " +
507
539
508
- " Progress is being sent to the developer tools console, in case you'd like to monitor it.\n \n " +
540
+ " Progress and output is sent to the developer tools console, in case you'd like to monitor it.\n \n " +
509
541
510
542
" You will be notified once the install finishes (or fails)."
511
543
512
- atom .notifications .addInfo (' PHP Integrator - Downloading Core' , {' detail' : message, dismissable : true })
544
+ atom .notifications .addInfo (' PHP Integrator - Installing Core' , {' detail' : message, dismissable : true })
513
545
514
546
successHandler = () ->
515
- atom .notifications .addSuccess (' Core installation successful ' , dismissable : true )
547
+ atom .notifications .addSuccess (' PHP Integrator - Core Installation Succeeded ' , dismissable : true )
516
548
517
549
failureHandler = () ->
518
550
message =
519
- " The core failed to install . This can happen for a variety of reasons, such as an outdated PHP " +
551
+ " Installation of the core failed . This can happen for a variety of reasons, such as an outdated PHP " +
520
552
" version or missing extensions.\n \n " +
521
553
522
554
" Logs in the developer tools will likely provide you with more information about what is wrong. You " +
523
555
" can open it via the menu View → Developer → Toggle Developer Tools.\n \n " +
524
556
525
557
" Additionally, the README provides more information about requirements and troubleshooting."
526
558
527
- atom .notifications .addError (' Core installation failed ' , {detail : message, dismissable : true })
559
+ atom .notifications .addError (' PHP Integrator - Core Installation Failed ' , {detail : message, dismissable : true })
528
560
529
- return @ getCoreManager ().install ().then (successHandler, failureHandler)
561
+ @ getCoreManager ().install ().then (successHandler, failureHandler)
530
562
531
563
### *
532
564
* Checks if the php-integrator-navigation package is installed and notifies the user it is obsolete if it is.
533
565
###
534
- notifyAboutRedundantNavigationPackageIfnecessary : () ->
566
+ notifyAboutRedundantNavigationPackageIfNecessary : () ->
535
567
atom .packages .onDidActivatePackage (packageData) ->
536
568
return if packageData .name != ' php-integrator-navigation'
537
569
@@ -565,7 +597,7 @@ module.exports =
565
597
* Checks if the php-integrator-autocomplete-plus package is installed and notifies the user it is obsolete if it
566
598
* is.
567
599
###
568
- notifyAboutRedundantAutocompletionPackageIfnecessary : () ->
600
+ notifyAboutRedundantAutocompletionPackageIfNecessary : () ->
569
601
atom .packages .onDidActivatePackage (packageData) ->
570
602
return if packageData .name != ' php-integrator-autocomplete-plus'
571
603
@@ -599,44 +631,55 @@ module.exports =
599
631
* Activates the package.
600
632
###
601
633
activate : ->
602
- packageDeps .install (@packageName , true ).then () =>
603
- return if not @ testConfig ( false )
634
+ return packageDeps .install (@packageName , true ).then () =>
635
+ promise = @ installCoreIfNecessary ( )
604
636
605
- @ updateCoreIfOutdated ().then () =>
606
- @ notifyAboutRedundantNavigationPackageIfnecessary ()
607
- @ notifyAboutRedundantAutocompletionPackageIfnecessary ()
637
+ promise .then () =>
638
+ @ doActivate ()
639
+
640
+ promise .catch () =>
641
+ return
642
+
643
+ return promise
644
+
645
+ ### *
646
+ * Does the actual activation.
647
+ ###
648
+ doActivate : () ->
649
+ @ notifyAboutRedundantNavigationPackageIfNecessary ()
650
+ @ notifyAboutRedundantAutocompletionPackageIfNecessary ()
608
651
609
- @ registerCommands ()
610
- @ registerConfigListeners ()
611
- @ registerStatusBarListeners ()
652
+ @ registerCommands ()
653
+ @ registerConfigListeners ()
654
+ @ registerStatusBarListeners ()
612
655
613
- @editorTimeoutMap = {}
656
+ @editorTimeoutMap = {}
614
657
615
- @ registerAtomListeners ()
658
+ @ registerAtomListeners ()
616
659
617
- if @ getConfiguration ().get (' datatips.enable' )
618
- @ activateDatatips ()
660
+ if @ getConfiguration ().get (' datatips.enable' )
661
+ @ activateDatatips ()
619
662
620
- if @ getConfiguration ().get (' signatureHelp.enable' )
621
- @ activateSignatureHelp ()
663
+ if @ getConfiguration ().get (' signatureHelp.enable' )
664
+ @ activateSignatureHelp ()
622
665
623
- if @ getConfiguration ().get (' linting.enable' )
624
- @ activateLinting ()
666
+ if @ getConfiguration ().get (' linting.enable' )
667
+ @ activateLinting ()
625
668
626
- if @ getConfiguration ().get (' gotoDefinition.enable' )
627
- @ activateGotoDefinition ()
669
+ if @ getConfiguration ().get (' gotoDefinition.enable' )
670
+ @ activateGotoDefinition ()
628
671
629
- if @ getConfiguration ().get (' autocompletion.enable' )
630
- @ activateAutocompletion ()
672
+ if @ getConfiguration ().get (' autocompletion.enable' )
673
+ @ activateAutocompletion ()
631
674
632
- @ getProxy ().setIsActive (true )
675
+ @ getProxy ().setIsActive (true )
633
676
634
- # This fixes the corner case where the core is still installing, the project manager service has already
635
- # loaded and the project is already active. At that point, the index that resulted from it silently
636
- # failed because the proxy (and core) weren't active yet. This in turn causes the project to not
637
- # automatically start indexing, which is especially relevant if a core update requires a reindex.
638
- if @activeProject ?
639
- @ changeActiveProject (@activeProject )
677
+ # This fixes the corner case where the core is still installing, the project manager service has already
678
+ # loaded and the project is already active. At that point, the index that resulted from it silently
679
+ # failed because the proxy (and core) weren't active yet. This in turn causes the project to not
680
+ # automatically start indexing, which is especially relevant if a core update requires a reindex.
681
+ if @activeProject ?
682
+ @ changeActiveProject (@activeProject )
640
683
641
684
### *
642
685
* Registers listeners for events from Atom's API.
0 commit comments