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

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

[elpa] externals/phps-mode 1594c15e9e 117/135: More work on imenu genera


From: Christian Johansson
Subject: [elpa] externals/phps-mode 1594c15e9e 117/135: More work on imenu generation
Date: Sun, 29 Jan 2023 03:11:10 -0500 (EST)

branch: externals/phps-mode
commit 1594c15e9e953d544b9951c17f6dc3e39cd48665
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>

    More work on imenu generation
---
 phps-mode-ast.el        |  17 +++-
 phps-mode-parser-sdt.el | 263 +++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 266 insertions(+), 14 deletions(-)

diff --git a/phps-mode-ast.el b/phps-mode-ast.el
index dbe79d0d72..a9a16bfef7 100644
--- a/phps-mode-ast.el
+++ b/phps-mode-ast.el
@@ -75,6 +75,8 @@
     (phps-mode-debug-message
      (message "\nTranslation:\n%S\n\n" translation))
 
+    (message "phps-mode-parser-sdt-symbol-imenu--table: %S" 
phps-mode-parser-sdt-symbol-imenu--table)
+
     ;; Convert imenu index from hash-table to list structure here
     (let ((imenu-index))
       (maphash
@@ -83,7 +85,7 @@
              (let ((v-list))
                (maphash
                 (lambda (k2 v2)
-                  (if hash-table-p v2
+                  (if (hash-table-p v2)
                     (let ((v2-list))
                       (maphash
                        (lambda (k3 v3)
@@ -91,6 +93,7 @@
                           `(,k3 . ,v3)
                           v2-list))
                        v2)
+                      ;; TODO sort v2-list here
                       (push
                        `(,k2 ,v2-list)
                        v-list))
@@ -98,6 +101,7 @@
                      `(,k2 . ,v2)
                      v-list)))
                 v)
+               ;; TODO Sort by index here
                (push
                 `(,k ,v-list)
                 imenu-index))
@@ -105,6 +109,17 @@
             `(,k . ,v)
             imenu-index)))
        phps-mode-parser-sdt-symbol-imenu--table)
+      ;; TODO sort imenu-index here
+      ;; (setq
+      ;;  imenu-index
+      ;;  (sort
+      ;;   imenu-index
+      ;;   (lambda (a b)
+      ;;     (cond
+      ;;      ((and
+      ;;        (listp a)
+      ;;        (listp b))
+      ;;       (if ()
       (setq
        phps-mode-parser-sdt-symbol-imenu
        imenu-index))
diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el
index 48f9e5ad52..079d7a89ab 100644
--- a/phps-mode-parser-sdt.el
+++ b/phps-mode-parser-sdt.el
@@ -887,8 +887,247 @@
          phps-mode-parser-sdt-symbol-imenu--table))))
 
   (when phps-mode-parser-sdt-symbol-imenu--stack
+    ;; Go through imenu stack and add new items to imenu index
     (message "phps-mode-parser-sdt-symbol-imenu--stack: %S" 
phps-mode-parser-sdt-symbol-imenu--stack)
-    ;; TODO Go through stack and add on imenu index
+    (let ((imenu-namespace)
+          (imenu-class)
+          (imenu-trait)
+          (imenu-interface)
+          (imenu-function))
+      (dolist (imenu-scope phps-mode-parser-sdt-symbol-imenu--stack)
+        (let ((imenu-item-type (nth 0 imenu-scope))
+              (imenu-item-name (nth 1 imenu-scope))
+              (imenu-item-start (nth 2 imenu-scope)))
+          (cond
+           ((equal imenu-item-type 'namespace)
+            (setq imenu-namespace (list imenu-item-name imenu-item-start)))
+           ((equal imenu-item-type 'class)
+            (setq imenu-class (list imenu-item-name imenu-item-start)))
+           ((equal imenu-item-type 'interface)
+            (setq imenu-interface (list imenu-item-name imenu-item-start)))
+           ((equal imenu-item-type 'trait)
+            (setq imenu-trait (list imenu-item-name imenu-item-start)))
+           ((equal imenu-item-type 'function)
+            (setq imenu-function (list imenu-item-name imenu-item-start))))))
+      (cond
+
+       (imenu-namespace
+        (let ((imenu-nail (format "namespace %s" (nth 0 imenu-namespace))))
+          (unless (gethash imenu-nail phps-mode-parser-sdt-symbol-imenu--table)
+            (let ((imenu-object (make-hash-table :test 'equal)))
+              (puthash 'declaration (nth 1 imenu-namespace) imenu-object)
+              (puthash imenu-nail imenu-object 
phps-mode-parser-sdt-symbol-imenu--table)))
+          (cond
+           (imenu-class
+            (let ((imenu-nail2 (format "class %s" (nth 0 imenu-class))))
+              (unless
+                  (gethash
+                   imenu-nail2
+                   (gethash
+                    imenu-nail
+                    phps-mode-parser-sdt-symbol-imenu--table))
+                (let ((imenu-object (make-hash-table :test 'equal)))
+                  (puthash 'declaration (nth 1 imenu-class) imenu-object)
+                  (puthash
+                   imenu-nail2
+                   imenu-object
+                   (gethash
+                    imenu-nail
+                    phps-mode-parser-sdt-symbol-imenu--table))))
+              (when imenu-function
+                (let ((imenu-nail3 (format "function %s" (nth 0 
imenu-function))))
+                  (unless
+                      (gethash
+                       imenu-nail3
+                       (gethash
+                        imenu-nail2
+                        (gethash
+                         imenu-nail
+                         phps-mode-parser-sdt-symbol-imenu--table))))
+                  (let ((imenu-object (make-hash-table :test 'equal)))
+                    (puthash 'declaration (nth imenu-function))
+                    (puthash
+                     imenu-nail3
+                     imenu-object
+                     (gethash
+                      imenu-nail2
+                      (gethash
+                       imenu-nail
+                       phps-mode-parser-sdt-symbol-imenu--table))))))))
+
+           (imenu-trait
+            (let ((imenu-nail2 (format "trait %s" (nth 0 imenu-trait))))
+              (unless
+                  (gethash
+                   imenu-nail2
+                   (gethash
+                    imenu-nail
+                    phps-mode-parser-sdt-symbol-imenu--table))
+                (let ((imenu-object (make-hash-table :test 'equal)))
+                  (puthash 'declaration (nth 1 imenu-class) imenu-object)
+                  (puthash
+                   imenu-nail2
+                   imenu-object
+                   (gethash
+                    imenu-nail
+                    phps-mode-parser-sdt-symbol-imenu--table))))
+              (when imenu-function
+                (let ((imenu-nail3 (format "function %s" (nth 0 
imenu-function))))
+                  (unless
+                      (gethash
+                       imenu-nail3
+                       (gethash
+                        imenu-nail2
+                        (gethash
+                         imenu-nail
+                         phps-mode-parser-sdt-symbol-imenu--table))))
+                  (let ((imenu-object (make-hash-table :test 'equal)))
+                    (puthash 'declaration (nth imenu-function))
+                    (puthash
+                     imenu-nail3
+                     imenu-object
+                     (gethash
+                      imenu-nail2
+                      (gethash
+                       imenu-nail
+                       phps-mode-parser-sdt-symbol-imenu--table))))))))
+
+           (imenu-interface
+            (let ((imenu-nail2 (format "interface %s" (nth 0 
imenu-interface))))
+              (unless
+                  (gethash
+                   imenu-nail2
+                   (gethash
+                    imenu-nail
+                    phps-mode-parser-sdt-symbol-imenu--table))
+                (let ((imenu-object (make-hash-table :test 'equal)))
+                  (puthash 'declaration (nth 1 imenu-class) imenu-object)
+                  (puthash
+                   imenu-nail2
+                   imenu-object
+                   (gethash
+                    imenu-nail
+                    phps-mode-parser-sdt-symbol-imenu--table))))
+              (when imenu-function
+                (let ((imenu-nail3 (format "function %s" (nth 0 
imenu-function))))
+                  (unless
+                      (gethash
+                       imenu-nail3
+                       (gethash
+                        imenu-nail2
+                        (gethash
+                         imenu-nail
+                         phps-mode-parser-sdt-symbol-imenu--table))))
+                  (let ((imenu-object (make-hash-table :test 'equal)))
+                    (puthash 'declaration (nth imenu-function))
+                    (puthash
+                     imenu-nail3
+                     imenu-object
+                     (gethash
+                      imenu-nail2
+                      (gethash
+                       imenu-nail
+                       phps-mode-parser-sdt-symbol-imenu--table)))))))))))
+
+       (imenu-class
+        (let ((imenu-nail (format "class %s" (nth 0 imenu-class))))
+          (unless
+              (gethash
+               imenu-nail
+               phps-mode-parser-sdt-symbol-imenu--table)
+            (let ((imenu-object (make-hash-table :test 'equal)))
+              (puthash 'declaration (nth 1 imenu-class) imenu-object)
+              (puthash
+               imenu-nail
+               imenu-object
+               phps-mode-parser-sdt-symbol-imenu--table)
+              (when imenu-function
+                (let ((imenu-nail2 (format "function %s" (nth 0 
imenu-function))))
+                  (unless
+                      (gethash
+                       imenu-nail2
+                       (gethash
+                        imenu-nail
+                        phps-mode-parser-sdt-symbol-imenu--table))))
+                (let ((imenu-object (make-hash-table :test 'equal)))
+                  (puthash 'declaration (nth imenu-function))
+                  (puthash
+                   imenu-nail2
+                   imenu-object
+                   (gethash
+                    imenu-nail
+                    phps-mode-parser-sdt-symbol-imenu--table))))))))
+
+       (imenu-trait
+        (let ((imenu-nail (format "trait %s" (nth 0 imenu-trait))))
+          (unless
+              (gethash
+               imenu-nail
+               phps-mode-parser-sdt-symbol-imenu--table)
+            (let ((imenu-object (make-hash-table :test 'equal)))
+              (puthash 'declaration (nth 1 imenu-class) imenu-object)
+              (puthash
+               imenu-nail
+               imenu-object
+               phps-mode-parser-sdt-symbol-imenu--table)
+              (when imenu-function
+                (let ((imenu-nail2 (format "function %s" (nth 0 
imenu-function))))
+                  (unless
+                      (gethash
+                       imenu-nail2
+                       (gethash
+                        imenu-nail
+                        phps-mode-parser-sdt-symbol-imenu--table))))
+                (let ((imenu-object (make-hash-table :test 'equal)))
+                  (puthash 'declaration (nth imenu-function))
+                  (puthash
+                   imenu-nail2
+                   imenu-object
+                   (gethash
+                    imenu-nail
+                    phps-mode-parser-sdt-symbol-imenu--table))))))))
+
+       (imenu-interface
+        (let ((imenu-nail (format "interface %s" (nth 0 imenu-interface))))
+          (unless
+              (gethash
+               imenu-nail
+               phps-mode-parser-sdt-symbol-imenu--table)
+            (let ((imenu-object (make-hash-table :test 'equal)))
+              (puthash 'declaration (nth 1 imenu-class) imenu-object)
+              (puthash
+               imenu-nail
+               imenu-object
+               phps-mode-parser-sdt-symbol-imenu--table)
+              (when imenu-function
+                (let ((imenu-nail2 (format "function %s" (nth 0 
imenu-function))))
+                  (unless
+                      (gethash
+                       imenu-nail2
+                       (gethash
+                        imenu-nail
+                        phps-mode-parser-sdt-symbol-imenu--table))))
+                (let ((imenu-object (make-hash-table :test 'equal)))
+                  (puthash 'declaration (nth imenu-function))
+                  (puthash
+                   imenu-nail2
+                   imenu-object
+                   (gethash
+                    imenu-nail
+                    phps-mode-parser-sdt-symbol-imenu--table))))))))
+
+       (imenu-function
+        (let ((imenu-nail (format "function %s" (nth 0 imenu-function))))
+          (unless
+              (gethash
+               imenu-nail
+               phps-mode-parser-sdt-symbol-imenu--table)
+            (let ((imenu-object (make-hash-table :test 'equal)))
+              (puthash 'declaration (nth 1 imenu-function) imenu-object)
+              (puthash
+               imenu-nail
+               imenu-object
+               phps-mode-parser-sdt-symbol-imenu--table)))))))
     (setq phps-mode-parser-sdt-symbol-imenu--stack nil))
 
   ;; Parse bookkeeping writes and reads at every statement terminus
@@ -913,18 +1152,16 @@
              (symbol-function))
 
         ;; Collect namespace, class, interface, trait and function here
-        (dolist (symbol-scope-item symbol-scope)
-          (let ((symbol-scope-item-type (nth 0 symbol-scope))
-                (symbol-scope-item-name (nth 1 symbol-scope)))
-            (cond
-             ((equal symbol-scope-item-type 'namespace)
-              (setq symbol-namespace symbol-scope-item-name))
-             ((equal symbol-scope-item-type 'class)
-              (setq symbol-class symbol-scope-item-name))
-             ((equal symbol-scope-item-type 'interface)
-              (setq symbol-interface symbol-scope-item-name))
-             ((equal symbol-scope-item-type 'function)
-              (setq symbol-function symbol-scope-item-name)))))
+        (when (nth 1 (nth 1 symbol-uri-object))
+          (setq symbol-namespace (car (nth 1 (nth 1 symbol-uri-object)))))
+        (when (nth 3 (nth 1 symbol-uri-object))
+          (setq symbol-class (car (nth 3 (nth 1 symbol-uri-object)))))
+        (when (nth 5 (nth 1 symbol-uri-object))
+          (setq symbol-trait (car (nth 5 (nth 1 symbol-uri-object)))))
+        (when (nth 7 (nth 1 symbol-uri-object))
+          (setq symbol-interface (car (nth 7 (nth 1 symbol-uri-object)))))
+        (when (nth 9 (nth 1 symbol-uri-object))
+          (setq symbol-function (car (nth 9 (nth 1 symbol-uri-object)))))
 
         ;; Place symbol in imenu if not there already
         (cond



reply via email to

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