branch: externals/phpinspect commit db370623daea5511cc2c842740c4b80291f695e2 Author: Hugo Thunnissen <de...@hugot.nl> Commit: Hugo Thunnissen <de...@hugot.nl>
Implement "files" autoload strategy --- phpinspect-autoload.el | 41 ++++++++++++++++++++++++++++------------- phpinspect-project.el | 5 ++++- test/test-autoload.el | 15 ++++++++++++--- 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/phpinspect-autoload.el b/phpinspect-autoload.el index 55ff853490..6ea4c478bd 100644 --- a/phpinspect-autoload.el +++ b/phpinspect-autoload.el @@ -61,6 +61,13 @@ :documentation "The directories that this autoloader finds code in.")) +(cl-defstruct (phpinspect-files (:constructor phpinspect-make-files)) + (autoloader nil) + (list nil + :type list + :documentation + "List of files to be indexed")) + (cl-defstruct (phpinspect-autoloader (:constructor phpinspect-make-autoloader)) (project nil @@ -81,14 +88,6 @@ qualified names congruent with a bareword type name. Keyed by bareword typenames.")) -(cl-defstruct (phpinspect-cj-iter-ctx (:constructor phpinspect-make-cj-iter-ctx)) - (autoloader nil - :type phpinspect-autoloader) - (compiled-dirs nil - :type boolean) - (dirs nil - :type list)) - (cl-defmethod phpinspect--read-json-file (fs file) (with-temp-buffer (phpinspect-fs-insert-file-contents fs file) @@ -157,6 +156,14 @@ bareword typenames.")) (when own (puthash type-fqn file own-typehash)))))) +(phpinspect-define-pipeline-step phpinspect-project-add-file-index phpinspect-project-add-file-index) + +(cl-defmethod phpinspect-al-strategy-execute ((strat phpinspect-files)) + (phpinspect--log "indexing files list: %s" (phpinspect-files-list strat)) + (let* ((project (phpinspect-autoloader-project (phpinspect-files-autoloader strat)))) + (phpinspect-pipeline (phpinspect-files-list strat) + :into (phpinspect-project-add-file-index :with-context project)))) + (cl-defmethod phpinspect-autoloader-put-type-bag ((al phpinspect-autoloader) (type-fqn symbol)) (let* ((type-name (phpinspect-intern-name (car (last (split-string (symbol-name type-fqn) "\\\\"))))) @@ -190,7 +197,8 @@ bareword typenames.")) :own (eq 'local (car file)))) (dolist (path directory-paths) (push (file-name-concat project-root path) - (phpinspect-psr0-directories strategy)))) + (phpinspect-psr0-directories strategy))) + (push strategy batch)) prefixes)) ("psr-4" (maphash @@ -204,11 +212,18 @@ bareword typenames.")) :own (eq 'local (car file)))) (dolist (path directory-paths) (push (file-name-concat project-root path) - (phpinspect-psr4-directories strategy)))) + (phpinspect-psr4-directories strategy))) + (push strategy batch)) prefixes)) - (_ (phpinspect--log "Unsupported autoload strategy \"%s\" encountered" type))) - - (push strategy batch))) + ("files" + (setq strategy + (phpinspect-make-files + :list (mapcar + (lambda (file) (file-name-concat project-root file)) + prefixes) + :autoloader al)) + (push strategy batch)) + (_ (phpinspect--log "Unsupported autoload strategy \"%s\" encountered" type))))) autoload) (phpinspect-pipeline-emit-all batch)))) diff --git a/phpinspect-project.el b/phpinspect-project.el index 68312b21ac..b8797f13b7 100644 --- a/phpinspect-project.el +++ b/phpinspect-project.el @@ -83,7 +83,7 @@ can be accessed.") :documentation "The autoload object through which this project's type definitions can be retrieved") - (worker nil + (worker (phpinspect-make-dynamic-worker) :type phpinspect-worker :documentation "The worker that this project may queue tasks for") @@ -250,5 +250,8 @@ before the search is executed." (phpinspect-fs-insert-file-contents fs filename 'prefer-async) (phpinspect-index-current-buffer)))) +(cl-defmethod phpinspect-project-add-file-index ((project phpinspect-project) (filename string)) + (phpinspect-project-add-index project (phpinspect-project-index-file project filename))) + (provide 'phpinspect-project) ;;; phpinspect-project.el ends here diff --git a/test/test-autoload.el b/test/test-autoload.el index 7d9348b5cc..876f12add7 100644 --- a/test/test-autoload.el +++ b/test/test-autoload.el @@ -91,10 +91,12 @@ (ert-deftest phpinspect-al-strategy-execute () (let* ((fs (phpinspect-make-virtual-fs)) - (autoloader (phpinspect-make-autoloader - :project (phpinspect--make-project :root "/project/root" :fs fs))) + (project (phpinspect--make-project :root "/project/root" :fs fs)) + (autoloader (phpinspect-make-autoloader :project project)) result error) + (setf (phpinspect-project-autoload project) autoloader) + (phpinspect-virtual-fs-set-file fs "/project/root/composer.json" @@ -121,7 +123,12 @@ (phpinspect-virtual-fs-set-file fs "/project/root/vendor/not-runescape/wow/composer.json" - "{ \"autoload\": { \"psr-4\": {\"WoW\\\\Dwarves\\\\\": \"src/\"}}}") + "{ \"autoload\": { \"psr-4\": {\"WoW\\\\Dwarves\\\\\": \"src/\"}, + \"files\": [ \"include/FilesList.php\"]}}") + + (phpinspect-virtual-fs-set-file fs + "/project/root/vendor/not-runescape/wow/include/FilesList.php" + "<?php class FilesList { function list() {} }") (phpinspect-virtual-fs-set-file fs "/project/root/vendor/not-runescape/wow/src/TestClass.php" "") @@ -141,6 +148,8 @@ (should-not (hash-table-empty-p (phpinspect-autoloader-own-types autoloader))) (should-not (hash-table-empty-p (phpinspect-autoloader-types autoloader))) + (should (phpinspect-project-get-class project (phpinspect--make-type :name "\\FilesList"))) + (should (string= "/project/root/vendor/runescape/client/src/Runescape/Banana/App.php" (phpinspect-autoloader-resolve autoloader