You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
Go to file
Hugo Thunnissen 8734c9418d Test + improve `phpinspect-fix-imports' (and parse enums as classes)
- `phpinspect-fix-imports' now sorts the imports alphabetically
- `phpinspect-fix-imports' removes excess trailing newlines
- "enum" keywords are now regarded like "class" keywords. (enum cases not yet
   supported)
- Namespaces were added to token index
1 month ago
benchmarks Add headers to new .el files + delete compile script 1 year ago
scripts Add headers to new .el files + delete compile script 1 year ago
stubs Generate builtin stubs (+ add script to do so) 1 year ago
test Test + improve `phpinspect-fix-imports' (and parse enums as classes) 1 month ago
.gitignore Implement stub index for builtin functions and types 1 year ago
.woodpecker.yml Another attempt at fixing CI 2 years ago
COPYING Add license information 3 years ago
Makefile Implement support for PHP8.1 property typehints 2 months ago
README.md Update README with install/build instructions 1 year ago
phpinspect-autoload.el Make autoload indexation more robust and prevent double indexation 1 month ago
phpinspect-bmap.el Remove unnecessary macros + use `let' to set PLACE in iterative macros 1 year ago
phpinspect-buffer.el Introduce `phpinspect-buffer-fresh-p' and `phpinspect-buffer-reparse-if-not-fresh' 1 month ago
phpinspect-cache.el Refactor use of project root to project obj injection + test and fix some bugs 1 month ago
phpinspect-changeset.el Update copyright statements and apply some code style improvements 1 year ago
phpinspect-class-struct.el Implement stub index for builtin functions and types 1 year ago
phpinspect-class.el Refactor use of project root to project obj injection + test and fix some bugs 1 month ago
phpinspect-completion.el Refactor use of project root to project obj injection + test and fix some bugs 1 month ago
phpinspect-edtrack.el Update copyright statements and apply some code style improvements 1 year ago
phpinspect-eldoc.el Refactor use of project root to project obj injection + test and fix some bugs 1 month ago
phpinspect-fs.el Update copyright statements and apply some code style improvements 1 year ago
phpinspect-imports.el Test + improve `phpinspect-fix-imports' (and parse enums as classes) 1 month ago
phpinspect-index.el Test + improve `phpinspect-fix-imports' (and parse enums as classes) 1 month ago
phpinspect-meta.el Implement removal of unused imports in `phpinspect-fix-imports' 1 month ago
phpinspect-parse-context.el Apply overall code quality improvements 1 year ago
phpinspect-parser.el Test + improve `phpinspect-fix-imports' (and parse enums as classes) 1 month ago
phpinspect-pipeline.el Make autoload indexation more robust and prevent double indexation 1 month ago
phpinspect-project-struct.el Implement stub index for builtin functions and types 1 year ago
phpinspect-project.el Fix bug that broke stub cache 1 month ago
phpinspect-queue.el Remove unnecessary macros + use `let' to set PLACE in iterative macros 1 year ago
phpinspect-resolve.el Resolve types of expressions nested in list tokens 1 month ago
phpinspect-resolvecontext.el Refactor use of project root to project obj injection + test and fix some bugs 1 month ago
phpinspect-serialize.el Support @method annotations for static methods 2 months ago
phpinspect-splayt.el Fix bug in `phpinspect-splayt-find-all-between' that impacted import indexation 6 months ago
phpinspect-suggest.el Refactor use of project root to project obj injection + test and fix some bugs 1 month ago
phpinspect-toc.el Update copyright statements and apply some code style improvements 1 year ago
phpinspect-token-predicates.el Implement support for PHP8.1 property typehints 2 months ago
phpinspect-type.el Test + improve `phpinspect-fix-imports' (and parse enums as classes) 1 month ago
phpinspect-util.el Fix infinite recursion bug in `phpinspect--get-pattern-type-in-block' 1 month ago
phpinspect-worker.el Handle quitting more gracefully in worker and pipeline threads 1 year ago
phpinspect.el Refactor use of project root to project obj injection + test and fix some bugs 1 month ago

README.md

phpinspect.el

PHPInspect is a minor mode that provides code intelligence for PHP in Emacs. At its core is a PHP parser implemented in Emacs Lisp. PHPInspect comes with backends for completion-at-point, company-mode and eldoc. A backend for xref (which provides go-to-definition functionality) is planned to be implemented at a later date. The main documentation of the mode is in the docstring of the mode itself (C-h f phpinspect-mode RET to view, or read it in the source code of phpinspect.el).

Projects and Finding Types

