emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/phpinspect e9ffa3a0ad 1/3: Fully reindex buffer after s


From: ELPA Syncer
Subject: [elpa] externals/phpinspect e9ffa3a0ad 1/3: Fully reindex buffer after save
Date: Wed, 7 Aug 2024 18:58:39 -0400 (EDT)

branch: externals/phpinspect
commit e9ffa3a0ad88752fb1e9c84c22bb1f691964144c
Author: Hugo Thunnissen <devel@hugot.nl>
Commit: Hugo Thunnissen <devel@hugot.nl>

    Fully reindex buffer after save
---
 phpinspect-buffer.el  | 25 ++++++++++++++++++++++---
 phpinspect-cache.el   |  2 +-
 phpinspect-project.el | 24 ++++++++++++++++--------
 phpinspect-suggest.el | 14 +++++++++-----
 phpinspect-type.el    |  6 ++++++
 phpinspect.el         |  2 +-
 6 files changed, 55 insertions(+), 18 deletions(-)

diff --git a/phpinspect-buffer.el b/phpinspect-buffer.el
index 354ec5e0b2..4872aed20d 100644
--- a/phpinspect-buffer.el
+++ b/phpinspect-buffer.el
@@ -33,6 +33,8 @@
 (require 'phpinspect-resolve)
 (require 'phpinspect-util)
 
+(phpinspect--declare-log-group 'buffer)
+
 (defvar-local phpinspect-current-buffer nil
   "An instance of `phpinspect-buffer' local to the active
 buffer. This variable is only set for buffers where
@@ -106,11 +108,13 @@ linked with."
   (gethash token (phpinspect-buffer-token-index buffer)))
 
 (cl-defmethod phpinspect-buffer-set-index-reference-for-token ((buffer 
phpinspect-buffer) token index)
+  (phpinspect--log "Setting index reference for token %s" token)
   (unless (phpinspect-probably-token-p token)
     (error "%s does not seem to be a token" token))
   (puthash token index (phpinspect-buffer-token-index buffer)))
 
 (cl-defmethod phpinspect-buffer-update-index-reference-for-token ((buffer 
phpinspect-buffer) old new)
+  (phpinspect--log "Updating index reference for old  token %s to new token 
%s" old new)
   (unless (and (phpinspect-probably-token-p old) (phpinspect-probably-token-p 
new))
     (when (and old new)
       (error "old and new parameters should be tokens")))
@@ -123,6 +127,7 @@ linked with."
   (unless (phpinspect-probably-token-p token)
     (error "%s does not seem to be a token" token))
 
+  (phpinspect--log "Deleting index for token %s" token)
   (cond ((phpinspect-class-p token)
          (when-let ((class (gethash token (phpinspect-buffer-token-index 
buffer))))
            (remhash token (phpinspect-buffer-token-index buffer))
@@ -299,9 +304,10 @@ linked with."
                              type-resolver
                              scope
                              (and (phpinspect-comment-p comment-before) 
comment-before)))
-              (if static
-                  (phpinspect--class-set-static-method class-obj indexed)
-                (phpinspect--class-set-method class-obj indexed))
+              (unless (phpinspect--function-anonyous-p indexed)
+                (if static
+                    (phpinspect--class-set-static-method class-obj indexed)
+                  (phpinspect--class-set-method class-obj indexed)))
 
               (phpinspect-buffer-set-index-reference-for-token
                buffer (phpinspect-meta-token func)
@@ -421,6 +427,10 @@ linked with."
   (setf (phpinspect-buffer-map buffer) (phpinspect-make-bmap))
   (setf (phpinspect-buffer-declarations buffer) nil)
   (setf (phpinspect-buffer-imports buffer) nil)
+  (setf (phpinspect-buffer-namespaces buffer) nil)
+  (setf (phpinspect-buffer-classes buffer) nil)
+  (setf (phpinspect-buffer-class-variables buffer) nil)
+  (setf (phpinspect-buffer-functions buffer) nil)
   (setf (phpinspect-buffer-token-index buffer)
         (make-hash-table :test 'eq :size 100 :rehash-size 1.5))
   (phpinspect-edtrack-clear (phpinspect-buffer-edit-tracker buffer)))
@@ -429,6 +439,13 @@ linked with."
   (phpinspect-buffer-reset buffer)
   (phpinspect-buffer-parse buffer 'no-interrupt))
 
+(cl-defmethod phpinspect-buffer-reindex ((buffer phpinspect-buffer))
+  (dolist (token (hash-table-keys (phpinspect-buffer-token-index buffer)))
+    (phpinspect-buffer-delete-index-for-token buffer token))
+
+  (phpinspect-buffer-reparse buffer)
+  (phpinspect-buffer-update-project-index buffer))
+
 (cl-defmethod phpinspect-buffer-update-project-index ((buffer 
phpinspect-buffer))
   "Update project index using the last parsed token map of this
 buffer. When `phpinspect-buffer-parse' has been executed before
@@ -440,12 +457,14 @@ continuing execution."
   (unless (phpinspect-buffer-map buffer)
     (phpinspect-buffer-parse buffer))
 
+  (phpinspect--log "Preparing to update project index")
   ;; Use inhibit-quit to prevent index corruption though partial index
   ;; application.
   (let ((inhibit-quit t))
     (when (phpinspect-buffer-project buffer)
       (let ((map (phpinspect-buffer-map buffer)))
         (unless (eq map (phpinspect-buffer--last-indexed-bmap buffer))
+          (phpinspect--log "Updating project index")
           (phpinspect-buffer-index-imports buffer (phpinspect-bmap-imports 
map))
           (phpinspect-buffer-index-declarations buffer 
(phpinspect-bmap-declarations map))
           (phpinspect-buffer-index-namespaces buffer 
(phpinspect-bmap-namespaces map))
diff --git a/phpinspect-cache.el b/phpinspect-cache.el
index 281ff75f64..eda831bff8 100644
--- a/phpinspect-cache.el
+++ b/phpinspect-cache.el
@@ -172,7 +172,7 @@ currently opened projects."
 
 (cl-defmethod phpinspect--cache-get-project-create
   ((cache phpinspect--cache) (project-root string))
-    "Get a project that is located in PROJECT-ROOT from CACHE.
+  "Get a project that is located in PROJECT-ROOT from CACHE.
 If no such project exists in the cache yet, it is created and
 then returned."
   (let ((project (phpinspect--cache-get-project cache project-root)))
diff --git a/phpinspect-project.el b/phpinspect-project.el
index 01c8f12fdb..f3cae30dec 100644
--- a/phpinspect-project.el
+++ b/phpinspect-project.el
@@ -241,29 +241,37 @@ indexation, but indexed synchronously before returning."
     (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)))
+        (phpinspect-project-add-index
+         project
+         (phpinspect-project-index-type-file project class-fqn))))
     class))
 
 (cl-defmethod phpinspect-project-get-class-extra-or-create
   ((project phpinspect-project) (class-fqn phpinspect--type) &optional 
no-enqueue)
-  (or (phpinspect-project-get-class-or-extra project class-fqn)
+  (or (phpinspect-project-get-class-or-extra project class-fqn no-enqueue)
       (phpinspect-project-get-class-create project class-fqn no-enqueue)))
 
 
 (cl-defmethod phpinspect-project-get-class
-  ((project phpinspect-project) (class-fqn phpinspect--type))
+  ((project phpinspect-project) (class-fqn phpinspect--type) &optional index)
   "Get indexed class by name of CLASS-FQN stored in PROJECT."
   (let ((class (gethash (phpinspect--type-name-symbol class-fqn)
                         (phpinspect-project-class-index project))))
-    (when (and class (phpinspect-project-read-only-p project)
-               (not (phpinspect--class-read-only-p class)))
-      (setf (phpinspect--class-read-only-p class) t))
+    (when class
+      (when (and (phpinspect-project-read-only-p project)
+                 (not (phpinspect--class-read-only-p class)))
+        (setf (phpinspect--class-read-only-p class) t))
+
+      (when (and index (not (phpinspect--class-initial-index class)))
+        (phpinspect-project-add-index
+         project
+         (phpinspect-project-index-type-file project class-fqn))))
 
     class))
 
 (cl-defmethod phpinspect-project-get-class-or-extra
-  ((project phpinspect-project) (class-fqn phpinspect--type))
-  (or (phpinspect-project-get-class project class-fqn)
+  ((project phpinspect-project) (class-fqn phpinspect--type) &optional index)
+  (or (phpinspect-project-get-class project class-fqn index)
       (and (phpinspect-project-extra-class-retriever project)
            (funcall (phpinspect-project-extra-class-retriever project)
                     class-fqn))))
diff --git a/phpinspect-suggest.el b/phpinspect-suggest.el
index d705811786..0a56fd3614 100644
--- a/phpinspect-suggest.el
+++ b/phpinspect-suggest.el
@@ -30,6 +30,8 @@
 (require 'phpinspect-project)
 (require 'phpinspect-class)
 
+(phpinspect--declare-log-group 'suggest)
+
 (defun phpinspect-suggest-functions (rctx)
   (let* ((project (phpinspect--resolvecontext-project rctx)))
     (phpinspect-project-get-functions-with-extra project)))
@@ -76,7 +78,6 @@
                              "Retrieved class index, starting method 
collection %s (%s)"
                            "No class index found in %s for %s")
                          project-root class-fqn)
-
         (when class
           (if static
               (phpinspect--class-get-static-method-list class)
@@ -138,9 +139,12 @@ static variables and static methods."
       (phpinspect--log "Statement type: %s" statement-type)
       (when statement-type
         (let ((type (funcall type-resolver statement-type)))
-          (append (phpinspect--get-variables-for-class
-                   type
-                   static)
-                  (funcall method-lister type)))))))
+          (when-let ((result
+                      (append (phpinspect--get-variables-for-class
+                               type
+                               static)
+                              (funcall method-lister type))))
+            (phpinspect--log "Returning attributes %s" result)
+            result))))))
 
 (provide 'phpinspect-suggest)
diff --git a/phpinspect-type.el b/phpinspect-type.el
index 1ffee8a16f..5ffa0fa598 100644
--- a/phpinspect-type.el
+++ b/phpinspect-type.el
@@ -248,6 +248,9 @@ as first element and the type as second element.")
                "A phpinspect--type object representing the the
 return type of the function."))
 
+(defun phpinspect--function-anonyous-p (fn)
+  (eq (phpinspect-intern-name "anonymous") (phpinspect--function-name-symbol 
fn)))
+
 (defmacro phpinspect--make-function (&rest property-list)
   `(phpinspect--make-function-generated
     ,@(phpinspect--wrap-plist-name-in-symbol property-list)))
@@ -269,6 +272,9 @@ return type of the function."))
          "When the variable is an object attribute, this should
 contain the scope of the variable as returned by
 `phpinspect-parse-scope'")
+  (readonly nil
+            :documentation
+            "Whether or not the variable is readonly")
   (lifetime nil
             :documentation
             "The lifetime of the variable (e.g. whether it is static or not). 
Will
diff --git a/phpinspect.el b/phpinspect.el
index f78b5fe45d..bf8d413855 100644
--- a/phpinspect.el
+++ b/phpinspect.el
@@ -112,7 +112,7 @@
 
 Reparses the entire buffer without token reuse."
   (when (and (boundp 'phpinspect-mode) phpinspect-mode)
-    (phpinspect-buffer-reparse phpinspect-current-buffer)))
+    (phpinspect-buffer-reindex phpinspect-current-buffer)))
 
 (defun phpinspect--disable-mode ()
   "Clean up the buffer environment for the mode to be disabled."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]