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

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

[elpa] externals/phps-mode 3b6eb46d4c 129/135: Added new MVP bookkeeping


From: Christian Johansson
Subject: [elpa] externals/phps-mode 3b6eb46d4c 129/135: Added new MVP bookkeeping and imenu test
Date: Sun, 29 Jan 2023 03:11:11 -0500 (EST)

branch: externals/phps-mode
commit 3b6eb46d4c8216a3fd341320db038510857be3c3
Author: christian <christian@cvj.se>
Commit: christian <christian@cvj.se>

    Added new MVP bookkeeping and imenu test
---
 phps-mode-parser-sdt.el    | 104 ++++++++++++++++++++++++---------------------
 test/phps-mode-test-ast.el |  10 +++--
 2 files changed, 61 insertions(+), 53 deletions(-)

diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el
index 220d74e7bd..b44ca19edf 100644
--- a/phps-mode-parser-sdt.el
+++ b/phps-mode-parser-sdt.el
@@ -663,13 +663,15 @@
        phps-mode-parser-sdt--bookkeeping--superglobal-variable-p)
       (list
        name
-       (list 'namespace nil 'class nil 'trait nil 'interface nil 'function nil 
'superglobal t))
+       (list 'namespace nil 'class nil 'trait nil 'interface nil 'function nil 
'superglobal t 'object-operator nil 'static-member nil))
     (let ((potential-uris (list ""))
           (scope-namespace)
           (scope-class)
           (scope-trait)
           (scope-interface)
-          (scope-function))
+          (scope-function)
+          (scope-object-operator)
+          (scope-static-member))
       (when scope
         (let ((scope-count (length scope))
               (scope-index 0))
@@ -700,10 +702,12 @@
                    ((equal next-scope-type 'global)
                     (setq next-scope-is-global t))
                    ((equal next-scope-type 'object-operator)
+                    (setq scope-object-operator (car (cdr next-scope)))
                     (let ((downcased-scope-name (downcase (car (cdr 
next-scope)))))
                       (when (string= downcased-scope-name "$this")
                         (setq next-scope-is-this-object-operator t))))
                    ((equal next-scope-type 'static-member)
+                    (setq scope-static-member t)
                     (let ((downcased-scope-name (downcase (car (cdr 
next-scope)))))
                       (when (or
                              (string= downcased-scope-name "self")
@@ -864,10 +868,10 @@
         (if matching-uri
             (list
              matching-uri
-             (list 'namespace scope-namespace 'class scope-class 'trait 
scope-trait 'interface scope-interface 'function scope-function 'superglobal 
nil))
+             (list 'namespace scope-namespace 'class scope-class 'trait 
scope-trait 'interface scope-interface 'function scope-function 'superglobal 
nil 'object-operator scope-object-operator 'static-member scope-static-member))
           (list
            (nth 0 potential-uris)
-           (list 'namespace scope-namespace 'class scope-class 'trait 
scope-trait 'interface scope-interface 'function scope-function 'superglobal 
nil)))))))
+           (list 'namespace scope-namespace 'class scope-class 'trait 
scope-trait 'interface scope-interface 'function scope-function 'superglobal 
nil 'object-operator scope-object-operator 'static-member 
scope-static-member)))))))
 
 (defun phps-mode-parser-sdt--parse-top-statement ()
   "Parse latest top statement."
@@ -1164,7 +1168,7 @@
              (symbol-interface)
              (symbol-trait)
              (symbol-function)
-             (symbol-superglobal)
+             (symbol-is-superglobal)
              (symbol-is-this (string= (downcase symbol-name) "$this")))
 
         ;; Collect namespace, class, interface, trait and function here
@@ -1179,7 +1183,7 @@
         (when (nth 9 (nth 1 symbol-uri-object))
           (setq symbol-function (car (nth 9 (nth 1 symbol-uri-object)))))
         (when (nth 11 (nth 1 symbol-uri-object))
-          (setq symbol-superglobal t))
+          (setq symbol-is-superglobal t))
 
         ;; (message "\nsymbol-name: %S" symbol-name)
         ;; (message "symbol-scope: %S" symbol-scope)
@@ -1189,15 +1193,12 @@
         ;; (message "symbol-interface: %S" symbol-interface)
         ;; (message "symbol-function: %S" symbol-function)
 
-        ;; TODO detect if symbol is super-global
-        ;; TODO detect if symbol is $this, self, static
-
         ;; Place symbol in imenu if not there already
         ;; and is not superglobal
         ;; and is not $this
         (unless (or
-                 symbol-superglobal
-                 symbol-is-this)
+                 symbol-is-this
+                 symbol-is-superglobal)
           (cond
 
            ;; Symbol is inside namespace
@@ -1592,46 +1593,51 @@
                symbol-name
                symbol-scope))
              (symbol-uri (car symbol-uri-object))
+             (symbol-object-operator
+              (nth 13 (nth 1 symbol-uri-object)))
              (symbol-hit 0))
