branch: externals/phps-mode commit ddc5b5aa2aa109b66bc7bd3edafe4ee9989d7248 Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Using sorted bookkeeping for test --- phps-mode-parser-sdt.el | 31 ++++++++++++++++++------------- phps-mode-test.el | 7 ++++++- test/phps-mode-test-ast.el | 20 ++++++++------------ 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el index 88dae66d7a..df265fe62e 100644 --- a/phps-mode-parser-sdt.el +++ b/phps-mode-parser-sdt.el @@ -1262,7 +1262,7 @@ ;; Declare variables (dolist ( symbol-list - phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack) + (reverse phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack)) (let* ((symbol-name (car symbol-list)) (symbol-scope (car (cdr symbol-list))) (symbol-start (car (cdr (cdr symbol-list)))) @@ -1356,27 +1356,32 @@ ((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) - (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))) + (matching-hit)) (while (and (not matching-hit) (< matching-symbol-index matching-symbol-count)) - (when (<= matching-symbol-start symbol-start) - (setq matching-hit t) - (setq symbol-hit matching-symbol-id)) + (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 diff --git a/phps-mode-test.el b/phps-mode-test.el index ef62b64e97..b4e65ffe7f 100644 --- a/phps-mode-test.el +++ b/phps-mode-test.el @@ -178,7 +178,12 @@ hash-table) (if un-sorted (nreverse result) - (sort (nreverse result) (lambda (a b) (< (car a) (car b)))))) + (sort + (nreverse result) + (lambda (a b) + (if (listp (car a)) + (< (car (car a)) (car (car b))) + (< (car a) (car b))))))) nil))) (transient-mark-mode t) diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el index 751c410487..73544ed977 100644 --- a/test/phps-mode-test-ast.el +++ b/test/phps-mode-test-ast.el @@ -40,26 +40,22 @@ ;; (message "symbol-table: \n%S\n" phps-mode-parser-sdt-symbol-table) ;; (message "phps-mode-parser-sdt-symbol-table-by-uri: \n%S\n" phps-mode-parser-sdt-symbol-table-by-uri) - (unless - (equal - (phps-mode-test--hash-to-list - phps-mode-parser-sdt-bookkeeping - t) - expected-bookkeeping) + (unless (equal + (phps-mode-test--hash-to-list + phps-mode-parser-sdt-bookkeeping) + expected-bookkeeping) (message "expected-bookkeeping:\n%S\n" expected-bookkeeping) (message "actual-bookkeeping:\n%S\n" (phps-mode-test--hash-to-list - phps-mode-parser-sdt-bookkeeping - t))) + phps-mode-parser-sdt-bookkeeping))) (should (equal (phps-mode-test--hash-to-list - phps-mode-parser-sdt-bookkeeping - t) + phps-mode-parser-sdt-bookkeeping) expected-bookkeeping)) (when expected-imenu @@ -343,8 +339,8 @@ (phps-mode-test-ast--should-bookkeep "<?php\nfunction myFunction()\n{\n $variable = 123;\n if ($variable === 456) {\n $variable = 789;\n }\n}\n" "Variable inside function with assignment inside conditional block" - '(((89 98) 1) ((60 69) 1) ((35 44) 1)) - '(("myFunction" . 16))) + '(((35 44) 2) ((60 69) 2) ((89 98) 2)) + '(("function myFunction" . 16) ("function myFunction id $variable" . 35) ("function myFunction id $variable (2)" . 89))) (message "\n-- Ran tests for bookkeeping generation. --"))