Synchronously index classes when listing methods/properties for completion

master
Hugo Thunnissen 2 months ago
parent 62bfc7830a
commit f7f43332b2

@ -163,12 +163,12 @@ currently opened projects."
project)) project))
(defun phpinspect-get-or-create-cached-project-class (project-root class-fqn) (defun phpinspect-get-or-create-cached-project-class (project-root class-fqn &optional no-enqueue)
(when project-root (when project-root
(let ((project (phpinspect--cache-get-project-create (let ((project (phpinspect--cache-get-project-create
(phpinspect--get-or-create-global-cache) (phpinspect--get-or-create-global-cache)
project-root))) project-root)))
(phpinspect-project-get-class-extra-or-create project class-fqn)))) (phpinspect-project-get-class-extra-or-create project class-fqn no-enqueue))))
(cl-defmethod phpinspect--cache-get-project-create (cl-defmethod phpinspect--cache-get-project-create
((cache phpinspect--cache) (project-root string)) ((cache phpinspect--cache) (project-root string))

@ -220,12 +220,28 @@ serious performance hits. Enable at your own risk (:")
(cl-defmethod phpinspect-project-get-class-create (cl-defmethod phpinspect-project-get-class-create
((project phpinspect-project) (class-fqn phpinspect--type) &optional no-enqueue) ((project phpinspect-project) (class-fqn phpinspect--type) &optional no-enqueue)
"Get class object belonging to CLASS-FQN from PROJECT.
If the class does exist on the filesystem but has not yet been
indexed, it will be queued for indexation and an empty class
object (awaiting indedaxation) is returned.
If NO-ENQUEUE is non-nil, the class will not be queued for
indexation, but indexed synchronously before returning."
(let ((class (phpinspect-project-get-class project class-fqn))) (let ((class (phpinspect-project-get-class project class-fqn)))
(unless class (unless class
(phpinspect-project-edit project (phpinspect-project-edit project
(setq class (phpinspect-project-create-class project class-fqn)) (setq class (phpinspect-project-create-class project class-fqn))
(unless no-enqueue (unless no-enqueue
(phpinspect-project-enqueue-if-not-present project class-fqn)))) (phpinspect-project-enqueue-if-not-present project class-fqn))))
(phpinspect--log "Got project class, no-index is set to: %s, initial-index is: %s"
no-index (phpinspect--class-initial-index class))
(phpinspect-project-edit project
(when (and no-enqueue (phpinspect--class-initial-index class))
(phpinspect--log "Indexing type file for %s" class-fqn)
(phpinspect-project-index-type-file project class-fqn)))
class)) class))
(cl-defmethod phpinspect-project-get-class-extra-or-create (cl-defmethod phpinspect-project-get-class-extra-or-create
@ -233,7 +249,6 @@ serious performance hits. Enable at your own risk (:")
(or (phpinspect-project-get-class-or-extra project class-fqn) (or (phpinspect-project-get-class-or-extra project class-fqn)
(phpinspect-project-get-class-create project class-fqn no-enqueue))) (phpinspect-project-get-class-create project class-fqn no-enqueue)))
(defalias 'phpinspect-project-add-class-if-missing #'phpinspect-project-get-class-create)
(cl-defmethod phpinspect-project-get-class (cl-defmethod phpinspect-project-get-class
((project phpinspect-project) (class-fqn phpinspect--type)) ((project phpinspect-project) (class-fqn phpinspect--type))

@ -71,7 +71,7 @@
(when project-root (when project-root
(let ((class (phpinspect-get-or-create-cached-project-class (let ((class (phpinspect-get-or-create-cached-project-class
project-root project-root
class-fqn))) class-fqn 'no-enqueue)))
(phpinspect--log (if class (phpinspect--log (if class
"Retrieved class index, starting method collection %s (%s)" "Retrieved class index, starting method collection %s (%s)"
"No class index found in %s for %s") "No class index found in %s for %s")
@ -93,7 +93,7 @@
(defun phpinspect--get-variables-for-class (class-name &optional static) (defun phpinspect--get-variables-for-class (class-name &optional static)
(let ((class (phpinspect-get-or-create-cached-project-class (let ((class (phpinspect-get-or-create-cached-project-class
(phpinspect-current-project-root) (phpinspect-current-project-root)
class-name))) class-name 'no-enqueue)))
(when class (when class
(if static (if static
(append (phpinspect--class-get-static-variables class) (phpinspect--class-get-constants class)) (append (phpinspect--class-get-static-variables class) (phpinspect--class-get-constants class))
@ -113,6 +113,7 @@ resolved to provide completion candidates.
If STATIC is non-nil, candidates are provided for constants, If STATIC is non-nil, candidates are provided for constants,
static variables and static methods." static variables and static methods."
(phpinspect--log "Suggesting attributes at point")
;; Strip away the existing (incomplete) attribute token. Otherwise, resolving ;; Strip away the existing (incomplete) attribute token. Otherwise, resolving
;; a type from this context while the user has already typed part of an ;; a type from this context while the user has already typed part of an
;; attribute name could return the type of an existing attribute that matches ;; attribute name could return the type of an existing attribute that matches
@ -134,6 +135,7 @@ static variables and static methods."
(let ((statement-type (phpinspect-resolve-type-from-context (let ((statement-type (phpinspect-resolve-type-from-context
resolvecontext resolvecontext
type-resolver))) type-resolver)))
(phpinspect--log "Statement type: %s" statement-type)
(when statement-type (when statement-type
(let ((type (funcall type-resolver statement-type))) (let ((type (funcall type-resolver statement-type)))
(append (phpinspect--get-variables-for-class (append (phpinspect--get-variables-for-class

Loading…
Cancel
Save