Cleanup suggest-attribute scoping code

master
Hugo Thunnissen 1 month ago
parent f84327523b
commit afb9a9e4ed

@ -111,13 +111,6 @@
(cl-defmethod phpinspect--candidate-scope ((candidate phpinspect--variable)) (cl-defmethod phpinspect--candidate-scope ((candidate phpinspect--variable))
(phpinspect--variable-scope candidate)) (phpinspect--variable-scope candidate))
(cl-defmethod phpinspect--candiate-inherited ((candidate phpinspect--function))
(phpinspect--function--inherited candidate))
;; FIXME: when inheriting of variables is implemented
(cl-defmethod phpinspect--candidate-inherited ((_candidate phpinspect--variable))
nil)
(defun phpinspect-suggest-attributes-at-point (defun phpinspect-suggest-attributes-at-point
(resolvecontext &optional static) (resolvecontext &optional static)
"Suggest object or class attributes at point. "Suggest object or class attributes at point.
@ -151,8 +144,7 @@ static variables and static methods."
static)) static))
(statement-type (phpinspect-resolve-type-from-context (statement-type (phpinspect-resolve-type-from-context
resolvecontext resolvecontext
type-resolver)) type-resolver)))
enclosing-class-name)
(phpinspect--log "Statement type: %s" statement-type) (phpinspect--log "Statement type: %s" statement-type)
(when statement-type (when statement-type
@ -163,20 +155,20 @@ static variables and static methods."
(funcall method-lister type)))) (funcall method-lister type))))
;; Filter out candidates according to scoping rules ;; Filter out candidates according to scoping rules
(when (and enclosing-class (if-let ((enclosing-class-name
(setq enclosing-class-name (and enclosing-class
(phpinspect--get-class-name-from-token enclosing-class))) (phpinspect--get-class-name-from-token enclosing-class)))
(let* ((enclosing-type (funcall type-resolver (phpinspect--make-type :name enclosing-class-name))) (enclosing-type (funcall type-resolver (phpinspect--make-type :name enclosing-class-name)))
(allow-protected (phpinspect--type= type enclosing-type)) ((phpinspect--type= type enclosing-type)))
filtered-result) ;; We're inside the class being completed. Return all possible
;; attributes as scoping doesn't matter.
result
;; We're outside the class being completed. Return only public
;; attributes.
(let (filtered)
(dolist (candidate result) (dolist (candidate result)
(if allow-protected (when (phpinspect-public-p (phpinspect--candidate-scope candidate))
(push candidate filtered-result) (push candidate filtered)))
(when (phpinspect-public-p (phpinspect--candidate-scope candidate)) filtered))))))
(push candidate filtered-result))))
(setq result filtered-result))
(phpinspect--log "Returning attributes %s" result)
result)))))
(provide 'phpinspect-suggest) (provide 'phpinspect-suggest)

Loading…
Cancel
Save