branch: externals/phps-mode
commit ee28b830995a60e9e745ec444506d5d698324a0c
Author: Christian Johansson <christ...@cvj.se>
Commit: Christian Johansson <christ...@cvj.se>

    Added support for bookkeeping and imenu for list() variable assignment
---
 phps-mode-parser-sdt.el    | 32 ++++++++++++++++++++++++++++++++
 test/phps-mode-test-ast.el | 13 ++++++++-----
 2 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el
index 37b6466295..18d51d34c5 100644
--- a/phps-mode-parser-sdt.el
+++ b/phps-mode-parser-sdt.el
@@ -5170,6 +5170,38 @@
 (puthash
  357
  (lambda(args _terminals)
+   (let ((array-pair-list (nth 2 args)))
+     (dolist (array-item array-pair-list)
+       (let ((array-item-type (plist-get array-item 'ast-type)))
+         (cond
+          ((equal array-item-type 'array-pair-expr)
+           (let* ((array-item-expr (plist-get array-item 'expr))
+                  (array-item-expr-type (plist-get array-item-expr 'ast-type)))
+             (cond
+              ((equal array-item-expr-type 'expr-variable)
+               (let* ((expr-variable (plist-get array-item-expr 'variable))
+                      (expr-variable-type (plist-get expr-variable 'ast-type)))
+                 (cond
+                  ((equal expr-variable-type 'variable-callable-variable)
+                   (let* ((callable-variable (plist-get expr-variable 
'callable-variable))
+                          (callable-variable-type (plist-get callable-variable 
'ast-type)))
+                     (cond
+                      ((equal callable-variable-type 
'callable-variable-simple-variable)
+                       (let* ((callable-simple-variable
+                               (plist-get callable-variable 'simple-variable))
+                              (variable-name
+                               (plist-get callable-simple-variable 'variable))
+                              (variable-start
+                               (plist-get callable-simple-variable 'ast-start))
+                              (variable-end
+                               (plist-get callable-simple-variable 'ast-end)))
+                         (push
+                          (list
+                           variable-name
+                           phps-mode-parser-sdt--bookkeeping-namespace
+                           variable-start
+                           variable-end)
+                          
phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack))))))))))))))))
    `(
      ast-type
      expr-list
diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el
index e3da1b8e35..147b654abc 100644
--- a/test/phps-mode-test-ast.el
+++ b/test/phps-mode-test-ast.el
@@ -131,12 +131,9 @@
   "Run test for bookkeeping generation."
   (message "-- Running tests for bookkeeping generation... --\n")
 
-  ;; TODO Support list($abc, $def) = myFunction();
-
   ;; TODO v2 Should have more delicate handling of isset, !empty condition 
blocks
-  ;; TODO v2 Should properly bookkeep inside endlessly nested anonymous 
functions / arrow functions / anonymous classes
-  ;; TODO v2 bookkeep and include constants in imenu
-  ;; TODO v2 imenu should contain declaration of variables, both define and 
namespace const and class, trait and interface const
+  ;; TODO v2 Should properly bookkeep inside potentially endlessly nested 
anonymous functions / arrow functions / anonymous classes
+  ;; TODO v2 bookkeep and include all kind of constants in imenu
 
   (phps-mode-test-ast--should-bookkeep
    "<?php\n\n$var = 'abc';\n\nif ($var2) {\n    echo 'This never 
happens';\n}\nif ($var) {\n    echo 'This happens';\n}"
@@ -215,6 +212,12 @@
    '(((9 16) 1) ((18 25) 2) ((45 52) 1) ((78 85) 2))
    '(("$random" . 9) ("$bandom" . 18)))
 
+  (phps-mode-test-ast--should-bookkeep
+   "<?php\n\nlist($random, $bandom) = myValues();\nif ($random) {\n    echo 
'Hit';\n}\nif ($bandom) {\n    echo 'Hit';\n}\n"
+   "Bookkeeping of variable declarations in array via list()"
+   '(((13 20) 1) ((22 29) 2) ((49 56) 1) ((82 89) 2))
+   '(("$random" . 13) ("$bandom" . 22)))
+
   (phps-mode-test-ast--should-bookkeep
    "<?php\n\n$var = 123;\n\nfunction test($abc) {\n    global $var, $var2;\n   
 if ($var) {\n        echo 'Hit';\n    }\n    if ($var2) {\n        echo 
'Hit';\n    }\n}"
    "Bookkeeping of global variable declaration in function"

Reply via email to