branch: externals/phps-mode commit 66c02b9be1eb3dbf147ba2caaf3f2b6249e17661 Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Passing test for bookkeeping of interface variables --- phps-mode-parser-sdt.el | 32 ++++++++++++++++++++++++++++++++ test/phps-mode-test-ast.el | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el index bf35794061..68e343d11f 100644 --- a/phps-mode-parser-sdt.el +++ b/phps-mode-parser-sdt.el @@ -2293,6 +2293,38 @@ (puthash 191 (lambda(args terminals) + ;; Go through stacks and modify symbol name-spaces + ;; but only for non-super-global variables. + ;; + ;; Should place class scope first in scope + ;; unless a namespace exists, in that case it should be placed second in scope + (let ((class-name (nth 1 args))) + (when phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack + (dolist ( + symbol-list + phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack) + (let ((symbol-name (car symbol-list)) + (symbol-start (nth 2 symbol-list)) + (symbol-end (nth 3 symbol-list))) + (unless (gethash + symbol-name + phps-mode-parser-sdt--bookkeeping--superglobal-variable-p) + (let ((symbol-scope (reverse (car (cdr symbol-list))))) + (if (equal (car (car symbol-scope)) 'namespace) + (let ((namespace-name (car (cdr (car symbol-scope))))) + (setcar symbol-scope (list 'interface class-name)) + (push (list 'namespace namespace-name) symbol-scope)) + (push + (list 'interface class-name) + symbol-scope)) + (setq symbol-scope (reverse symbol-scope)) + (setcar + (cdr symbol-list) + symbol-scope) + (push + (list symbol-name symbol-scope symbol-start symbol-end) + phps-mode-parser-sdt--bookkeeping-symbol-stack))))))) + `( ast-type interface-declaration-statement diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el index 4930dacd01..1fb50e6b56 100644 --- a/test/phps-mode-test-ast.el +++ b/test/phps-mode-test-ast.el @@ -301,7 +301,7 @@ (phps-mode-test-ast--should-bookkeep "<?php\ninterface myInterface\n{\n function myFunction1();\n function myFunction2($x);\n}\n" "Bookkeeping variable in interface function" - '((" class myInterface function myFunction2 id $x" 1) ((84 86) 1))) + '((" interface myInterface function myFunction2 id $x" ((84 86))) ((84 86) 1))) (phps-mode-test-ast--should-bookkeep "<?php\n\nfunction myFunction1()\n{\n return isset($a);\n}\n\nfunction myFunction2()\n{\n $b = 2;\n if ($b) {\n echo 'Hit';\n }\n if ($b) {\n echo 'Hit';\n }\n}\n"