Skip to content

Commit 298c15b

Browse files
committed
declare phpactor-executable as defcustom (take two)
By doing this, we are able to replace phpactor-find-executable function which is a bit more optimized as completion makes frequent use of it. - update test - reevaluate phpactor-executable using setq (override defcustom), after composer install using hook convert use of phpactor-executable function to use of variable apply change for completion too
1 parent faf853c commit 298c15b

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

README.org

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ This package is Emacs interface to [[http://phpactor.github.io/phpactor/][Phpact
4242

4343
*NOTICE*: To ensure the supported version of Phpactor is installed, you might need to run this command again after an upgrade of this package.
4444

45-
Alternatively, you can install Phpactor on your own and configure `phpactor-executable` but please be aware that any change in Phpactor's rpc protocol can introduce breakages.
46-
45+
Alternatively, you can install Phpactor on your own and customize `phpactor-executable` but please be aware that any change in Phpactor's rpc protocol can introduce breakages.
4746

4847
** Configuration
4948
*** completion

company-phpactor.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Here we create a temporary syntax table in order to add $ to symbols."
7979
(defun company-phpactor (command &optional arg &rest ignored)
8080
"`company-mode' completion backend for Phpactor."
8181
(interactive (list 'interactive))
82-
(when (phpactor-find-executable)
82+
(when phpactor-executable
8383
(save-restriction
8484
(widen)
8585
(pcase command

phpactor.el

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,6 @@
7474
:type 'boolean)
7575

7676
;; Variables
77-
;;;###autoload
78-
(progn
79-
(defvar phpactor-executable nil
80-
"Path to `phpactor' executable file.")
81-
(make-variable-buffer-local 'phpactor-executable)
82-
(put 'phpactor-executable 'safe-local-variable
83-
#'(lambda (v) (if (consp v)
84-
(and (eq 'root (car v)) (stringp (cdr v)))
85-
(or (null v) (stringp v))))))
86-
8777
(defvar phpactor--debug nil)
8878
(defvar phpactor-history-size 100)
8979
(defvar phpactor-history-ring nil)
@@ -121,6 +111,22 @@ of GitHub.")
121111

122112
;; Special variables
123113
(defvar phpactor--execute-async nil)
114+
115+
;;;###autoload
116+
(defun phpactor--find-executable ()
117+
(let ((vendor-executable (f-join phpactor-install-directory "vendor/bin/phpactor")))
118+
(if (file-exists-p vendor-executable)
119+
vendor-executable
120+
(warn "Phpactor not found. Please run phpactor-install-or-update")
121+
nil)))
122+
123+
(defcustom phpactor-executable (phpactor--find-executable)
124+
"Path to phpactor executable.
125+
It is recommemded not to customize this, but if you do, you'll
126+
have to ensure a compatible version of phpactor is used."
127+
:type '(string)
128+
:safe #'stringp
129+
:group 'phpactor)
124130

125131
;; Utility functions
126132
(defun phpactor-find-executable ()
@@ -154,7 +160,9 @@ of GitHub.")
154160
(php-runtime-quote-string (concat directory file))
155161
(php-runtime-quote-string (concat phpactor-install-directory file)))
156162
do (php-runtime-expr code))
163+
(add-hook 'compilation-finish-functions (lambda (buffer desc) (setq phpactor-executable (phpactor--find-executable))))
157164
(composer nil "install" "--no-dev")))
165+
158166
(defalias 'phpactor-update #'phpactor-install-or-update)
159167

160168
(defun phpactor-get-working-dir ()
@@ -172,7 +180,7 @@ of GitHub.")
172180
"Return command string by `SUB-COMMAND' and `ARGS'."
173181
(declare (indent 1))
174182
(mapconcat 'shell-quote-argument
175-
(cons (phpactor-find-executable)
183+
(cons phpactor-executable
176184
(cons sub-command args))
177185
" "))
178186

@@ -199,7 +207,6 @@ of GitHub.")
199207
(let ((json (phpactor--serialize-json (list :action action
200208
:parameters arguments)))
201209
(output (get-buffer-create "*Phpactor Output*"))
202-
(phpactor-executable (phpactor-find-executable))
203210
(coding-system-for-write 'utf-8)
204211
(cwd (phpactor-get-working-dir)))
205212
(with-current-buffer output (erase-buffer))
@@ -543,9 +550,9 @@ function."
543550
(cl-defun phpactor-action-dispatch (&key action parameters version)
544551
"Execite action by `NAME' and `PARAMETERS'."
545552
(when (and version (not (equal phpactor--supported-rpc-version version)))
546-
(if (phpactor-find-executable)
553+
(if phpactor-executable
547554
(error "Phpactor uses rpc protocol %s but this package requires %s" version phpactor--supported-rpc-version)
548-
(error "Phpactor should be upgraded. Please run phpactor-update")))
555+
(error "Phpactor should be upgraded. Please run phpactor-install-or-update")))
549556
(phpactor--add-history 'phpactor-action-dispatch (list :action action :parameters parameters :version version))
550557
(let ((func (cdr-safe (assq (intern action) phpactor-action-table))))
551558
(if func

tests/e2e/test-sanity.el

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
(with-timeout
2929
(timeout-duration (display-warning 'buttercup (format "Error : timeout waiting %s seconds for composer install to finish" timeout-duration)))
3030
(while (not (file-exists-p (f-join phpactor-install-directory "vendor/bin/phpactor")))
31-
(sleep-for 1)))
32-
(expect (phpactor-find-executable) :to-equal (f-join phpactor-install-directory "vendor/bin/phpactor"))
31+
(sleep-for 1))
32+
(sleep-for 1))
33+
(expect phpactor-executable :to-equal (f-join phpactor-install-directory "vendor/bin/phpactor"))
3334
)))
3435

3536
(describe "defun: `phpactor-get-working-dir'"

0 commit comments

Comments
 (0)