From 47335f345082b089d94769feb567f70bc75331cd Mon Sep 17 00:00:00 2001 From: Hugo Thunnissen Date: Sun, 2 Jul 2023 16:47:24 +0200 Subject: [PATCH] Refactor phpinspect--project to phpinspect-project --- phpinspect-autoload.el | 6 +-- phpinspect-cache.el | 2 +- phpinspect-class.el | 4 +- phpinspect-imports.el | 6 +-- phpinspect-index.el | 6 +-- phpinspect-project.el | 102 ++++++++++++++++++++-------------------- phpinspect-worker.el | 10 ++-- phpinspect.el | 34 +++++++------- test/phpinspect-test.el | 8 ++-- test/test-project.el | 10 ++-- 10 files changed, 94 insertions(+), 94 deletions(-) diff --git a/phpinspect-autoload.el b/phpinspect-autoload.el index fb921f3..d7b1fed 100644 --- a/phpinspect-autoload.el +++ b/phpinspect-autoload.el @@ -57,7 +57,7 @@ (cl-defstruct (phpinspect-autoloader (:constructor phpinspect-make-autoloader)) (project nil - :type phpinspect--project + :type phpinspect-project :documentation "The project that this autoloader can find files for") (own-types (make-hash-table :test 'eq :size 10000 :rehash-size 10000) :type hash-table @@ -111,8 +111,8 @@ bareword typenames.")) (cl-defmethod phpinspect-autoloader-refresh ((autoloader phpinspect-autoloader)) "Refresh autoload definitions by reading composer.json files from the project and vendor folders." - (let* ((project-root (phpinspect--project-root (phpinspect-autoloader-project autoloader))) - (fs (phpinspect--project-fs (phpinspect-autoloader-project autoloader))) + (let* ((project-root (phpinspect-project-root (phpinspect-autoloader-project autoloader))) + (fs (phpinspect-project-fs (phpinspect-autoloader-project autoloader))) (vendor-dir (concat project-root "/vendor")) (composer-json-path (concat project-root "/composer.json")) (composer-json) diff --git a/phpinspect-cache.el b/phpinspect-cache.el index b6f25e5..d9e37f7 100644 --- a/phpinspect-cache.el +++ b/phpinspect-cache.el @@ -55,7 +55,7 @@ then returned." :worker (phpinspect-make-dynamic-worker)) (phpinspect--cache-projects cache))) (let ((autoload (phpinspect-make-autoloader :project project))) - (setf (phpinspect--project-autoload project) autoload) + (setf (phpinspect-project-autoload project) autoload) (phpinspect-autoloader-refresh autoload))) project)) diff --git a/phpinspect-class.el b/phpinspect-class.el index ff31ee1..3fa10ab 100644 --- a/phpinspect-class.el +++ b/phpinspect-class.el @@ -27,7 +27,7 @@ (cl-defstruct (phpinspect--class (:constructor phpinspect--make-class-generated)) (project nil - :type phpinspect--project + :type phpinspect-project :documentaton "The project that this class belongs to") (index nil @@ -85,7 +85,7 @@ #'phpinspect--class-p (mapcar (lambda (class-name) - (phpinspect--project-get-class-create (phpinspect--class-project class) + (phpinspect-project-get-class-create (phpinspect--class-project class) class-name)) `(,@(alist-get 'implements index) ,@(alist-get 'extends index))))) diff --git a/phpinspect-imports.el b/phpinspect-imports.el index cff07ef..efcc4de 100644 --- a/phpinspect-imports.el +++ b/phpinspect-imports.el @@ -87,7 +87,7 @@ buffer position to insert the use statement at." (format "%c%cuse %s;%c%c" ?\n ?\n fqn ?\n ?\n)))))))) (defun phpinspect-add-use-interactive (typename buffer project &optional namespace-token) - (let* ((autoloader (phpinspect--project-autoload project)) + (let* ((autoloader (phpinspect-project-autoload project)) (fqn-bags (phpinspect-autoloader-type-name-fqn-bags autoloader))) (let ((fqns (gethash typename fqn-bags))) @@ -117,7 +117,7 @@ that there are import (\"use\") statements for them." (imports (alist-get 'imports index)) (project (phpinspect--cache-get-project-create (phpinspect--get-or-create-global-cache) - (phpinspect-project-root)))) + (phpinspect-current-project-root)))) (dolist (class classes) (let* ((class-imports (alist-get 'imports class)) (used-types (alist-get 'used-types class)) @@ -137,7 +137,7 @@ that there are import (\"use\") statements for them." "\\" (symbol-name type))) (phpinspect-autoloader-types - (phpinspect--project-autoload project)))) + (phpinspect-project-autoload project)))) (phpinspect-add-use-interactive type phpinspect-current-buffer project namespace) ;; Buffer has been modified by adding type, update tree + diff --git a/phpinspect-index.el b/phpinspect-index.el index ba23303..d6188fc 100644 --- a/phpinspect-index.el +++ b/phpinspect-index.el @@ -462,7 +462,7 @@ Return value is a list of the types that are \"newed\"." (let ((project (phpinspect--cache-get-project-create (phpinspect--get-or-create-global-cache) project-root))) - (phpinspect--project-get-class-create project class-fqn)))) + (phpinspect-project-get-class-create project class-fqn)))) (defun phpinspect--index-current-buffer () (phpinspect--index-tokens (phpinspect-parse-current-buffer))) @@ -471,11 +471,11 @@ Return value is a list of the types that are \"newed\"." "Index a PHP file for classes and the methods they have" (phpinspect--index-tokens (phpinspect-parse-current-buffer))) -(cl-defmethod phpinspect--index-type-file ((project phpinspect--project) +(cl-defmethod phpinspect--index-type-file ((project phpinspect-project) (type phpinspect--type)) (condition-case error (let* ((class-file (with-temp-buffer - (cd (phpinspect--project-root project)) + (cd (phpinspect-project-root project)) (phpinspect-type-filepath type))) (visited-buffer (when class-file (find-buffer-visiting class-file))) (new-index) diff --git a/phpinspect-project.el b/phpinspect-project.el index c1cadcc..030116b 100644 --- a/phpinspect-project.el +++ b/phpinspect-project.el @@ -28,7 +28,7 @@ (require 'phpinspect-fs) (require 'filenotify) -(cl-defstruct (phpinspect--project (:constructor phpinspect--make-project)) +(cl-defstruct (phpinspect-project (:constructor phpinspect--make-project)) (class-index (make-hash-table :test 'eq :size 100 :rehash-size 40) :type hash-table :documentation @@ -61,115 +61,115 @@ Projects get purged when they are removed from the global cache.") :documentation "All active file watchers in this project, indexed by the absolute paths of the files they're watching.")) -(cl-defgeneric phpinspect--project-add-class - ((project phpinspect--project) (class (head phpinspect--indexed-class))) +(cl-defgeneric phpinspect-project-add-class + ((project phpinspect-project) (class (head phpinspect--indexed-class))) "Add an indexed CLASS to PROJECT.") -(cl-defmethod phpinspect--project-purge ((project phpinspect--project)) +(cl-defmethod phpinspect-project-purge ((project phpinspect-project)) "Disable all background processes for project and put it in a `purged` state." (maphash (lambda (_ watcher) (file-notify-rm-watch watcher)) - (phpinspect--project-file-watchers project)) + (phpinspect-project-file-watchers project)) - (setf (phpinspect--project-file-watchers project) + (setf (phpinspect-project-file-watchers project) (make-hash-table :test #'equal :size 10000 :rehash-size 10000)) - (setf (phpinspect--project-purged project) t)) + (setf (phpinspect-project-purged project) t)) -(cl-defmethod phpinspect--project-watch-file ((project phpinspect--project) +(cl-defmethod phpinspect-project-watch-file ((project phpinspect-project) filepath callback) (let ((watcher (file-notify-add-watch filepath '(change) callback))) - (puthash filepath watcher (phpinspect--project-file-watchers project)))) + (puthash filepath watcher (phpinspect-project-file-watchers project)))) -(cl-defmethod phpinspect--project-add-return-types-to-index-queueue - ((project phpinspect--project) methods) +(cl-defmethod phpinspect-project-add-return-types-to-index-queueue + ((project phpinspect-project) methods) (dolist (method methods) (when (phpinspect--function-return-type method) - (phpinspect--project-enqueue-if-not-present + (phpinspect-project-enqueue-if-not-present project (phpinspect--function-return-type method))))) -(cl-defmethod phpinspect--project-add-variable-types-to-index-queue - ((project phpinspect--project) variables) +(cl-defmethod phpinspect-project-add-variable-types-to-index-queue + ((project phpinspect-project) variables) (dolist (var variables) (when (phpinspect--variable-type var) - (phpinspect--project-enqueue-if-not-present project (phpinspect--variable-type var))))) + (phpinspect-project-enqueue-if-not-present project (phpinspect--variable-type var))))) -(cl-defmethod phpinspect--project-enqueue-if-not-present - ((project phpinspect--project) (type phpinspect--type)) +(cl-defmethod phpinspect-project-enqueue-if-not-present + ((project phpinspect-project) (type phpinspect--type)) (unless (phpinspect--type-is-native type) - (let ((class (phpinspect--project-get-class project type))) + (let ((class (phpinspect-project-get-class project type))) (when (or (not class) (not (or (phpinspect--class-initial-index class)))) (when (not class) - (setq class (phpinspect--project-create-class project type))) + (setq class (phpinspect-project-create-class project type))) (phpinspect--log "Adding unpresent class %s to index queue" type) - (phpinspect-worker-enqueue (phpinspect--project-worker project) + (phpinspect-worker-enqueue (phpinspect-project-worker project) (phpinspect-make-index-task project type)))))) -(cl-defmethod phpinspect--project-add-class-attribute-types-to-index-queue - ((project phpinspect--project) (class phpinspect--class)) - (phpinspect--project-add-return-types-to-index-queueue +(cl-defmethod phpinspect-project-add-class-attribute-types-to-index-queue + ((project phpinspect-project) (class phpinspect--class)) + (phpinspect-project-add-return-types-to-index-queueue project (phpinspect--class-get-method-list class)) - (phpinspect--project-add-return-types-to-index-queueue + (phpinspect-project-add-return-types-to-index-queueue project (phpinspect--class-get-static-method-list class)) - (phpinspect--project-add-variable-types-to-index-queue + (phpinspect-project-add-variable-types-to-index-queue project (phpinspect--class-variables class))) -(cl-defmethod phpinspect--project-add-index - ((project phpinspect--project) (index (head phpinspect--root-index))) +(cl-defmethod phpinspect-project-add-index + ((project phpinspect-project) (index (head phpinspect--root-index))) (dolist (indexed-class (alist-get 'classes (cdr index))) - (phpinspect--project-add-class project (cdr indexed-class)))) + (phpinspect-project-add-class project (cdr indexed-class)))) -(cl-defmethod phpinspect--project-enqueue-imports - ((project phpinspect--project) imports) +(cl-defmethod phpinspect-project-enqueue-imports + ((project phpinspect-project) imports) (dolist (import imports) (when import (phpinspect--log "Adding import to index queue: %s" import) - (phpinspect--project-enqueue-if-not-present project (cdr import))))) + (phpinspect-project-enqueue-if-not-present project (cdr import))))) -(cl-defmethod phpinspect--project-add-class - ((project phpinspect--project) (indexed-class (head phpinspect--indexed-class))) +(cl-defmethod phpinspect-project-add-class + ((project phpinspect-project) (indexed-class (head phpinspect--indexed-class))) (let* ((class-name (phpinspect--type-name-symbol (alist-get 'class-name (cdr indexed-class)))) (class (gethash class-name - (phpinspect--project-class-index project)))) + (phpinspect-project-class-index project)))) (unless class (setq class (phpinspect--make-class-generated :project project))) (phpinspect--class-set-index class indexed-class) - (puthash class-name class (phpinspect--project-class-index project)) - (phpinspect--project-add-class-attribute-types-to-index-queue project class))) + (puthash class-name class (phpinspect-project-class-index project)) + (phpinspect-project-add-class-attribute-types-to-index-queue project class))) -(cl-defmethod phpinspect--project-set-class - ((project phpinspect--project) (class-fqn phpinspect--type) (class phpinspect--class)) +(cl-defmethod phpinspect-project-set-class + ((project phpinspect-project) (class-fqn phpinspect--type) (class phpinspect--class)) (puthash (phpinspect--type-name-symbol class-fqn) class - (phpinspect--project-class-index project))) + (phpinspect-project-class-index project))) -(cl-defmethod phpinspect--project-create-class - ((project phpinspect--project) (class-fqn phpinspect--type)) +(cl-defmethod phpinspect-project-create-class + ((project phpinspect-project) (class-fqn phpinspect--type)) (let ((class (phpinspect--make-class-generated :project project))) - (phpinspect--project-set-class project class-fqn class) + (phpinspect-project-set-class project class-fqn class) class)) -(cl-defmethod phpinspect--project-get-class-create - ((project phpinspect--project) (class-fqn phpinspect--type)) - (let ((class (phpinspect--project-get-class project class-fqn))) +(cl-defmethod phpinspect-project-get-class-create + ((project phpinspect-project) (class-fqn phpinspect--type)) + (let ((class (phpinspect-project-get-class project class-fqn))) (unless class - (setq class (phpinspect--project-create-class project class-fqn)) - (phpinspect--project-enqueue-if-not-present project class-fqn)) + (setq class (phpinspect-project-create-class project class-fqn)) + (phpinspect-project-enqueue-if-not-present project class-fqn)) class)) -(defalias 'phpinspect--project-add-class-if-missing #'phpinspect--project-get-class-create) +(defalias 'phpinspect-project-add-class-if-missing #'phpinspect-project-get-class-create) -(cl-defmethod phpinspect--project-get-class - ((project phpinspect--project) (class-fqn phpinspect--type)) +(cl-defmethod phpinspect-project-get-class + ((project phpinspect-project) (class-fqn phpinspect--type)) "Get indexed class by name of CLASS-FQN stored in PROJECT." (gethash (phpinspect--type-name-symbol class-fqn) - (phpinspect--project-class-index project))) + (phpinspect-project-class-index project))) (provide 'phpinspect-project) ;;; phpinspect-project.el ends here diff --git a/phpinspect-worker.el b/phpinspect-worker.el index f63d97b..ecb4284 100644 --- a/phpinspect-worker.el +++ b/phpinspect-worker.el @@ -35,7 +35,7 @@ (:constructor phpinspect-make-index-task-generated)) "Represents an index task that can be executed by a `phpinspect-worker`." (project nil - :type phpinspect--project + :type phpinspect-project :documentation "The project that the task should be executed for.") (type nil @@ -267,7 +267,7 @@ CONTINUE must be a condition-variable" (if task ;; Execute task if it belongs to a project that has not been ;; purged (meaning that it is still actively used). - (unless (phpinspect--project-purged (phpinspect-task-project task)) + (unless (phpinspect-project-purged (phpinspect-task-project task)) (phpinspect-task-execute task worker)) ;; else: join with the main thread until wakeup is signaled (thread-join main-thread)) @@ -319,7 +319,7 @@ CONTINUE must be a condition-variable" (interactive) (phpinspect-worker-stop phpinspect-worker)) -(cl-defgeneric phpinspect-make-index-task ((project phpinspect--project) +(cl-defgeneric phpinspect-make-index-task ((project phpinspect-project) (type phpinspect--type)) (phpinspect-make-index-task-generated :project project @@ -342,7 +342,7 @@ CONTINUE must be a condition-variable" (phpinspect-index-task-type task)))) (phpinspect--log "Indexing class %s for project in %s from index thread" (phpinspect-index-task-type task) - (phpinspect--project-root project)) + (phpinspect-project-root project)) (cond (is-native-type (phpinspect--log "Skipping indexation of native type %s" @@ -356,7 +356,7 @@ CONTINUE must be a condition-variable" (let* ((type (phpinspect-index-task-type task)) (root-index (phpinspect--index-type-file project type))) (when root-index - (phpinspect--project-add-index project root-index))))))) + (phpinspect-project-add-index project root-index))))))) (provide 'phpinspect-worker) diff --git a/phpinspect.el b/phpinspect.el index d758ea6..b5512cf 100644 --- a/phpinspect.el +++ b/phpinspect.el @@ -136,7 +136,7 @@ statement of the innermost incomplete token as subject accompanied by all of its enclosing tokens." (unless resolvecontext (setq resolvecontext (phpinspect--make-resolvecontext - :project-root (phpinspect-project-root)))) + :project-root (phpinspect-current-project-root)))) (let ((last-token (car (last token))) (last-encountered-token (car @@ -160,14 +160,14 @@ accompanied by all of its enclosing tokens." (defsubst phpinspect-cache-project-class (project-root indexed-class) (when project-root - (phpinspect--project-add-class + (phpinspect-project-add-class (phpinspect--cache-get-project-create (phpinspect--get-or-create-global-cache) project-root) indexed-class))) (defsubst phpinspect-get-cached-project-class (project-root class-fqn) (when project-root - (phpinspect--project-get-class + (phpinspect-project-get-class (phpinspect--cache-get-project-create (phpinspect--get-or-create-global-cache) project-root) class-fqn))) @@ -354,7 +354,7 @@ TODO: (let* ((type-of-previous-statement (phpinspect-resolve-type-from-context resolvecontext type-resolver)) (method-name-sym (phpinspect-intern-name (cadr (cadar (last statement 2))))) - (class (phpinspect--project-get-class-create + (class (phpinspect-project-get-class-create (phpinspect--cache-get-project-create (phpinspect--get-or-create-global-cache) (phpinspect--resolvecontext-project-root resolvecontext)) @@ -768,7 +768,7 @@ EXPRESSION." (defun phpinspect--get-variables-for-class (buffer-classes class-name &optional static) (let ((class (phpinspect-get-or-create-cached-project-class - (phpinspect-project-root) + (phpinspect-current-project-root) class-name))) ;; TODO return static variables/constants when static is set (when class @@ -828,18 +828,18 @@ users will have to use \\[phpinspect-purge-cache]." (let ((imports (alist-get 'imports phpinspect--buffer-index)) (project (phpinspect--cache-get-project-create (phpinspect--get-or-create-global-cache) - (phpinspect-project-root)))) + (phpinspect-current-project-root)))) (dolist (class (alist-get 'classes phpinspect--buffer-index)) (when class - (phpinspect--project-add-class project (cdr class)) + (phpinspect-project-add-class project (cdr class)) (let ((imports (alist-get 'imports (cdr class)))) (when imports - (phpinspect--project-enqueue-imports project imports))))) + (phpinspect-project-enqueue-imports project imports))))) - (when imports (phpinspect--project-enqueue-imports project imports))))) + (when imports (phpinspect-project-enqueue-imports project imports))))) (defun phpinspect--disable-mode () @@ -1187,7 +1187,7 @@ currently opened projects." (when phpinspect-cache ;; Allow currently known cached projects to cleanup after themselves (maphash (lambda (_ project) - (phpinspect--project-purge project)) + (phpinspect-project-purge project)) (phpinspect--cache-projects phpinspect-cache))) ;; Assign a fresh cache object @@ -1229,7 +1229,7 @@ level of START-FILE in stead of `default-directory`." (string= parent-without-vendor ""))) (phpinspect--find-project-root parent-without-vendor)))))))) -(defsubst phpinspect-project-root () +(defsubst phpinspect-current-project-root () "Call `phpinspect-project-root-function' with ARGS as arguments." (unless (and (boundp 'phpinspect--buffer-project) phpinspect--buffer-project) (set (make-local-variable 'phpinspect--buffer-project) (funcall phpinspect-project-root-function))) @@ -1255,8 +1255,8 @@ fully qualified names from the project's source, and not its dependencies, are returned." (let* ((project (phpinspect--cache-get-project-create (phpinspect--get-or-create-global-cache) - (phpinspect-project-root))) - (autoloader (phpinspect--project-autoload project))) + (phpinspect-current-project-root))) + (autoloader (phpinspect-project-autoload project))) (let ((fqns)) (maphash (lambda (type _) (push (symbol-name type) fqns)) (if (eq 'own filter) @@ -1298,8 +1298,8 @@ when INDEX-NEW is non-nil, new files are added to the index before the search is executed." (let* ((project (phpinspect--cache-get-project-create (phpinspect--get-or-create-global-cache) - (phpinspect-project-root))) - (autoloader (phpinspect--project-autoload project))) + (phpinspect-current-project-root))) + (autoloader (phpinspect-project-autoload project))) (when (eq index-new 'index-new) (phpinspect-autoloader-refresh autoloader)) (let* ((result (phpinspect-autoloader-resolve @@ -1329,8 +1329,8 @@ before the search is executed." (interactive) (let* ((project (phpinspect--cache-get-project-create (phpinspect--get-or-create-global-cache) - (phpinspect-project-root))) - (autoloader (phpinspect--project-autoload project))) + (phpinspect-current-project-root))) + (autoloader (phpinspect-project-autoload project))) (phpinspect-autoloader-refresh autoloader) (message (concat "Refreshed project autoloader. Found %d types within project," " %d types total.") diff --git a/test/phpinspect-test.el b/test/phpinspect-test.el index 754f6a8..f34369a 100644 --- a/test/phpinspect-test.el +++ b/test/phpinspect-test.el @@ -484,7 +484,7 @@ class Thing (phpinspect-eldoc-word-width 100)) (phpinspect-purge-cache) (phpinspect-cache-project-class - (phpinspect-project-root) + (phpinspect-current-project-root) (cdar (alist-get 'classes (cdr index)))) (should (string= "getThis: ($moment DateTime, $thing Thing, $other): Thing" @@ -510,7 +510,7 @@ class Thing (phpinspect-eldoc-word-width 100)) (phpinspect-purge-cache) (phpinspect-cache-project-class - (phpinspect-project-root) + (phpinspect-current-project-root) (cdar (alist-get 'classes (cdr index)))) (should (string= "doThing: ($moment DateTime, $thing Thing, $other): Thing" @@ -538,7 +538,7 @@ class Thing (context (phpinspect--get-resolvecontext tokens))) (phpinspect-purge-cache) (phpinspect-cache-project-class - (phpinspect-project-root) + (phpinspect-current-project-root) (cdar (alist-get 'classes (cdr index)))) (should (phpinspect--type= (phpinspect--make-type :name "\\Thing") @@ -567,7 +567,7 @@ class Thing (context (phpinspect--get-resolvecontext tokens))) (phpinspect-purge-cache) (phpinspect-cache-project-class - (phpinspect-project-root) + (phpinspect-current-project-root) (cdar (alist-get 'classes (cdr index)))) (should (phpinspect--type= (phpinspect--make-type :name "\\Thing") diff --git a/test/test-project.el b/test/test-project.el index fa0ee27..a2adb37 100644 --- a/test/test-project.el +++ b/test/test-project.el @@ -28,9 +28,9 @@ (ert-deftest phpinspect-project-purge () (let ((project (phpinspect--make-project))) - (phpinspect--project-purge project) + (phpinspect-project-purge project) - (should (eq t (phpinspect--project-purged project))))) + (should (eq t (phpinspect-project-purged project))))) (ert-deftest phpinspect-project-watch-file-and-purge () (let* ((root (make-temp-file "phpinspect-test" 'dir)) @@ -38,9 +38,9 @@ (worker (phpinspect-make-worker)) (watch-file (concat root "/watch1")) (project (phpinspect--make-project :fs fs :root root))) - (phpinspect--project-watch-file project watch-file + (phpinspect-project-watch-file project watch-file (lambda (&rest ignored))) - (phpinspect--project-purge project) + (phpinspect-project-purge project) - (should (= 0 (length (hash-table-values (phpinspect--project-file-watchers project))))))) + (should (= 0 (length (hash-table-values (phpinspect-project-file-watchers project)))))))