Apply overall code quality improvements
ci/woodpecker/push/woodpecker Pipeline failed Details

Even benchmarks and tests now compile without warnings or errors :)

This includes patches from Stefan Monnier:
- https://lists.gnu.org/archive/html/emacs-devel/2023-08/msg00548.html
WIP-cache
Hugo Thunnissen 9 months ago
parent 20ec37481a
commit 2d29bce498

@ -30,30 +30,35 @@
(current-buffer)
(point-max)))
(let ((here (file-name-directory (or load-file-name buffer-file-name))))
(let ((here (file-name-directory (macroexp-file-name)))
result)
(with-temp-buffer
(insert-file-contents (concat here "/Response.php"))
(insert-file-contents (expand-file-name "Response.php" here))
(message "Incremental parse (warmup):")
(phpinspect-with-parse-context (phpinspect-make-pctx :incremental t :bmap (phpinspect-make-bmap))
(benchmark 1 '(phpinspect-parse-current-buffer)))
(setq result (benchmark-run 1 (phpinspect-parse-current-buffer))))
(message "Elapsed time: %f (%f in %d GC's)" (car result) (caddr result) (cadr result))
(let ((bmap (phpinspect-make-bmap))
(bmap2 (phpinspect-make-bmap)))
(message "Incremental parse:")
(phpinspect-with-parse-context (phpinspect-make-pctx :incremental t :bmap bmap)
(benchmark 1 '(phpinspect-parse-current-buffer)))
(setq result (benchmark-run 1 (phpinspect-parse-current-buffer))))
(garbage-collect)
(message "Elapsed time: %f (%f in %d GC's)" (car result) (caddr result) (cadr result))
(garbage-collect)
(message "Incremental parse (no edits):")
(phpinspect-with-parse-context (phpinspect-make-pctx :incremental t
:bmap bmap2
:previous-bmap bmap
:edtrack (phpinspect-make-edtrack))
(benchmark 1 '(phpinspect-parse-current-buffer)))
(setq result (benchmark-run 1 (phpinspect-parse-current-buffer))))
(message "Elapsed time: %f (%f in %d GC's)" (car result) (caddr result) (cadr result))
(garbage-collect)
(message "Incremental parse repeat (no edits):")
@ -61,7 +66,8 @@
:bmap (phpinspect-make-bmap)
:previous-bmap bmap2
:edtrack (phpinspect-make-edtrack))
(benchmark 1 '(phpinspect-parse-current-buffer)))
(setq result (benchmark-run 1 (phpinspect-parse-current-buffer))))
(message "Elapsed time: %f (%f in %d GC's)" (car result) (caddr result) (cadr result))
(garbage-collect)
@ -81,8 +87,9 @@
(phpinspect-edtrack-register-edit edtrack 9061 9061 1)
(phpinspect-with-parse-context (phpinspect-make-pctx :bmap bmap-after :incremental t :previous-bmap bmap :edtrack edtrack)
(benchmark 1 '(phpinspect-parse-current-buffer)))
(setq result (benchmark-run 1 (phpinspect-parse-current-buffer))))
(message "Elapsed time: %f (%f in %d GC's)" (car result) (caddr result) (cadr result))
(phpinspect-edtrack-clear edtrack)
(insert "{")
@ -98,22 +105,27 @@
:incremental t
:previous-bmap bmap-after
:edtrack edtrack)
(benchmark 1 '(phpinspect-parse-current-buffer)))
(setq result (benchmark-run 1 (phpinspect-parse-current-buffer))))
(message "Elapsed time: %f (%f in %d GC's)" (car result) (caddr result) (cadr result))
;; (save-current-buffer
;; (profiler-stop)
;; (profiler-report)
;; (profiler-report-write-profile (concat here "/profile.txt")))
;; (profiler-report-write-profile (expand-file-name "profile.txt" here)))
)))
(with-temp-buffer
(insert-file-contents (concat here "/Response.php"))
(insert-file-contents (expand-file-name "Response.php" here))
(garbage-collect)
(message "Bare (no token reuse) parse (warmup):")
(benchmark 1 '(phpinspect-parse-current-buffer))
(setq result (benchmark-run 1 (phpinspect-parse-current-buffer)))
(message "Elapsed time: %f (%f in %d GC's)" (car result) (caddr result) (cadr result))
(garbage-collect)
(message "Bare (no token reuse) parse:")
(benchmark 1 '(phpinspect-parse-current-buffer))))
(setq result (benchmark-run 1 (phpinspect-parse-current-buffer))))
(message "Elapsed time: %f (%f in %d GC's)" (car result) (caddr result) (cadr result)))

@ -53,7 +53,7 @@
(setq result
(benchmark-run 1
(phpinspect-splayt-traverse (i tree)
i)))
(ignore i))))
(message "Elapsed time: %f (%f in %d GC's)"
(car result) (caddr result) (cadr result))
@ -64,7 +64,7 @@
(setq result
(benchmark-run 1
(phpinspect-splayt-traverse-lr (i tree)
i)))
(ignore i))))
(message "Elapsed time: %f (%f in %d GC's)"
(car result) (caddr result) (cadr result)))
@ -87,7 +87,7 @@
(setq result
(benchmark-run 1
(dotimes (i 10000)
(gethash i map))))
(ignore (gethash i map)))))
(message "Elapsed time: %f (%f in %d GC's)"
(car result) (caddr result) (cadr result))
@ -97,7 +97,7 @@
(garbage-collect)
(setq result
(benchmark-run 1
(maphash (lambda (k v) k v) map)))
(ignore (maphash (lambda (k v) k v) map))))
(message "Elapsed time: %f (%f in %d GC's)"
(car result) (caddr result) (cadr result)))

