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

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

[elpa] externals/phpinspect d141f8a6db 08/18: Infer namespace token with


From: ELPA Syncer
Subject: [elpa] externals/phpinspect d141f8a6db 08/18: Infer namespace token within import manipulation loop
Date: Fri, 16 Aug 2024 06:58:56 -0400 (EDT)

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

    Infer namespace token within import manipulation loop
---
 phpinspect-imports.el | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/phpinspect-imports.el b/phpinspect-imports.el
index ec5fd7658f..f2329abd61 100644
--- a/phpinspect-imports.el
+++ b/phpinspect-imports.el
@@ -131,8 +131,10 @@ NAMESPACE-META itself is returned without alterations."
           (phpinspect--type= import-type (phpinspect-use-name-to-type (cadadr 
token)))))))
 
 (defun phpinspect-remove-unneeded-use-statements (types buffer imports 
parent-token)
-  (let ((namespace (phpinspect-meta-find-parent-matching-token parent-token 
#'phpinspect-namespace-p)))
-    (dolist (import imports)
+  (dolist (import imports)
+    ;; Namespace must be inferred within the loop, see comments in
+    ;; `phpinspect-add-use-statements-for-missing-types' for context.
+    (let ((namespace (phpinspect-meta-find-parent-matching-token parent-token 
#'phpinspect-namespace-p)))
       (unless (member (car import) types)
         (when-let ((use-meta (phpinspect-find-use-statement-for-import 
namespace (cdr import))))
           (let ((start-point (phpinspect-meta-start use-meta))
@@ -155,12 +157,16 @@ Uses PROJECT's autoloader to determine available types 
for import.
 
 PARENT-TOKEN must be a `token-meta' object and is used to
 determine the scope of the imports (global or local namespace)."
-  (let* ((namespace (phpinspect-meta-find-parent-matching-token
+  (dolist (type types)
+    ;; Namespace token must be inferred within the loop, as the ancestors of
+    ;; PARENT-TOKEN may change after a buffer reparse (which happens after each
+    ;; insert)
+    (let* ((namespace (phpinspect-meta-find-parent-matching-token
                        parent-token #'phpinspect-namespace-p))
-         (namespace-name (if namespace
+           (namespace-name (if namespace
                                (phpinspect-namespace-name 
(phpinspect-meta-token namespace))
                              "")))
-    (dolist (type types)
+
       ;; Add use statements for types that aren't imported or already 
referenced
       ;; with a fully qualified name.
       (unless (or (or (alist-get type imports))
@@ -169,8 +175,9 @@ determine the scope of the imports (global or local 
namespace)."
                              nil namespace-name (phpinspect-name-string type)))
                            (phpinspect-autoloader-types
                             (phpinspect-project-autoload project))))
-        (phpinspect-add-use-interactive type buffer project namespace)
-        (phpinspect-buffer-parse buffer 'no-interrupt)))))
+        (unless (member (phpinspect-name-string type) 
phpinspect-native-typenames)
+          (phpinspect-add-use-interactive type buffer project namespace)
+          (phpinspect-buffer-parse buffer 'no-interrupt))))))
 
 (defun phpinspect-fix-imports ()
   "Find types that are used in the current buffer and make sure



reply via email to

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