-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflycheck-phanclient.el
51 lines (42 loc) · 2.39 KB
/
flycheck-phanclient.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
;;; flycheck-phanclient.el --- A flycheck checker for phan, using the phan daemon.
;;; Commentary:
;;
;; Based on emacs-phpphan, but using phan_client to quickly get a daemon to analyze the current file instead.
;; This code is experimental.
;;; Code:
(require 'flycheck)
(require 'php-project)
;; TODO: Use phan's severity level to choose between warning and info. Include that in the lines printed by phan_client.
;; TODO: Allow users to override the information included in message?
(defvar flycheck-phanclient--phan-executable nil)
;; This will search for "phan" in the following places:
;;
;; 1. If the value of flycheck-phanclient--phan-executable is not nil, use that
;; 2. vendor/bin/phan relative to composer.json in an ancestor directory
;; 3. Search for a separate phan executable or phar file in the executable path
(defun flycheck-phanclient-start-daemon ()
"Start the phan daemon"
(interactive)
(let* ((default-directory (php-project-get-root-dir))
(phan-executable (or flycheck-phanclient--phan-executable
(if (file-exists-p "vendor/bin/phan")
(concat default-directory "vendor/bin/phan")
(executable-find "phan"))))
(cmd (list phan-executable "--daemonize-tcp-port" "4846" "--quick")))
(apply #'start-process "PhanDaemon" "*phan daemon*" cmd)))
(flycheck-define-checker php-phanclient
"A PHP static analyzer using phan. Analyzes the file on buffer save.
See URL `https://github.com/phan/phan'."
:command ("phan_client" "-l" source-original "-f" source)
;; Alternately, use the below :command with the commented out :predicate to only run the check after file save.
;; :command ("phan_client" "-l" source-original)
:error-patterns
((warning line-start (or "Parse" "Fatal" "syntax" "Phan") " error" (any ":" ",") " " (message) " in " (file-name) " on line " line line-end))
:modes (php-mode php+-mode)
; We would work around this by passing the contents of the temporary file and the path to the original file to the daemon through phan_client
; However, if the "-f" option isn't used (and only source-original was used), we would have to limit this to when the buffer was saved(flycheck-buffer-saved-p)
; :predicate flycheck-buffer-saved-p
)
(flycheck-add-next-checker 'php '(warning . php-phanclient))
(add-to-list 'flycheck-checkers 'php-phanclient)
(provide 'flycheck-phanclient)