diff --git a/phpinspect-index.el b/phpinspect-index.el index de032a2..780fc1b 100644 --- a/phpinspect-index.el +++ b/phpinspect-index.el @@ -544,18 +544,29 @@ NAMESPACE will be assumed the root namespace if not provided" namespaces type-resolver-factory location-resolver indexed)) indexed)) -(defun phpinspect--index-functions-in-tokens (tokens type-resolver-factory &optional imports namespace add-used-types) + + +(defun phpinspect--index-functions-in-tokens + (tokens type-resolver-factory &optional imports namespace add-used-types type-resolver) "Index functions in TOKENS." - (let ((type-resolver (funcall type-resolver-factory imports nil namespace)) - comment-before functions) + (setq type-resolver (or type-resolver (funcall type-resolver-factory imports nil namespace))) + (let (comment-before functions function) (dolist (token tokens) (cond ((phpinspect-comment-p token) (setq comment-before token)) ((phpinspect-function-p token) - (push (phpinspect--index-function-from-scope - type-resolver `(:public ,token) comment-before add-used-types - namespace) - functions)))) + (setq function (phpinspect--index-function-from-scope + type-resolver `(:public ,token) comment-before add-used-types + namespace)) + (unless (phpinspect--function-anonyous-p function) + (push function functions))) + ((phpinspect-block-or-list-p token) + (dolist (fn (phpinspect--index-functions-in-tokens + (cdr token) type-resolver-factory imports namespace + add-used-types type-resolver)) + (unless (phpinspect--function-anonyous-p fn) + (push fn functions)))))) + functions)) (defun phpinspect-function-declaration (function-token) diff --git a/phpinspect-resolve.el b/phpinspect-resolve.el index 3af2a33..40428e3 100644 --- a/phpinspect-resolve.el +++ b/phpinspect-resolve.el @@ -43,10 +43,6 @@ :type phpinspect-token :documentation "The token that is assigned from")) -(defsubst phpinspect-block-or-list-p (token) - (or (phpinspect-block-p token) - (phpinspect-list-p token))) - (defsubst phpinspect-maybe-assignment-p (token) "Like `phpinspect-assignment-p', but includes \"as\" barewords as possible tokens." (or (phpinspect-assignment-p token) diff --git a/phpinspect-token-predicates.el b/phpinspect-token-predicates.el index 7c68103..b27e5d8 100644 --- a/phpinspect-token-predicates.el +++ b/phpinspect-token-predicates.el @@ -128,6 +128,10 @@ Type can be any of the token types returned by (or (phpinspect-token-type-p token :list) (phpinspect-incomplete-list-p token))) +(defsubst phpinspect-block-or-list-p (token) + (or (phpinspect-block-p token) + (phpinspect-list-p token))) + (define-inline phpinspect-declaration-p (token) (inline-quote (phpinspect-token-type-p ,token :declaration))) @@ -261,5 +265,4 @@ Type can be any of the token types returned by (inline-quote (not (phpinspect-comment-p ,token)))) - (provide 'phpinspect-token-predicates) diff --git a/test/test-index.el b/test/test-index.el index 96c217e..f2d2a32 100644 --- a/test/test-index.el +++ b/test/test-index.el @@ -407,3 +407,29 @@ public function doStuff() (should method) (should (phpinspect--function-return-type method)) (should (phpinspect--type= type (phpinspect--function-return-type method)))))))) + +(ert-deftest phpinspect-index-nested-functions () + (with-temp-buffer + (let* ((code "