branch: externals/phps-mode commit ada5e79291a73aea54915076a4e7faddf2bf6e38 Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Passing bookkeeping test for class properties in class constructor --- phps-mode-parser-sdt.el | 57 +++++++++++++++++++++++++++++++--------------- test/phps-mode-test-ast.el | 3 +-- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el index 636d9aefe1..9debeadd39 100644 --- a/phps-mode-parser-sdt.el +++ b/phps-mode-parser-sdt.el @@ -780,7 +780,7 @@ (let ((potential-uri-count (length potential-uris)) (potential-uri-index 0) (matching-uri)) - (message "potential-uris: %S" potential-uris) + ;; (message "potential-uris: %S" potential-uris) ;; Iterate potential-uris, select first match or if no match return the first (while (< potential-uri-index potential-uri-count) @@ -815,13 +815,13 @@ symbol-name symbol-scope))) - (message - "assign symbol uri: %S from %S + %S, start: %S, end: %S" - symbol-uri - symbol-name - symbol-scope - symbol-start - symbol-end) + ;; (message + ;; "assign symbol uri: %S from %S + %S, start: %S, end: %S" + ;; symbol-uri + ;; symbol-name + ;; symbol-scope + ;; symbol-start + ;; symbol-end) (if (gethash symbol-uri phps-mode-parser-sdt-bookkeeping) (puthash @@ -884,14 +884,14 @@ symbol-hit phps-mode-parser-sdt-bookkeeping) - (message - "reference symbol uri: %S from %S + %S, start: %S, end: %S, hit?: %S" - symbol-uri - symbol-name - symbol-scope - symbol-start - symbol-end - symbol-hit) + ;; (message + ;; "reference symbol uri: %S from %S + %S, start: %S, end: %S, hit?: %S" + ;; symbol-uri + ;; symbol-name + ;; symbol-scope + ;; symbol-start + ;; symbol-end + ;; symbol-hit) )) (setq @@ -3445,10 +3445,12 @@ ;; - add function scope but only for: ;; - non-super-global variables ;; - symbols defined inside function limits - (let ((function-name + (let* ((function-name (plist-get attributed-class-statement 'ast-name)) + (function-name-downcased + (downcase function-name)) (function-start (plist-get attributed-class-statement @@ -3461,7 +3463,11 @@ (plist-get attributed-class-statement 'parameter-list)) - (is-static-p)) + (is-static-p) + (is-contructor-p + (string= + function-name-downcased + "__construct"))) ;; Is static method? (when-let (method-modifiers @@ -3540,12 +3546,27 @@ 'parameter)) (attributed-parameter-name (plist-get attributed-parameter 'ast-name)) + (attributed-parameter-visibility + (plist-get attributed-parameter 'visibility)) (symbol-name attributed-parameter-name) (symbol-start (plist-get attributed-parameter 'ast-start)) (symbol-end (plist-get attributed-parameter 'ast-end))) + + (when (and + is-contructor-p + attributed-parameter-visibility) + ;; Declare class properties here + (push + (list + symbol-name + phps-mode-parser-sdt--bookkeeping-namespace + symbol-start + symbol-end) + phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack)) + (push (list symbol-name diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el index be42e58ddd..98a7fa7ccf 100644 --- a/test/phps-mode-test-ast.el +++ b/test/phps-mode-test-ast.el @@ -383,11 +383,10 @@ "A basic trait class" '((" trait MyTrait function sayHello id $this" ((80 147))) (" trait MyTrait id $var" ((35 39))) ((101 104) 1) ((94 99) 1) ((35 39) 1))) - ;; TODO Make this test pass (phps-mode-test-ast--should-bookkeep "<?php\nclass Person {\n public function __construct(\n private string $name,\n private int $age,\n public $address\n ) {}\n}" "Class with class properties in constructor." - nil) + '((" class Person function __construct id $address" ((126 134))) (" class Person id $address" ((126 134))) (" class Person function __construct id $age" ((105 109))) (" class Person id $age" ((105 109))) (" class Person function __construct id $name" ((78 83))) (" class Person id $name" ((78 83))) ((126 134) 1) ((105 109) 1) ((78 83) 1))) (message "\n-- Ran tests for bookkeeping generation. --"))