|
|
|
@ -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
|
|
|
|
|