Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/emacs-php/phpactor.el

Interface to Phpactor (an intelligent code-completion and refactoring tool for PHP)
https://github.com/emacs-php/phpactor.el

Last synced: 2 months ago
JSON representation

Interface to Phpactor (an intelligent code-completion and refactoring tool for PHP)

Awesome Lists containing this project

README

        

* phpactor.el - PHP refactoring and introspection
This package is Emacs interface to [[http://phpactor.github.io/phpactor/][Phpactor]].

*NOTICE*: This package is in development. Since some functions are running, this is released as an /alpha version/.

*NOTICE*: Phpactor is also in development stage.

#+BEGIN_HTML
Build Status
MELPA: phpactor
MELPA stable: phpactor
#+END_HTML
** Consider moving to LSP
Phpactor is a language server that supports the LSP Protocol and its own RPC protocol. This package only implements Phpactor's own RPC protocol.

They won't be removed immediately, but the LSP provides a comprehensive better user experience.
This package will continue to be maintained and we will follow any changes to the RPC protocol.

Please read [[https://github.com/emacs-php/php-mode/wiki/LSP-Support][LSP Support · emacs-php/php-mode Wiki]] for LSP clients in PHP.

** Installation

*Requirement*: You need to have composer globally installed.

*** First step
**** Installation with use-package :

#+BEGIN_SRC emacs-lisp
(use-package phpactor :ensure t)
(use-package company-phpactor :ensure t)
#+END_SRC

**** Installation with straight.el

(here using straight.el with use-package)

#+BEGIN_SRC emacs-lisp
(use-package phpactor
:straight (phpactor
:host github
:type git
:repo "emacs-php/phpactor.el"
:branch "master"
:files ("*.el" "composer.json" "composer.lock" (:exclude "*test.el"))
)
)
#+END_SRC

*** Second step
After having installed this package, run `phpactor-install-or-update` (this will install a supported version of phpactor inside `.emacs.d/phpactor`).

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

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.

** Configuration
*** completion
#+BEGIN_SRC emacs-lisp
(use-package php-mode
;;
:hook ((php-mode . (lambda () (set (make-local-variable 'company-backends)
'(;; list of backends
company-phpactor
company-files
))))))
#+END_SRC

*** eldoc integration

#+BEGIN_SRC elisp
(add-hook 'php-mode-hook
(lambda ()
(make-local-variable 'eldoc-documentation-function)
(setq eldoc-documentation-function
'phpactor-hover)))
#+END_SRC

*** Jump (go to definition)
**** using [[https://github.com/jojojames/smart-jump][Smart-jump]]
#+BEGIN_SRC elisp
(with-eval-after-load 'php-mode
(phpactor-smart-jump-register))
#+END_SRC
**** without Smart-jump
#+BEGIN_SRC elisp
(with-eval-after-load 'php-mode
(define-key php-mode-map (kbd "M-.") #'phpactor-goto-definition)
(define-key php-mode-map (kbd "M-?") #'phpactor-find-references))
#+END_SRC
*** phpactor itself
See https://phpactor.github.io/phpactor/configuration.html

*** keybindings

Phpactor.el doesn't bring any keybindings and it's up to you to configure them as you wish.

You could for example limit yourself to only one by using [[https://github.com/magit/transient][transient.el]] like this

#+BEGIN_SRC elisp
(define-transient-command php-transient-menu ()
"Php"
[["Class"
("cc" "Copy" phpactor-copy-class)
("cn" "New" phpactor-create-new-class)
("cr" "Move" phpactor-move-class)
("ci" "Inflect" phpactor-inflect-class)
("n" "Namespace" phpactor-fix-namespace)]
["Properties"
("a" "Accessor" phpactor-generate-accessors)
("pc" "Constructor" phpactor-complete-constructor)
("pm" "Add missing props" phpactor-complete-properties)
("r" "Rename var locally" phpactor-rename-variable-local)
("R" "Rename var in file" phpactor-rename-variable-file)]
["Extract"
("ec" "constant" phpactor-extract-constant)
("ee" "expression" phpactor-extract-expression)
("em" "method" phpactor-extract-method)]
["Methods"
("i" "Implement Contracts" phpactor-implement-contracts)
("m" "Generate method" phpactor-generate-method)]
["Navigate"
("x" "List refs" phpactor-list-references)
("X" "Replace refs" phpactor-replace-references)
("." "Goto def" phpactor-goto-definition)]
["Phpactor"
("s" "Status" phpactor-status)
("u" "Install" phpactor-install-or-update)]])
#+END_SRC

** Troubleshooting

You can run ``phpactor-status`` while visiting a project file.

If needed, configure [[https://github.com/emacs-php/php-mode/blob/1f04813f46219e626b385d0d96abefad914bfae0/php-project.el#L54][the way the project root is detected]] via .dir-locals.el

"*Phpactor Output*" buffer might also contain useful informations.

** About Phpactor

We will assume your emacs configuration is stored under "~/.emacs.d/"

*** Where is phpactor installed

After running `phpactor-install-or-update`, phpactor should be installed under "~/.emacs.d/phpactor/".
And the phpactor executable should be "~/.emacs.d/phpactor/vendor/bin/phpactor"

*** Contribute to phpactor

Phpactor's packages are cloned (using git) under "~/.emacs.d/phpactor/vendor/phpactor".
If you make a modification to phpactor you'd like to contribute, you can just of git straight away to open a pull request therefrom.