branch: externals/phps-mode
commit 9201d1ccd426d4ec9a58c3c5c81a6b8873d99385
Author: Christian Johansson <[email protected]>
Commit: Christian Johansson <[email protected]>
Imenu index now handles functions with optional arguments
---
phps-mode-functions.el | 7 ++++++-
phps-mode-test-functions.el | 5 +++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index c15c37b..04c36ae 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -631,6 +631,7 @@
(open-class-level nil)
(in-class-name nil)
(in-function-declaration nil)
+ (in-function-name nil)
(open-function-level nil)
(nesting-level 0))
(dolist (token tokens)
@@ -695,14 +696,17 @@
((string= token-symbol "{")
(setq open-function-level nesting-level)
+ (setq in-function-name nil)
(setq in-function-declaration nil))
((string= token-symbol ";")
(setq in-function-declaration nil))
- ((equal token-symbol 'T_STRING)
+ ((and (equal token-symbol 'T_STRING)
+ (not in-function-name))
(let ((index-name (format "%s()"
(buffer-substring-no-properties token-start token-end)))
(index-pos token-start))
+ (setq in-function-name index-name)
(when in-class-name
(setq index-name (concat in-class-name "->" index-name)))
(when in-namespace-name
@@ -721,6 +725,7 @@
(setq in-class-declaration t))
((equal token-symbol 'T_FUNCTION)
+ (setq in-function-name nil)
(setq in-function-declaration t)))))))))
(nreverse index)))
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index 04100bd..b69ae50 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -616,6 +616,11 @@
"Imenu object-oriented file with bracket-less namespace, class that extends
and implements and functions"
(should (equal (phps-mode-functions-imenu-create-index-function)
'(("\\myNamespace" . 17) ("\\myNamespace\\myClass" . 36)
("\\myNamespace\\myClass->myFunctionA()" . 108)
("\\myNamespace\\myClass->myFunctionB()" . 148)))))
+ (phps-mode-test-with-buffer
+ "<?php\nnamespace myNamespace;\nclass myClass extends myAbstract implements
myInterface {\n public function myFunctionA($myArg = null) {}\n protected
function myFunctionB($myArg = 'abc') {}\n}\n"
+ "Imenu object-oriented file with bracket-less namespace, class that extends
and implements and functions with optional arguments"
+ (should (equal (phps-mode-functions-imenu-create-index-function)
'(("\\myNamespace" . 17) ("\\myNamespace\\myClass" . 36)
("\\myNamespace\\myClass->myFunctionA()" . 108)
("\\myNamespace\\myClass->myFunctionB()" . 161)))))
+
)
;; TODO Add tests for all examples here: https://www.php-fig.org/psr/psr-2/