From f7f43332b226443f9c9f245a57dd1c9386339db5 Mon Sep 17 00:00:00 2001 From: Hugo Thunnissen Date: Mon, 5 Aug 2024 09:30:03 +0200 Subject: [PATCH] Synchronously index classes when listing methods/properties for completion --- phpinspect-cache.el | 4 ++-- phpinspect-project.el | 17 ++++++++++++++++- phpinspect-suggest.el | 6 ++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/phpinspect-cache.el b/phpinspect-cache.el index 3e4bbea..281ff75 100644 --- a/phpinspect-cache.el +++ b/phpinspect-cache.el @@ -163,12 +163,12 @@ currently opened projects." 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 (let ((project (phpinspect--cache-get-project-create (phpinspect--get-or-create-global-cache) 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 ((cache phpinspect--cache) (project-root string)) diff --git a/phpinspect-project.el b/phpinspect-project.el index a5b3764..685990f 100644 --- a/phpinspect-project.el +++ b/phpinspect-project.el @@ -220,12 +220,28 @@ serious performance hits. Enable at your own risk (:") (cl-defmethod phpinspect-project-get-class-create ((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))) (unless class (phpinspect-project-edit project (setq class (phpinspect-project-create-class project class-fqn)) (unless no-enqueue (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)) (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) (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 ((project phpinspect-project) (class-fqn phpinspect--type)) diff --git a/phpinspect-suggest.el b/phpinspect-suggest.el index e6e87df..d705811 100644 --- a/phpinspect-suggest.el +++ b/phpinspect-suggest.el @@ -71,7 +71,7 @@ (when project-root (let ((class (phpinspect-get-or-create-cached-project-class project-root - class-fqn))) + class-fqn 'no-enqueue))) (phpinspect--log (if class "Retrieved class index, starting method collection %s (%s)" "No class index found in %s for %s") @@ -93,7 +93,7 @@ (defun phpinspect--get-variables-for-class (class-name &optional static) (let ((class (phpinspect-get-or-create-cached-project-class (phpinspect-current-project-root) - class-name))) + class-name 'no-enqueue))) (when class (if static (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, static variables and static methods." + (phpinspect--log "Suggesting attributes at point") ;; Strip away the existing (incomplete) attribute token. Otherwise, resolving ;; 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 @@ -134,6 +135,7 @@ static variables and static methods." (let ((statement-type (phpinspect-resolve-type-from-context resolvecontext type-resolver))) + (phpinspect--log "Statement type: %s" statement-type) (when statement-type (let ((type (funcall type-resolver statement-type))) (append (phpinspect--get-variables-for-class