@ -1,11 +1,14 @@
#!/bin/bash
rm ./**/*.elc
rm *.elc
for file in ./*.el; do
cask emacs -batch -L . --eval '(setq byte-compile-error-on-warn t)' -f batch-byte-compile "$file" || break
done
for file in ./**/*.el; do
cask emacs -batch -L . --eval '(setq byte-compile-error-on-warn nil)' -f batch-byte-compile "$file" || break
cask emacs -batch -L . --eval '(setq byte-compile-error-on-warn t)' -f batch-byte-compile "$file" || break
done
if [[ -z $NO_REMOVE_ELC ]]; then

@ -405,8 +405,9 @@ NAMESPACE will be assumed the root namespace if not provided"
"Find usage of the \"new\" keyword in TOKENS.
Return value is a list of the types that are \"newed\"."
(let ((previous-tokens)
(used-types))
(let* ((previous-tokens)
(used-types (cons nil nil))
(used-types-rear used-types))
(while tokens
(let ((token (pop tokens))
(previous-token (car previous-tokens)))
@ -415,23 +416,25 @@ Return value is a list of the types that are \"newed\"."
(phpinspect-word-p token))
(let ((type (cadr token)))
(when (not (string-match-p "\\\\" type))
(push type used-types))))
(setq used-types-rear (setcdr used-types-rear (cons type nil))))))
((and (phpinspect-static-attrib-p token)
(phpinspect-word-p previous-token))
(let ((type (cadr previous-token)))
(when (not (string-match-p "\\\\" type))
(push type used-types))))
(setq used-types-rear (setcdr used-types-rear (cons type nil))))))
((phpinspect-object-attrib-p token)
(let ((lists (seq-filter #'phpinspect-list-p token)))
(dolist (list lists)
(setq used-types (append (phpinspect--find-used-types-in-tokens (cdr list))
used-types)))))
(setq used-types-rear
(nconc used-types-rear
(phpinspect--find-used-types-in-tokens (cdr list)))
used-types-rear (last used-types-rear)))))
((or (phpinspect-list-p token) (phpinspect-block-p token))
(setq used-types (append (phpinspect--find-used-types-in-tokens (cdr token))
used-types))))
(setq used-types-rear
(nconc used-types-rear (phpinspect--find-used-types-in-tokens (cdr token)))
used-types-rear (last used-types-rear))))
(push token previous-tokens)))
used-types))
(cdr used-types)))
(defun phpinspect--index-tokens (tokens &optional type-resolver-factory location-resolver)
"Index TOKENS as returned by `phpinspect--parse-current-buffer`."

@ -36,7 +36,7 @@ parsing. Usually used in combination with
"Parser Context"
(incremental nil)
(meta-iterator nil)
(interrupt-threshold (time-convert '(0 0 2000 0))
(interrupt-threshold (time-convert '(0 0 2000 0) t)
:documentation
"After how much time `interrupt-predicate'
should be polled. This is 2ms by default.")

@ -144,116 +144,110 @@ HANDLERS must be a list of symbols referring to existing
parser handlers defined using `phpinspect-defhandler'.
DELIMITER-PREDICATE must be a function. It is passed the last
parsed token after every handler iteration. If it evaluates to
parsed token after every handler iteration. If it returns
something other than nil, parsing is deemed completed and the
loop exits. An example use case of this is to determine the end
of a statement. You can use `phpinspect-terminator-p` as
delimiter predicate and have parsing stop when the last parsed
token is \";\", which marks the end of a statement in PHP."
(let ((delimiter-predicate (if (symbolp delimiter-predicate)
`(quote ,delimiter-predicate)
delimiter-predicate)))
`(defsubst ,(phpinspect-parser-func-name name "simple") (buffer max-point &optional skip-over continue-condition &rest _ignored)
(with-current-buffer buffer
(let* ((tokens (cons ,tree-type nil))
(tokens-rear tokens)
token
(delimiter-predicate (when (functionp ,delimiter-predicate) ,delimiter-predicate)))
(when skip-over (forward-char skip-over))
(cl-assert (symbolp delimiter-predicate))
`(defun ,(phpinspect-parser-func-name name "simple") (buffer max-point &optional skip-over continue-condition &rest _ignored)
(with-current-buffer buffer
(let* ((tokens (cons ,tree-type nil))
(tokens-rear tokens)
token)
(when skip-over (forward-char skip-over))
(while (and (< (point) max-point)
(if continue-condition (funcall continue-condition) t)
(not ,(if delimiter-predicate
`(,delimiter-predicate (car (last tokens)))
nil)))
(cond ,@(mapcar
(lambda (handler)
`((looking-at (,(phpinspect-handler-regexp-func-name handler)))
(setq token (,(phpinspect-handler-func-name handler) (match-string 0) max-point))
(when token
(setq tokens-rear (setcdr tokens-rear (cons token nil))))))
handlers)
(t (forward-char))))
;; Return
tokens))))
(defun phpinspect-make-incremental-parser-function (name tree-type handlers &optional delimiter-predicate)
"Like `phpinspect-make-parser-function', but returned function
is able to reuse an already parsed tree."
(cl-assert (symbolp delimiter-predicate))
`(defun ,(phpinspect-parser-func-name name "incremental") (context buffer max-point &optional skip-over continue-condition root)
(with-current-buffer buffer
(let* ((tokens (cons ,tree-type nil))
(tokens-rear tokens)
(root-start (point))
(bmap (phpinspect-pctx-bmap context))
(previous-bmap (phpinspect-pctx-previous-bmap context))
(edtrack (phpinspect-pctx-edtrack context))
(taint-iterator (when edtrack (phpinspect-edtrack-make-taint-iterator edtrack)))
(check-interrupt (phpinspect-pctx-interrupt-predicate context))
;; Loop variables
(start-position)
(original-position)
(current-end-position)
(existing-meta)
(delta)
(token))
(when skip-over (forward-char skip-over))
(phpinspect-pctx-save-whitespace context
(while (and (< (point) max-point)
(if continue-condition (funcall continue-condition) t)
(not (if delimiter-predicate
(funcall delimiter-predicate (car (last tokens)))
nil)))
(cond ,@(mapcar
(not ,(if delimiter-predicate
`(,delimiter-predicate (car (last tokens)))
nil)))
(when check-interrupt
(phpinspect-pctx-check-interrupt context))
(setq start-position (point))
(cond ((and previous-bmap edtrack
(setq existing-meta
(phpinspect-bmap-token-starting-at
previous-bmap
(setq original-position
(phpinspect-edtrack-original-position-at-point edtrack start-position))))
(not (or (phpinspect-root-p (phpinspect-meta-token existing-meta))
(phpinspect-taint-iterator-token-is-tainted-p taint-iterator existing-meta))))
(setq delta (- start-position original-position)
current-end-position (+ (phpinspect-meta-end existing-meta) delta)
token (phpinspect-meta-token existing-meta))
;;(message "Reusing token %s at point %s" (phpinspect-meta-string existing-meta) (point))
;; Re-register existing token
(phpinspect-bmap-overlay
bmap previous-bmap existing-meta delta
(phpinspect-pctx-consume-whitespace context))
(goto-char current-end-position)
;; Skip over whitespace after so that we don't do a full
;; run down all of the handlers during the next iteration
(when (looking-at (phpinspect-handler-regexp whitespace))
(,(phpinspect-handler-func-name 'whitespace) (match-string 0))))
,@(mapcar
(lambda (handler)
`((looking-at (,(phpinspect-handler-regexp-func-name handler)))
(setq token (,(phpinspect-handler-func-name handler) (match-string 0) max-point))
(when token
(setq tokens-rear (setcdr tokens-rear (cons token nil))))))
(phpinspect-pctx-register-token context token start-position (point)))))
handlers)
(t (forward-char))))
;; Return
tokens)))))
(t (forward-char)))
(when token
(setq tokens-rear (setcdr tokens-rear (cons token nil)))
(setq token nil))))
(when root
(phpinspect-pctx-register-token context tokens root-start (point)))
(defun phpinspect-make-incremental-parser-function (name tree-type handlers &optional delimiter-predicate)
"Like `phpinspect-make-parser-function', but returned function
is able to reuse an already parsed tree."
(let ((delimiter-predicate (if (symbolp delimiter-predicate)
`(quote ,delimiter-predicate)
delimiter-predicate)))
`(defsubst ,(phpinspect-parser-func-name name "incremental") (context buffer max-point &optional skip-over continue-condition root)
(with-current-buffer buffer
(let* ((tokens (cons ,tree-type nil))
(tokens-rear tokens)
(root-start (point))
(bmap (phpinspect-pctx-bmap context))
(previous-bmap (phpinspect-pctx-previous-bmap context))
(edtrack (phpinspect-pctx-edtrack context))
(taint-iterator (when edtrack (phpinspect-edtrack-make-taint-iterator edtrack)))
(check-interrupt (phpinspect-pctx-interrupt-predicate context))
;; Loop variables
(start-position)
(original-position)
(current-end-position)
(existing-meta)
(delta)
(token)
(delimiter-predicate (when (functionp ,delimiter-predicate) ,delimiter-predicate)))
(when skip-over (forward-char skip-over))
(phpinspect-pctx-save-whitespace context
(while (and (< (point) max-point)
(if continue-condition (funcall continue-condition) t)
(not (if delimiter-predicate
(funcall delimiter-predicate (car (last tokens)))
nil)))
(when check-interrupt
(phpinspect-pctx-check-interrupt context))
(setq start-position (point))
(cond ((and previous-bmap edtrack
(setq existing-meta
(phpinspect-bmap-token-starting-at
previous-bmap
(setq original-position
(phpinspect-edtrack-original-position-at-point edtrack start-position))))
(not (or (phpinspect-root-p (phpinspect-meta-token existing-meta))
(phpinspect-taint-iterator-token-is-tainted-p taint-iterator existing-meta))))
(setq delta (- start-position original-position)
current-end-position (+ (phpinspect-meta-end existing-meta) delta)
token (phpinspect-meta-token existing-meta))
;;(message "Reusing token %s at point %s" (phpinspect-meta-string existing-meta) (point))
;; Re-register existing token
(phpinspect-bmap-overlay
bmap previous-bmap existing-meta delta
(phpinspect-pctx-consume-whitespace context))
(goto-char current-end-position)
;; Skip over whitespace after so that we don't do a full
;; run down all of the handlers during the next iteration
(when (looking-at (phpinspect-handler-regexp whitespace))
(,(phpinspect-handler-func-name 'whitespace) (match-string 0))))
,@(mapcar
(lambda (handler)
`((looking-at (,(phpinspect-handler-regexp-func-name handler)))
(setq token (,(phpinspect-handler-func-name handler) (match-string 0) max-point))
(when token
(phpinspect-pctx-register-token context token start-position (point)))))
handlers)
(t (forward-char)))
(when token
(setq tokens-rear (setcdr tokens-rear (cons token nil)))
(setq token nil))))
(when root
(phpinspect-pctx-register-token context tokens root-start (point)))
;; Return
tokens)))))
;; Return
tokens))))
(cl-defstruct (phpinspect-parser (:constructor phpinspect-make-parser))
(name 'root
@ -475,21 +469,21 @@ nature like argument lists"
(cond ((string= annotation-name "var")
;; The @var annotation accepts 2 parameters:
;; the type and the $variable name
(append (list :var-annotation)
(phpinspect--parse-annotation-parameters 2)))
(cons :var-annotation
(phpinspect--parse-annotation-parameters 2)))
((string= annotation-name "return")
;; The @return annotation only accepts 1 word as parameter:
;; The return type
(append (list :return-annotation)
(phpinspect--parse-annotation-parameters 1)))
(cons :return-annotation
(phpinspect--parse-annotation-parameters 1)))
((string= annotation-name "param")
;; The @param annotation accepts 2 parameters:
;; The type of the param, and the param's $name
(append (list :param-annotation)
(phpinspect--parse-annotation-parameters 2)))
(cons :param-annotation
(phpinspect--parse-annotation-parameters 2)))
((string= annotation-name "method")
(append (list :method-annotation)
(phpinspect--parse-annotation-parameters 3)))
(cons :method-annotation
(phpinspect--parse-annotation-parameters 3)))
(t
(list :annotation annotation-name))))
(list :annotation nil)))

@ -258,9 +258,10 @@ directories."
(pcase key
(:into
(let ((parameters)
(name)
(construct-params))
(let* ((construct-params (cons nil nil))
(cons-params-rear construct-params)
parameters name)
(if (listp value)
(progn
(setq name (car value)
@ -275,8 +276,9 @@ directories."
(setq key (pop parameters)
value (pop parameters))
(setq key (intern (string-replace ":with-" ":" (symbol-name key))))
(setq construct-params (nconc construct-params (list key value)))))
(push (apply #'phpinspect--make-pipeline-step `(,@construct-params :name ,name))
(setq cons-params-rear
(setcdr cons-params-rear (cons key (cons value nil))))))
(push (apply #'phpinspect--make-pipeline-step `(,@(cdr construct-params) :name ,name))
steps)))
(_ (error "unexpected key %s" key))))

@ -279,23 +279,20 @@ apeared to be a little more performant than using `let'."
nil)))
(defmacro phpinspect-splayt-traverse (place-and-splayt &rest body)
"Traverse splay tree in cadr of PLACE-AND-SPLAYT, executing BODY.
"Traverse SPLAYT, executing BODY.
The car of PLACE-AND-SPLAYT is assigned the value of each node.
The PLACE is assigned the value of each node.
Traversal is breadth-first to take advantage of the splay trees
Traversal is breadth-first to take advantage of the splay trees'
main benefit: the most accessed interval of keys is likely to be
near the top of the tee."
near the top of the tee.
(fn (PLACE SPLAYT) BODY...)"
(declare (indent 1))
(let* ((current (gensym))
(code `(phpinspect-splayt-node-traverse
(,current (phpinspect-splayt-root-node ,(cadr place-and-splayt)))
(setf ,(car place-and-splayt) (phpinspect-splayt-node-value ,current))
,@body)))
(if (symbolp (car place-and-splayt))
`(let (,(car place-and-splayt))
,code)
code)))
`(phpinspect-splayt-node-traverse
(,(car place-and-splayt) (phpinspect-splayt-root-node ,(cadr place-and-splayt)))
(setf ,(car place-and-splayt) (phpinspect-splayt-node-value ,(car place-and-splayt)))
,@body))
(defmacro phpinspect-splayt-node-traverse-lr (place-and-node &rest body)
(declare (indent 1))
@ -316,21 +313,16 @@ near the top of the tee."
(setq ,current (phpinspect-splayt-node-right ,current)))))))
(defmacro phpinspect-splayt-traverse-lr (place-and-splayt &rest body)
"Traverse splay tree depth-first from left to right,executing BODY.
"Traverse SPLAYT depth-first from left to right,executing BODY.
The car of PLACE-AND-SPLAYT is assigned the value of each node.
The cadr of PLACE-AND-SPLAYT is expected to be a splay tree."
(declare (indent 1))
(let* ((current (gensym))
(code `(phpinspect-splayt-node-traverse-lr
(,current (phpinspect-splayt-root-node ,(cadr place-and-splayt)))
(setf ,(car place-and-splayt) (phpinspect-splayt-node-value ,current))
,@body)))
(if (symbolp (car place-and-splayt))
`(let (,(car place-and-splayt))
,code)
code)))
The PLACE is assigned the value of each node.
(fn (PLACE SPLAYT) BODY...)"
(declare (indent 1))
`(phpinspect-splayt-node-traverse-lr
(,(car place-and-splayt) (phpinspect-splayt-root-node ,(cadr place-and-splayt)))
(setf ,(car place-and-splayt) (phpinspect-splayt-node-value ,(car place-and-splayt)))
,@body))
(define-inline phpinspect-splayt-node-key-less-p (node key)
(inline-quote (> ,key (phpinspect-splayt-node-key ,node))))

@ -51,7 +51,8 @@ PHP. Used to optimize string comparison.")
(inline-quote
(progn
(add-to-list 'phpinspect-log-groups (cons (or load-file-name buffer-file-name) ,group) nil #'equal))))
(add-to-list 'phpinspect-log-groups
(cons (macroexp-file-name) ,group)))))
(defun phpinspect-log-group-enabled-p (group)
(seq-find (lambda (cons)
@ -61,7 +62,8 @@ PHP. Used to optimize string comparison.")
(phpinspect--declare-log-group 'bam)
(defmacro phpinspect--log (&rest args)
(let ((log-group (alist-get (or load-file-name buffer-file-name) phpinspect-log-groups nil nil #'string=)))
(let ((log-group (alist-get (macroexp-file-name)
phpinspect-log-groups nil nil #'string=)))
`(when (and phpinspect--debug
(or (not phpinspect-enabled-log-groups)
,(when log-group
@ -77,7 +79,8 @@ PHP. Used to optimize string comparison.")
(defun phpinspect-filter-logs (group-name)
(interactive (list (completing-read "Log group: "
(mapcar (lambda (g) (symbol-name (cdr g)))
phpinspect-log-groups) nil t)))
phpinspect-log-groups)
nil t)))
(add-to-list 'phpinspect-enabled-log-groups (intern group-name)))
(defun phpinspect-unfilter-logs ()

@ -173,57 +173,57 @@ Example configuration if you already have a completion
UI (Company, Corfu) setup that can take advantage of completion
at point (capf) functions:
(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)
(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)
;; 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))
;; Enable phpinspect-mode
(phpinspect-mode))
(add-hook 'php-mode-hook #'my-php-personal-hook)
(add-hook \\='php-mode-hook #\\='my-php-personal-hook)
Example configuration for `company-mode':
(defun my-php-personal-hook ()
;; Assuming you already have company-mode enabled, these settings
;; add some IDE-like flair to it. This is of course not required, do
;; with it what you like.
(setq-local company-minimum-prefix-length 0)
(setq-local company-tooltip-align-annotations t)
(setq-local company-idle-delay 0.1)
(defun my-php-personal-hook ()
;; Assuming you already have company-mode enabled, these settings
;; add some IDE-like flair to it. This is of course not required, do
;; with it what you like.
(setq-local company-minimum-prefix-length 0)
(setq-local company-tooltip-align-annotations t)
(setq-local company-idle-delay 0.1)
;; If you don't have company-mode enabled by default, uncomment this line:
;; (company-mode)
;; If you don't have company-mode enabled by default, uncomment this line:
;; (company-mode)
;; By default, phpinspect-mode adds itself as a backend to
;; the `company-backends' of the current buffer. You can completely
;; disable all other backends with the statement below.
(setq-local company-backends '(phpinspect-company-backend))
;; By default, phpinspect-mode adds itself as a backend to
;; the `company-backends' of the current buffer. You can completely
;; disable all other backends with the statement below.
(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)
;; 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)
;; 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))
;; Enable phpinspect-mode
(phpinspect-mode))
(add-hook 'php-mode-hook #'my-php-personal-hook)
(add-hook \\='php-mode-hook #\\='my-php-personal-hook)
;; End example configuration."
;; End example configuration."
:after-hook (phpinspect--mode-function))
(defun phpinspect--suggest-at-point ()

@ -11,18 +11,12 @@
(phpinspect-purge-cache)
(defvar phpinspect-test-directory
(file-name-directory
(or load-file-name
buffer-file-name))
(file-name-directory (macroexp-file-name))
"Directory that phpinspect tests reside in.")
(defvar phpinspect-test-php-file-directory
(concat
(file-name-directory
(or load-file-name
buffer-file-name))
"/fixtures")
(expand-file-name "fixtures" phpinspect-test-directory)
"Directory with syntax trees of example PHP files.")
(defun phpinspect-test-read-fixture-data (name)
@ -33,7 +27,7 @@
(defun phpinspect-test-read-fixture-serialization (name)
(with-temp-buffer
(insert-file-contents-literally (concat phpinspect-test-php-file-directory "/" name ".eld"))
(eval (read (current-buffer)))))
(eval (read (current-buffer)) t)))
(defun phpinspect-test-parse-fixture-code (name)
(phpinspect-parse-file

@ -27,8 +27,8 @@
(require 'phpinspect)
(require 'phpinspect-test-env
(concat (file-name-directory (or load-file-name buffer-file-name byte-compile-current-file))
"phpinspect-test-env.el"))
(expand-file-name "phpinspect-test-env.el"
(file-name-directory (macroexp-file-name))))
(ert-deftest phpinspect-get-variable-type-in-block ()
(let* ((code "class Foo { function a(\\Thing $baz) { $foo = new \\DateTime(); $bar = $foo; Whatever comes after don't matter.")
@ -514,6 +514,7 @@ class Thing
(load-file (concat phpinspect-test-directory "/test-splayt.el"))
(load-file (concat phpinspect-test-directory "/test-pipeline.el"))
(load-file (concat phpinspect-test-directory "/test-toc.el"))
(load-file (concat phpinspect-test-directory "/test-meta.el"))
(provide 'phpinspect-test)

@ -27,6 +27,7 @@
(require 'ert)
(require 'phpinspect-fs)
(require 'phpinspect-autoload)
(require 'phpinspect-resolvecontext)
(ert-deftest phpinspect-filename-to-typename ()
(should (eq (phpinspect-intern-name "\\Foo\\Bar") (phpinspect-filename-to-typename "src/" "src/Foo////////Bar.php")))
@ -35,13 +36,7 @@
(ert-deftest phpinspect-find-composer-json-files ()
(let* ((fs (phpinspect-make-virtual-fs))
(autoloader (phpinspect-make-autoloader
:fs fs
:project-root-resolver (lambda () "/root")
:file-indexer
(phpinspect-project-make-file-indexer
(phpinspect--make-project :root "/root" :fs fs)))))
(let* ((fs (phpinspect-make-virtual-fs)))
(phpinspect-virtual-fs-set-file fs
"/root/composer.json"
"{ \"autoload\": { \"psr-4\": {\"WoW\\\\Dwarves\\\\\": \"src/\"}}}")
@ -57,12 +52,13 @@
(let ((sorter (lambda (file1 file2) (string-lessp (cdr file1) (cdr file2)))))
(should (equal (sort '((vendor . "/root/vendor/apples/pears/composer.json")
(vendor . "/root/vendor/runescape/client/composer.json")
(local . "/root/composer.json"))
sorter)
(sort (phpinspect-find-composer-json-files fs "/root")
sorter))))))
(should (equal (sort (copy-sequence
'((vendor . "/root/vendor/apples/pears/composer.json")
(vendor . "/root/vendor/runescape/client/composer.json")
(local . "/root/composer.json")))
sorter)
(sort (phpinspect-find-composer-json-files fs "/root")
sorter))))))
(ert-deftest phpinspect-autoload-composer-json-iterator ()
(let* ((fs (phpinspect-make-virtual-fs))

@ -1,3 +1,4 @@
;; -*- lexical-binding: t; -*-
(require 'phpinspect-bmap)
@ -6,7 +7,6 @@
(bmap2 (phpinspect-make-bmap))
(bmap3 (phpinspect-make-bmap))
(token '(:token))
(token1 '(:token1))
(token2 '(:token2))
(token3 '(:token3)))
@ -69,13 +69,15 @@
(phpinspect-bmap-register bmap 9 20 '(:node3))
(phpinspect-bmap-register bmap 21 44 '(:node4))
(setq result (phpinspect-bmap-tokens-overlapping bmap 22))
(should (equal '((:node4) (:node2) (:node1)) (mapcar #'phpinspect-meta-token result)))))
(let ((result (phpinspect-bmap-tokens-overlapping bmap 22)))
(should (equal '((:node4) (:node2) (:node1))
(mapcar #'phpinspect-meta-token result))))))
(ert-deftest phpinspect-bmap-tokens-overlapping-overlayed ()
(let ((bmap (phpinspect-make-bmap))
(bmap2 (phpinspect-make-bmap))
(bmap3 (phpinspect-make-bmap)))
(bmap3 (phpinspect-make-bmap))
result)
(phpinspect-bmap-register bmap 9 200 '(:token1))
(phpinspect-bmap-register bmap 20 200 '(:token2))
(phpinspect-bmap-register bmap 9 20 '(:token3))

@ -27,12 +27,11 @@
(require 'phpinspect-parser)
(require 'phpinspect-buffer)
(require 'phpinspect-test-env
(concat (file-name-directory (or load-file-name buffer-file-name byte-compile-current-file))
"phpinspect-test-env.el"))
(expand-file-name "phpinspect-test-env.el"
(file-name-directory (macroexp-file-name))))
(ert-deftest phpinspect-buffer-region-lookups ()
(let* ((parsed)
(class))
(let* (parsed)
(with-temp-buffer
(insert-file-contents (concat phpinspect-test-php-file-directory "/NamespacedClass.php"))
(setq phpinspect-current-buffer
@ -54,12 +53,11 @@
(ert-deftest phpinspect-parse-buffer-no-current ()
"Confirm that the parser is still functional with
`phpinspect-current-buffer' unset."
(let*((buffer)
(parsed))
(with-temp-buffer
(should-not phpinspect-current-buffer)
(insert-file-contents (concat phpinspect-test-php-file-directory "/NamespacedClass.php"))
(setq parsed (phpinspect-parse-current-buffer)))
(let* ((parsed
(with-temp-buffer
(should-not phpinspect-current-buffer)
(insert-file-contents (expand-file-name "NamespacedClass.php" phpinspect-test-php-file-directory))
(phpinspect-parse-current-buffer))))
(should (cdr parsed))))

@ -106,8 +106,7 @@
(should-not (phpinspect-taint-iterator-region-is-tainted-p iterator 30 35))))
(ert-deftest phpinspect-edtrack-taint-overlapping-edits ()
(let ((track (phpinspect-make-edtrack))
iterator)
(let ((track (phpinspect-make-edtrack)))
(phpinspect-edtrack-register-edit track 10 20 5)
(should (equal (list (cons 10 15)) (phpinspect-edtrack-taint-pool track)))

@ -24,6 +24,13 @@
;;; Code:
(require 'ert)
(require 'phpinspect-index)
(require 'phpinspect-parse-context)
(require 'phpinspect-bmap)
(require 'phpinspect-parser)
(require 'phpinspect-test-env
(expand-file-name "phpinspect-test-env.el"
(file-name-directory (macroexp-file-name))))
(ert-deftest phpinspect-index-static-methods ()
(let* ((class-tokens
@ -92,8 +99,9 @@ return StaticThing::create(new ThingFactory())->makeThing((((new Potato())->anti
(should (equal
(mapcar #'phpinspect-intern-name
(sort
'("Cheese" "Bacon" "Ham" "Bagel" "Monkey" "ExtendedThing"
"StaticThing" "Thing" "ThingFactory" "Potato" "OtherThing")
(copy-sequence
'("Cheese" "Bacon" "Ham" "Bagel" "Monkey" "ExtendedThing"
"StaticThing" "Thing" "ThingFactory" "Potato" "OtherThing"))
#'string<))
(sort used-types (lambda (s1 s2) (string< (symbol-name s1) (symbol-name s2))))))))
@ -111,7 +119,7 @@ return StaticThing::create(new ThingFactory())->makeThing((((new Potato())->anti
("Request" "Response")))))
(dolist (set blocks)
(let ((result (phpinspect--find-used-types-in-tokens (car set))))
(should (equal (cadr set) result))))))
(should (equal (sort (copy-sequence (cadr set)) #'string-lessp) (sort result #'string-lessp)))))))
(ert-deftest phpinspect-index-method-annotations ()
(let* ((result (phpinspect--index-tokens
@ -172,7 +180,7 @@ return StaticThing::create(new ThingFactory())->makeThing((((new Potato())->anti
(let* ((pctx (phpinspect-make-pctx :incremental t :bmap (phpinspect-make-bmap)))
(tree))
(with-temp-buffer
(insert-file-contents (concat phpinspect-test-php-file-directory "/IndexClass1.php"))
(insert-file-contents (expand-file-name "IndexClass1.php" phpinspect-test-php-file-directory))
(setf (phpinspect-pctx-bmap pctx) (phpinspect-make-bmap))
(phpinspect-with-parse-context pctx (setq tree (phpinspect-parse-current-buffer))))
(let* ((index1 (phpinspect--index-tokens tree

@ -40,28 +40,3 @@
(should (= 30 (phpinspect-meta-start meta)))
(should (phpinspect-meta-overlaps-point meta 30))))
(ert-deftest phpinspect-meta-iterator ()
(let* ((meta (phpinspect-make-meta nil 10 20 "" 'token))
(firstchild (phpinspect-make-meta nil 10 12 "" 'token))
(secondchild (phpinspect-make-meta nil 13 15 "" 'token))
(parent1 (phpinspect-make-meta nil 9 22 "" 'token))
(sibling (phpinspect-make-meta nil 30 55 "" 'token))
(parent2 (phpinspect-make-meta nil 0 100 "" 'token))
iterator)
(phpinspect-meta-set-parent meta parent1)
(phpinspect-meta-set-parent parent1 parent2)
(phpinspect-meta-set-parent sibling parent2)
(phpinspect-meta-set-parent firstchild meta)
(phpinspect-meta-set-parent secondchild meta)
(setq iterator (phpinspect-make-meta-iterator parent2))
(should (eq meta (phpinspect-meta-iterator-token-at-point iterator 10)))
(should (eq sibling (phpinspect-meta-iterator-token-at-point iterator 30)))
(should (eq meta (phpinspect-meta-iterator-token-at-point iterator 10)))
(should (eq firstchild (phpinspect-meta-iterator-token-at-point iterator 10)))
(should (eq secondchild (phpinspect-meta-iterator-token-at-point iterator 13)))
(should (eq meta (phpinspect-meta-iterator-token-at-point iterator 10)))
(should (eq firstchild (phpinspect-meta-iterator-token-at-point iterator 10)))
(should (eq sibling (phpinspect-meta-iterator-token-at-point iterator 30)))))

@ -26,6 +26,7 @@
(require 'ert)
(require 'phpinspect-parse-context)
(require 'phpinspect-meta)
(require 'phpinspect-bmap)
(ert-deftest phpinspect-pctx-cancel ()
(let ((meta (phpinspect-make-meta nil 10 20 " " 'token 'overlay nil))

@ -24,21 +24,10 @@
;;; Code:
(require 'phpinspect-parser)
(defvar phpinspect-test-directory
(file-name-directory
(or load-file-name
buffer-file-name))
"Directory that phpinspect tests reside in.")
(defvar phpinspect-test-php-file-directory
(concat
(file-name-directory
(or load-file-name
buffer-file-name))
"/fixtures")
"Directory with syntax trees of example PHP files.")
(require 'phpinspect-index)
(require 'phpinspect-test-env
(expand-file-name "phpinspect-test-env.el"
(file-name-directory (macroexp-file-name))))
(ert-deftest phpinspect-parse-bmap ()

@ -25,14 +25,15 @@
(require 'phpinspect-pipeline)
(defun phpinspect--correct-the-record (input)
(phpinspect-pipeline-emit
(format "It's not %s, but GNU/%s" input input)))
(ert-deftest phpinspect-pipeline ()
(let (result error thread)
(defun correct-the-record (input)
(phpinspect-pipeline-emit
(format "It's not %s, but GNU/%s" input input)))
(let (result error)
(phpinspect-pipeline (list "Linux" "Emacs")
:into correct-the-record
:into phpinspect--correct-the-record
:async (lambda (res err)
(setq result res
error err)))
@ -44,13 +45,14 @@
result))
(should-not error)))
(defun phpinspect--aah-it-broke (input)
(signal 'it-brokey input))
(ert-deftest phpinspect-pipeline-error ()
(defun aah-it-broke (input)
(signal 'it-brokey input))
(let (result error)
(phpinspect-pipeline (list "Holy smokey")
:into aah-it-broke
:into phpinspect--aah-it-broke
:async (lambda (res err)
(setq result res
error err)))
@ -60,5 +62,5 @@
(should error)
(should (equal '(phpinspect-pipeline-error
"Thread phpinspect-pipeline-aah-it-broke signaled error: (it-brokey . Holy smokey)")
"Thread phpinspect-pipeline-phpinspect--aah-it-broke signaled error: (it-brokey . Holy smokey)")
error))))

@ -35,11 +35,9 @@
(ert-deftest phpinspect-project-watch-file-and-purge ()
(let* ((root (make-temp-file "phpinspect-test" 'dir))
(fs (phpinspect-make-fs))
(worker (phpinspect-make-worker))
(watch-file (concat root "/watch1"))
(project (phpinspect--make-project :fs fs :root root)))
(phpinspect-project-watch-file project watch-file
(lambda (&rest ignored)))
(phpinspect-project-watch-file project watch-file #'ignore)
(phpinspect-project-purge project)

@ -1,5 +1,11 @@
;; -*- lexical-binding: t; -*-
(require 'phpinspect-resolvecontext)
(require 'phpinspect)
(require 'phpinspect-test-env
(expand-file-name "phpinspect-test-env.el"
(file-name-directory (macroexp-file-name))))
(ert-deftest phinspect-get-resolvecontext ()
(let* ((ctx (phpinspect-make-pctx :incremental t :bmap (phpinspect-make-bmap)))
@ -29,7 +35,7 @@ class TestClass {
(ert-deftest phpinspect-type-resolver-for-resolvecontext ()
(with-temp-buffer
(insert-file-contents (concat phpinspect-test-php-file-directory "/IncompleteClass.php"))
(insert-file-contents (expand-file-name "IncompleteClass.php" phpinspect-test-php-file-directory))
(let* ((bmap (phpinspect-parse-string-to-bmap (buffer-string)))
(resolvecontext (phpinspect-get-resolvecontext bmap (point-max)))
(type-resolver (phpinspect--make-type-resolver-for-resolvecontext
@ -80,10 +86,7 @@ class TestClass {
(funcall type-resolver (phpinspect--make-type :name "Dupuis\\GastonLagaffe")))))))
(ert-deftest phpinspect-type-resolver-for-resolvecontext-multiple-namespace-blocks ()
(with-temp-buffer
(insert-file-contents (concat phpinspect-test-php-file-directory "/IncompleteClassMultipleNamespaces.php"))
(let* ((bmap (phpinspect-parse-string-to-bmap (buffer-string)))
(resolvecontext (phpinspect--get-resolvecontext
(let* ((resolvecontext (phpinspect--get-resolvecontext
(phpinspect-test-read-fixture-data
"IncompleteClassMultipleNamespaces")))
(type-resolver (phpinspect--make-type-resolver-for-resolvecontext
@ -97,13 +100,13 @@ class TestClass {
(phpinspect--make-type :name "\\array"))))
(should (phpinspect--type= (phpinspect--make-type
:name "\\Symfony\\Component\\HttpFoundation\\Response")
(funcall type-resolver (phpinspect--make-type :name "Response"))))
(funcall type-resolver (phpinspect--make-type :name "Response"))))
(should (phpinspect--type= (phpinspect--make-type :name "\\Response")
(funcall type-resolver
(phpinspect--make-type :name "\\Response"))))
(should (phpinspect--type= (phpinspect--make-type :name "\\App\\Controller\\GastonLagaffe")
(funcall type-resolver (phpinspect--make-type :name "GastonLagaffe"))))
(funcall type-resolver (phpinspect--make-type :name "GastonLagaffe"))))
(should (phpinspect--type= (phpinspect--make-type
:name "\\App\\Controller\\Dupuis\\GastonLagaffe")
(funcall type-resolver (phpinspect--make-type
:name "Dupuis\\GastonLagaffe")))))))
:name "Dupuis\\GastonLagaffe"))))))

@ -71,7 +71,7 @@
(should (string= "twelve" (phpinspect-splayt-find tree 12)))
(should (string= "eleven" (phpinspect-splayt-find tree 11)))
(let ((expected (sort '("nine" "three" "eleven" "eight" "twelve" "four" "one") #'string-lessp))
(let ((expected (sort (copy-sequence '("nine" "three" "eleven" "eight" "twelve" "four" "one")) #'string-lessp))
(result))
(phpinspect-splayt-traverse (item tree)
@ -91,7 +91,7 @@
(phpinspect-splayt-insert tree 4 "four")
(phpinspect-splayt-insert tree 1 "one")
(let ((expected (sort '("nine" "three" "eleven" "eight" "twelve" "four" "one") #'string-lessp))
(let ((expected (sort (copy-sequence '("nine" "three" "eleven" "eight" "twelve" "four" "one")) #'string-lessp))
(result))
(phpinspect-splayt-traverse (item tree)
@ -161,7 +161,7 @@
(phpinspect-splayt-insert tree 1 "one")
(should (equal (sort '("eight" "nine" "eleven" "twelve") #'string-lessp)
(should (equal (sort (copy-sequence '("eight" "nine" "eleven" "twelve")) #'string-lessp)
(sort (phpinspect-splayt-find-all-after tree 7) #'string-lessp)))))
(ert-deftest phpinspect-splayt-to-list ()

@ -2,6 +2,7 @@
(require 'phpinspect-toc)
(require 'phpinspect-splayt)
(require 'phpinspect-meta)
(ert-deftest phpinspect-make-toc ()
(let ((tokens (phpinspect-make-splayt))

@ -23,6 +23,8 @@
;;; Code:
(require 'phpinspect-type)
(ert-deftest phpinspect--resolve-late-static-binding ()
(let* ((sets '(("\\bool" . "\\bool")
("\\static" . "\\AType")

@ -23,6 +23,8 @@
;;; Code:
(require 'phpinspect-util)
(ert-deftest phpinspect--pattern ()
(let* ((a "a")
(pattern1 (phpinspect--make-pattern :m `(,a) :m * :m "b"))

@ -3,12 +3,10 @@
(require 'phpinspect-index)
(require 'phpinspect-serialize)
(let ((here (file-name-directory
(or load-file-name
buffer-file-name)))
(let ((here (file-name-directory (macroexp-file-name)))
(print-length 1000)
(print-level 1000))
(dolist (file (directory-files (concat here "/../fixtures" ) t "\\.php\\'"))
(dolist (file (directory-files (expand-file-name "../fixtures" here) t "\\.php\\'"))
(with-temp-buffer
(insert-file-contents-literally file)
(let ((result (phpinspect-parse-current-buffer)))

Loading…
Cancel
Save