|
|
@ -368,7 +368,16 @@ namespace if not provided"
|
|
|
|
(previous nil
|
|
|
|
(previous nil
|
|
|
|
:type phpinspect--queue-item
|
|
|
|
:type phpinspect--queue-item
|
|
|
|
:documentation
|
|
|
|
:documentation
|
|
|
|
"The previous item in the queue"))
|
|
|
|
"The previous item in the queue")
|
|
|
|
|
|
|
|
(subscription nil
|
|
|
|
|
|
|
|
:type function
|
|
|
|
|
|
|
|
:read-only t
|
|
|
|
|
|
|
|
:documentation
|
|
|
|
|
|
|
|
"A function that should be called when items are
|
|
|
|
|
|
|
|
enqueued."))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defsubst phpinspect--make-queue (&optional subscription)
|
|
|
|
|
|
|
|
(phpinspect--make-queue-item :subscription subscription))
|
|
|
|
|
|
|
|
|
|
|
|
(cl-defmethod phpinspect--queue-last ((item phpinspect--queue-item))
|
|
|
|
(cl-defmethod phpinspect--queue-last ((item phpinspect--queue-item))
|
|
|
|
(if (phpinspect--queue-item-next item)
|
|
|
|
(if (phpinspect--queue-item-next item)
|
|
|
@ -381,27 +390,30 @@ namespace if not provided"
|
|
|
|
item))
|
|
|
|
item))
|
|
|
|
|
|
|
|
|
|
|
|
(cl-defmethod phpinspect--queue-enqueue ((item phpinspect--queue-item) thing)
|
|
|
|
(cl-defmethod phpinspect--queue-enqueue ((item phpinspect--queue-item) thing)
|
|
|
|
(let ((last (phpinspect--queue-last item)))
|
|
|
|
(let ((last (phpinspect--queue-last item)))
|
|
|
|
(if (not (phpinspect--queue-item-thing last))
|
|
|
|
(if (not (phpinspect--queue-item-thing last))
|
|
|
|
(setf (phpinspect--queue-item-thing last) thing)
|
|
|
|
(setf (phpinspect--queue-item-thing last) thing)
|
|
|
|
(setf (phpinspect--queue-item-next last)
|
|
|
|
(setf (phpinspect--queue-item-next last)
|
|
|
|
(phpinspect--make-queue-item :previous last :thing thing)))))
|
|
|
|
(phpinspect--make-queue-item
|
|
|
|
|
|
|
|
:previous last
|
|
|
|
|
|
|
|
:thing thing
|
|
|
|
|
|
|
|
:subscription (phpinspect--queue-item-subscription item)))))
|
|
|
|
|
|
|
|
(funcall (phpinspect--queue-item-subscription item)))
|
|
|
|
|
|
|
|
|
|
|
|
(cl-defmethod phpinspect--queue-dequeue ((item phpinspect--queue-item))
|
|
|
|
(cl-defmethod phpinspect--queue-dequeue ((item phpinspect--queue-item))
|
|
|
|
(let* ((first (phpinspect--queue-first item))
|
|
|
|
(let* ((first (phpinspect--queue-first item))
|
|
|
|
(thing (phpinspect--queue-item-thing first))
|
|
|
|
(thing (phpinspect--queue-item-thing first))
|
|
|
|
(next (phpinspect--queue-item-next first)))
|
|
|
|
(next (phpinspect--queue-item-next first)))
|
|
|
|
(when next (setf (phpinspect--queue-item-previous next) nil))
|
|
|
|
(when next (setf (phpinspect--queue-item-previous next) nil))
|
|
|
|
(cond ((and (eq item first) (not next))
|
|
|
|
(cond ((and (eq item first) (not next))
|
|
|
|
(setf (phpinspect--queue-item-thing item)
|
|
|
|
(setf (phpinspect--queue-item-thing item)
|
|
|
|
nil))
|
|
|
|
nil))
|
|
|
|
((eq item first)
|
|
|
|
((eq item first)
|
|
|
|
|
|
|
|
(setf (phpinspect--queue-item-thing item)
|
|
|
|
(setf (phpinspect--queue-item-thing item)
|
|
|
|
(phpinspect--queue-item-thing next))
|
|
|
|
(phpinspect--queue-item-thing next))
|
|
|
|
(setf (phpinspect--queue-item-next item)
|
|
|
|
(setf (phpinspect--queue-item-next item)
|
|
|
|
(phpinspect--queue-item-next next))))
|
|
|
|
(phpinspect--queue-item-next next))))
|
|
|
|
thing))
|
|
|
|
thing))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(cl-defmethod phpinspect--queue-find
|
|
|
|
(cl-defmethod phpinspect--queue-find
|
|
|
|
((item phpinspect--queue-item) thing comparison-func)
|
|
|
|
((item phpinspect--queue-item) thing comparison-func)
|
|
|
@ -423,7 +435,10 @@ namespace if not provided"
|
|
|
|
(when (not (phpinspect--queue-find item thing comparison-func))
|
|
|
|
(when (not (phpinspect--queue-find item thing comparison-func))
|
|
|
|
(phpinspect--queue-enqueue item thing)))
|
|
|
|
(phpinspect--queue-enqueue item thing)))
|
|
|
|
|
|
|
|
|
|
|
|
(defvar phpinspect--index-queue (phpinspect--make-queue-item)
|
|
|
|
(cl-defmethod phpinspect--queue-await-insert ((item phpinspect--queue-item))
|
|
|
|
|
|
|
|
(condition-wait (phpinspect--queue-item-insert item)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defvar phpinspect--index-queue (phpinspect--make-queue)
|
|
|
|
"Queue with indexation tasks. Each task is a list, the car of
|
|
|
|
"Queue with indexation tasks. Each task is a list, the car of
|
|
|
|
which is a project directory path and the cadr of which is an
|
|
|
|
which is a project directory path and the cadr of which is an
|
|
|
|
instance of `phpinspect--type`.")
|
|
|
|
instance of `phpinspect--type`.")
|
|
|
@ -436,33 +451,46 @@ namespace if not provided"
|
|
|
|
|
|
|
|
|
|
|
|
(defun phpinspect--index-thread-function ()
|
|
|
|
(defun phpinspect--index-thread-function ()
|
|
|
|
(while phpinspect--index-thread-running
|
|
|
|
(while phpinspect--index-thread-running
|
|
|
|
(let* ((task (phpinspect--queue-dequeue phpinspect--index-queue))
|
|
|
|
;; This error is used to wake up the thread when new tasks are added to the
|
|
|
|
(mx (make-mutex))
|
|
|
|
;; queue.
|
|
|
|
(continue (make-condition-variable mx))
|
|
|
|
(ignore-error 'phpinspect--wakeup-thread
|
|
|
|
(skip-pause))
|
|
|
|
(let* ((task (phpinspect--queue-dequeue phpinspect--index-queue))
|
|
|
|
(when task
|
|
|
|
(mx (make-mutex))
|
|
|
|
(phpinspect--log "Indexing class %s for project in %s from index thread"
|
|
|
|
(continue (make-condition-variable mx))
|
|
|
|
(phpinspect--index-task-type task)
|
|
|
|
(skip-pause))
|
|
|
|
(phpinspect--index-task-project-root task))
|
|
|
|
(if task
|
|
|
|
|
|
|
|
(progn
|
|
|
|
(let ((project (phpinspect--cache-get-project-create
|
|
|
|
(phpinspect--log "Indexing class %s for project in %s from index thread"
|
|
|
|
(phpinspect--get-or-create-global-cache)
|
|
|
|
(phpinspect--index-task-type task)
|
|
|
|
(phpinspect--index-task-project-root task)))
|
|
|
|
(phpinspect--index-task-project-root task))
|
|
|
|
(is-native-type (phpinspect--type-is-native
|
|
|
|
|
|
|
|
(phpinspect--index-task-type task))))
|
|
|
|
(let ((project (phpinspect--cache-get-project-create
|
|
|
|
(if is-native-type
|
|
|
|
(phpinspect--get-or-create-global-cache)
|
|
|
|
(progn
|
|
|
|
(phpinspect--index-task-project-root task)))
|
|
|
|
(phpinspect--log "Skipping indexation of native type %s"
|
|
|
|
(is-native-type (phpinspect--type-is-native
|
|
|
|
(phpinspect--index-task-type task))
|
|
|
|
(phpinspect--index-task-type task))))
|
|
|
|
(setq skip-pause t))
|
|
|
|
(if is-native-type
|
|
|
|
(let ((type-index (phpinspect--index-type
|
|
|
|
(progn
|
|
|
|
project
|
|
|
|
(phpinspect--log "Skipping indexation of native type %s"
|
|
|
|
(phpinspect--index-task-type task))))
|
|
|
|
(phpinspect--index-task-type task))
|
|
|
|
(when type-index (phpinspect--project-add-class project type-index))))))
|
|
|
|
|
|
|
|
|
|
|
|
;; We can skip pausing when a native type is encountered
|
|
|
|
(unless skip-pause
|
|
|
|
;; and skipped, as we haven't done any intensive work that
|
|
|
|
(phpinspect--index-thread-pause 1 mx continue))
|
|
|
|
;; may cause hangups.
|
|
|
|
(setq skip-pause nil)))
|
|
|
|
(setq skip-pause t))
|
|
|
|
|
|
|
|
(let ((type-index (phpinspect--index-type
|
|
|
|
|
|
|
|
project
|
|
|
|
|
|
|
|
(phpinspect--index-task-type task))))
|
|
|
|
|
|
|
|
(when type-index (phpinspect--project-add-class project type-index))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; else: join with the main thread until wakeup is signaled
|
|
|
|
|
|
|
|
(thread-join main-thread))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Pause for a second after indexing something, to allow user input to
|
|
|
|
|
|
|
|
;; interrupt the thread.
|
|
|
|
|
|
|
|
(unless skip-pause
|
|
|
|
|
|
|
|
(phpinspect--index-thread-pause 1 mx continue))
|
|
|
|
|
|
|
|
(setq skip-pause nil))))
|
|
|
|
(phpinspect--log "Index thread exiting")
|
|
|
|
(phpinspect--log "Index thread exiting")
|
|
|
|
(message "phpinspect index thread exited"))
|
|
|
|
(message "phpinspect index thread exited"))
|
|
|
|
|
|
|
|
|
|
|
@ -475,10 +503,18 @@ namespace if not provided"
|
|
|
|
(with-mutex mx (condition-wait continue))
|
|
|
|
(with-mutex mx (condition-wait continue))
|
|
|
|
(phpinspect--log "Index thread continuing"))
|
|
|
|
(phpinspect--log "Index thread continuing"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-error 'phpinspect--wakeup-thread
|
|
|
|
|
|
|
|
"This error is used to wakeup the index thread")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun phpinspect--wakeup-index-thread ()
|
|
|
|
|
|
|
|
(when (thread--blocker phpinspect--index-thread)
|
|
|
|
|
|
|
|
(thread-signal phpinspect--index-thread 'phpinspect--wakeup-thread nil)))
|
|
|
|
|
|
|
|
|
|
|
|
(defun phpinspect--ensure-index-thread ()
|
|
|
|
(defun phpinspect--ensure-index-thread ()
|
|
|
|
(interactive)
|
|
|
|
(interactive)
|
|
|
|
(when (or (not phpinspect--index-thread)
|
|
|
|
(when (or (not phpinspect--index-thread)
|
|
|
|
(not (thread-alive-p phpinspect--index-thread)))
|
|
|
|
(not (thread-alive-p phpinspect--index-thread)))
|
|
|
|
|
|
|
|
(setq phpinspect--index-queue (phpinspect--make-queue #'phpinspect--wakeup-index-thread))
|
|
|
|
(setq phpinspect--index-thread-running t)
|
|
|
|
(setq phpinspect--index-thread-running t)
|
|
|
|
(setq phpinspect--index-thread
|
|
|
|
(setq phpinspect--index-thread
|
|
|
|
(make-thread #'phpinspect--index-thread-function "phpinspect-index-thread"))))
|
|
|
|
(make-thread #'phpinspect--index-thread-function "phpinspect-index-thread"))))
|
|
|
|