By default, phpinspect will recognize composer projects and read their composer.json files for autoload information which is used to find files in which the types/classes/functions you use in your code are defined. It is also possible to add an "include directory" of files that should always be read and indexed for a certain project. To do this, open a file in a project and run M-x phpinspect-project-add-include-dir. You can also edit the list of include directories via M-x customize-goup RET phpinspect RET.

Example Configuration

If you already have a completion UI setup that is able to use completion-at-point-functions as completion source, you can basically just enable phpinspect-mode and you'll be good to go. An example of a basic mode hook configuration to get the most out of phpinspect is the following:

(defun my-php-personal-hook ()
  ;; Shortcut to add use statements for classes you use.
  (define-key php-mode-map (kbd \"C-c u\") 'phpinspect-fix-imports)

  ;; Shortcuts to quickly search/open files of PHP classes.
  ;; You can make these local to php-mode, but making them global
  ;; like this makes them work in other modes/filetypes as well, which
  ;; can be handy when jumping between templates, config files and PHP code.
  (global-set-key (kbd \"C-c a\") 'phpinspect-find-class-file)
  (global-set-key (kbd \"C-c c\") 'phpinspect-find-own-class-file)

  ;; Enable phpinspect-mode
  (phpinspect-mode))

(add-hook 'php-mode-hook #'my-php-personal-hook)

Example config with company mode setup

;;;###autoload
(defun my-php-personal-hook ()
  ;; It is important to enable `company-mode' before setting
  ;; the variables below.
  (company-mode)
  (setq-local company-minimum-prefix-length 0)
  (setq-local company-tooltip-align-annotations t)
  (setq-local company-idle-delay 0.1)
  (setq-local company-backends '(phpinspect-company-backend))

  ;; Shortcut to add use statements for classes you use.
  (define-key php-mode-map (kbd "C-c u") 'phpinspect-fix-imports)

  ;; Shortcuts to quickly search/open files of PHP classes.
  (global-set-key (kbd "C-c a") 'phpinspect-find-class-file)
  (global-set-key (kbd "C-c c") 'phpinspect-find-own-class-file)

  (phpinspect-mode))

(add-hook 'php-mode-hook #'my-php-personal-hook)

Install from git

git clone https://git.snorba.art/hugo/phpinspect.el ~/projects/phpinspect.el
cd ~/projects/phpinspect.el
make
(add-to-list 'load-path "~/projects/phpinspect.el")
(require 'phpinspect)

Compilation

It is highly recommended to byte- or native compile phpinspect. Aside from the normal performance boost that this brings to most packages, it can reduce phpinspect's parsing time by up to 90%. It especially makes a difference when incrementally parsing edited buffers. For example:

benchmarks/parse-file.el uncompiled on Ryzen 5 3600 (time in seconds):

Incremental parse (warmup):
Elapsed time: 0.168390 (0.019751 in 1 GCs)
Incremental parse:
Elapsed time: 0.143811 (0.000000 in 0 GCs)
Incremental parse (no edits):
Elapsed time: 0.000284 (0.000000 in 0 GCs)
Incremental parse repeat (no edits):
Elapsed time: 0.000241 (0.000000 in 0 GCs)
Incremental parse after buffer edit:
Elapsed time: 0.012449 (0.000000 in 0 GCs)
Incremental parse after 2 more edits:
Elapsed time: 0.015839 (0.000000 in 0 GCs)
Bare (no token reuse) parse (warmup):
Elapsed time: 0.048996 (0.000000 in 0 GCs)
Bare (no token reuse) parse:
Elapsed time: 0.052495 (0.000000 in 0 GCs)

benchmarks/parse-file.el with native compilation on Ryzen 5 3600 (time in seconds):

Incremental parse (warmup):
Elapsed time: 0.023432 (0.000000 in 0 GCs)
Incremental parse:
Elapsed time: 0.018350 (0.000000 in 0 GCs)
Incremental parse (no edits):
Elapsed time: 0.000076 (0.000000 in 0 GCs)
Incremental parse repeat (no edits):
Elapsed time: 0.000058 (0.000000 in 0 GCs)
Incremental parse after buffer edit:
Elapsed time: 0.001212 (0.000000 in 0 GCs)
Incremental parse after 2 more edits:
Elapsed time: 0.001381 (0.000000 in 0 GCs)
Bare (no token reuse) parse (warmup):
Elapsed time: 0.013874 (0.000000 in 0 GCs)
Bare (no token reuse) parse:
Elapsed time: 0.013878 (0.000000 in 0 GCs)

Development

Building

make

Running tests

Tests are implemented using ert. You can run them in batch mode with the following command:

make test

# or:
emacs -L ./ -batch -l ert -l ./test/phpinspect-test.el -f ert-run-tests-batch-and-exit