Implement indexation of readonly variables + allow invalid keywords

readonly variables no longer result in a failed indexation.

When we fail matching the scope keywords + variable patterns, only the variable
name is indexed instead of throwing an error.
master
Hugo Thunnissen 1 month ago
parent 2fcb326747
commit 3887bc58d4

@ -179,32 +179,40 @@ function (think \"new\" statements, return types etc.)."
Provide STATIC if the variable was defined as static. Provide STATIC if the variable was defined as static.
SCOPE should be a scope token (`phpinspect-scope-p')." SCOPE should be a scope token (`phpinspect-scope-p')."
(setq scope (take 5 (seq-filter #'phpinspect-not-comment-p scope))) (let (readonly)
(let (variable-name type) (when (and (phpinspect-word-p (cadr scope))
(cond (equal (cadr scope) `(:word "readonly")))
((phpinspect--match-sequence (take 3 scope) (setq readonly t)
;; Sequence: scope-type, typehint, variable [ = value ] (setcdr scope (cddr scope)))
:m * :f #'phpinspect-word-p :f #'phpinspect-variable-p)
(setq variable-name (cadr (nth 2 scope))) (setq scope (take 5 (seq-filter #'phpinspect-not-comment-p scope)))
(setq type (cadr (nth 1 scope)))) (let (variable-name type)
((phpinspect--match-sequence (take 2 scope) (cond
;; Sequence: variable [ = value ] ((phpinspect--match-sequence (take 3 scope)
:m * :f #'phpinspect-variable-p) ;; Sequence: scope-type, typehint, variable [ = value ]
(setq variable-name (cadr (nth 1 scope)) :m * :f #'phpinspect-word-p :f #'phpinspect-variable-p)
;; Since no typehint is available, attempt extracting one from a (setq variable-name (cadr (nth 2 scope)))
;; docstring. (setq type (cadr (nth 1 scope))))
type (phpinspect--variable-type-string-from-comment ((phpinspect--match-sequence (take 2 scope)
comment-before variable-name))) ;; Sequence: variable [ = value ]
(t (error (format "Failed to determine variable from scope %s" scope)))) :m * :f #'phpinspect-variable-p)
(setq variable-name (cadr (nth 1 scope))
(phpinspect--log "calling resolver from index-variable-from-scope") ;; Since no typehint is available, attempt extracting one from a
(phpinspect--make-variable ;; docstring.
;; Static class variables are always prefixed with dollar signs when type (phpinspect--variable-type-string-from-comment
;; referenced. comment-before variable-name)))
:name (if static (concat "$" variable-name) variable-name) (t
:scope `(,(car scope)) (setq variable-name (cadr (seq-find #'phpinspect-variable-p scope)))))
:lifetime (when static '(:static))
:type (if type (funcall type-resolver (phpinspect--make-type :name type)))))) (phpinspect--log "calling resolver from index-variable-from-scope")
(phpinspect--make-variable
;; Static class variables are always prefixed with dollar signs when
;; referenced.
:readonly readonly
:name (if static (concat "$" variable-name) variable-name)
:scope `(,(car scope))
:lifetime (when static '(:static))
:type (if type (funcall type-resolver (phpinspect--make-type :name type)))))))
(defun phpinspect-doc-block-p (token) (defun phpinspect-doc-block-p (token)
(phpinspect-token-type-p token :doc-block)) (phpinspect-token-type-p token :doc-block))

Loading…
Cancel
Save