-        (cond
-
-         ;; Super-global variable
-         ((gethash
-           symbol-name
-           phps-mode-parser-sdt--bookkeeping--superglobal-variable-p)
-          (setq symbol-hit -1))
+        (unless (and
+                 symbol-object-operator
+                 (not (string= (downcase symbol-object-operator) "$this")))
+          (cond
 
-         ;; Declared variable
-         ((gethash
-           symbol-uri
-           phps-mode-parser-sdt-symbol-table-by-uri)
-          ;; (message "matches: %S" (gethash
-          ;;  symbol-uri
-          ;;  phps-mode-parser-sdt-symbol-table-by-uri))
-          (let* ((matching-symbol-ids
-                  (gethash
-                   symbol-uri
-                   phps-mode-parser-sdt-symbol-table-by-uri))
-                 (matching-symbol-index 0)
-                 (matching-symbol-count (length matching-symbol-ids))
-                 (matching-hit))
-            (while (and
-                 (not matching-hit)
-                 (< matching-symbol-index matching-symbol-count))
-              (let* ((matching-symbol-id
-                      (nth matching-symbol-index matching-symbol-ids))
-                     (matching-symbol
-                      (gethash
-                       matching-symbol-id
-                       phps-mode-parser-sdt-symbol-table))
-                     (matching-symbol-start
-                      (nth 1 matching-symbol)))
-                ;; (message "matching-symbol: %S" matching-symbol)
-                ;; (message "matching-symbol-start: %S" matching-symbol-start)
-                (when (<= matching-symbol-start symbol-start)
-                  (setq matching-hit t)
-                  (setq symbol-hit matching-symbol-id)))
-              (setq matching-symbol-index (1+ matching-symbol-index))))))
+           ;; Super-global variable
+           ((gethash
+             symbol-name
+             phps-mode-parser-sdt--bookkeeping--superglobal-variable-p)
+            (setq symbol-hit -1))
+
+           ;; Declared variable
+           ((gethash
+             symbol-uri
+             phps-mode-parser-sdt-symbol-table-by-uri)
+            ;; (message "matches: %S" (gethash
+            ;;  symbol-uri
+            ;;  phps-mode-parser-sdt-symbol-table-by-uri))
+            (let* ((matching-symbol-ids
+                    (gethash
+                     symbol-uri
+                     phps-mode-parser-sdt-symbol-table-by-uri))
+                   (matching-symbol-index 0)
+                   (matching-symbol-count (length matching-symbol-ids))
+                   (matching-hit))
+              (while (and
+                      (not matching-hit)
+                      (< matching-symbol-index matching-symbol-count))
+                (let* ((matching-symbol-id
+                        (nth matching-symbol-index matching-symbol-ids))
+                       (matching-symbol
+                        (gethash
+                         matching-symbol-id
+                         phps-mode-parser-sdt-symbol-table))
+                       (matching-symbol-start
+                        (nth 1 matching-symbol)))
+                  ;; (message "matching-symbol: %S" matching-symbol)
+                  ;; (message "matching-symbol-start: %S" 
matching-symbol-start)
+                  (when (<= matching-symbol-start symbol-start)
+                    (setq matching-hit t)
+                    (setq symbol-hit matching-symbol-id)))
+                (setq matching-symbol-index (1+ matching-symbol-index)))))))
 
         (puthash
          (list
diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el
index ee8d1bf6ae..3e77798291 100644
--- a/test/phps-mode-test-ast.el
+++ b/test/phps-mode-test-ast.el
@@ -217,10 +217,12 @@
    '(((7 9) 1) ((15 19) 3) ((25 27) 2) ((32 34) 2) ((37 39) 1) ((41 43) 4) 
((49 52) 7) ((58 61) 6) ((69 72) 5) ((77 80) 6) ((83 86) 5) ((89 91) 4) ((102 
105) 8) ((110 113) 8) ((115 118) 9) ((144 147) 9) ((152 155) 10) ((165 168) 10) 
((174 177) 11) ((182 185) 11) ((191 194) 12) ((199 202) 12) ((207 210) 13) 
((215 220) 14) ((225 230) 14))
    '(("$y" . 7) ("$fn1" . 15) ("$x" . 25) ("$z" . 41) ("$fn" . 49) ("$x2" . 
58) ("$y2" . 69) ("$x3" . 102) ("$x4" . 115) ("$x5" . 152) ("$x6" . 174) ("$x7" 
. 191) ("$x8" . 207) ("$rest" . 215)))
 
-  ;; (phps-mode-test-ast--should-bookkeep
-  ;;  "<?php\n$z = (object) array('name' => 'random');\nif ($z->name) {\n    
echo 'Hit';\n}"
-  ;;  "Bookkeeping ignoring variable properties"
-  ;;  '((" id $z" 1) ((7 9) 1) ((52 54) 1)))
+  ;; TODO Make this pass for MVP
+  (phps-mode-test-ast--should-bookkeep
+   "<?php\n$z = (object) ['name' => 'random', 'doThis' => function() {}];\nif 
($z->name) {\n    echo 'Hit';\n}\nif ($z->doThis()) {\n    echo 'Hit';\n}"
+   "Bookkeeping ignoring variable properties that is not $this"
+   '(((7 9) 1) ((74 76) 1) ((108 110) 1))
+   '(("$z" . 7)))
 
   (phps-mode-test-ast--should-bookkeep
    "<?php\nif (!$var = false) {\n    echo 'Hit';\n}\n"



reply via email to

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