branch: externals/phps-mode commit a07fd20026bd8c0a1a974416bb99d15d20fbbf0d Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Keeping track of global namespace directly from SDT --- phps-mode-ast-imenu.el | 131 +++++++++++++++++++++++++++++------------------- phps-mode-parser-sdt.el | 101 ++++++++++++++++++++++++++++++++----- 2 files changed, 169 insertions(+), 63 deletions(-) diff --git a/phps-mode-ast-imenu.el b/phps-mode-ast-imenu.el index e61e6bfe9d..1b3528ee33 100644 --- a/phps-mode-ast-imenu.el +++ b/phps-mode-ast-imenu.el @@ -19,7 +19,9 @@ (defun phps-mode-ast-imenu--generate (&optional tree) "Generate imenu from current buffer AST or optionally from TREE." (let ((imenu-index) - (ast-tree (if tree tree phps-mode-ast--tree))) + (ast-tree (if tree tree phps-mode-ast--tree)) + (global-namespace-name) + (global-namespace-items)) (dolist (item ast-tree) (let ((children (plist-get item 'children)) (item-type (plist-get item 'ast-type)) @@ -30,57 +32,84 @@ item-index item-name item-type) - (if (and - (or - (equal item-type 'namespace) - (equal item-type 'class) - (equal item-type 'interface)) - children) - (progn - (dolist (child children) - (let ((grand-children (plist-get child 'children)) - (child-type (plist-get child 'ast-type)) - (child-name (plist-get child 'name)) - (child-index (plist-get child 'index)) - (subparent)) - (when (and - child-name - child-index) - (if (and - (or - (equal child-type 'class) - (equal child-type 'interface)) - grand-children) - (progn - (dolist (grand-child grand-children) - (let ((grand-child-index - (plist-get grand-child 'index)) - (grand-child-name - (plist-get grand-child 'name))) - (when (and - grand-child-index - grand-child-name) + (if (or + (equal item-type 'namespace) + (equal item-type 'class) + (equal item-type 'interface)) + (if children + (progn + (dolist (child children) + (let ((grand-children (plist-get child 'children)) + (child-type (plist-get child 'ast-type)) + (child-name (plist-get child 'name)) + (child-index (plist-get child 'index)) + (subparent)) + (when (and + child-name + child-index) + (if (and + (or + (equal child-type 'class) + (equal child-type 'interface)) + grand-children) + (progn + (dolist (grand-child grand-children) + (let ((grand-child-index + (plist-get grand-child 'index)) + (grand-child-name + (plist-get grand-child 'name))) + (when (and + grand-child-index + grand-child-name) + (push + `(,grand-child-name . ,grand-child-index) + subparent)))) + (when subparent (push - `(,grand-child-name . ,grand-child-index) - subparent)))) - (when subparent - (push - (append - (list child-name) - (reverse subparent)) - parent))) - (push - `(,child-name . ,child-index) - parent))))) - (when parent - (push - (append - (list item-name) - (reverse parent)) - imenu-index))) - (push - `(,item-name . ,item-index) - imenu-index))))) + (append + (list child-name) + (reverse subparent)) + parent))) + (push + `(,child-name . ,child-index) + parent))))) + (when parent + (let ((parent-item + (append + (list item-name) + (reverse parent)))) + (if global-namespace-name + (push + parent-item + global-namespace-items) + (push + parent-item + imenu-index)) + imenu-index))) + (if (equal item-type 'namespace) + (setq + global-namespace-name + item-name) + (if global-namespace-name + (push + `(,item-name . ,item-index) + global-namespace-items) + (push + `(,item-name . ,item-index) + imenu-index)))) + (if global-namespace-name + (push + `(,item-name . ,item-index) + global-namespace-items) + (push + `(,item-name . ,item-index) + imenu-index)))))) + (when global-namespace-name + (push + (append + (list global-namespace-name) + (reverse global-namespace-items)) + imenu-index)) (setq phps-mode-ast-imenu--index (reverse imenu-index))) diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el index d770cedda1..bfe93e9c30 100644 --- a/phps-mode-parser-sdt.el +++ b/phps-mode-parser-sdt.el @@ -962,7 +962,7 @@ ast-type attribute-group children - ,(append (plist-get (nth 0 args) 'ast-type) (nth 2 args)) + ,(append (plist-get (nth 0 args) 'ast-type) (list (nth 2 args))) )) phps-mode-parser--table-translations) @@ -998,7 +998,7 @@ ast-type attributes children - ,(append (plist-get (nth 0 args) 'children) (nth 1 args)) + ,(append (plist-get (nth 0 args) 'children) (list (nth 1 args))) )) phps-mode-parser--table-translations) @@ -1088,7 +1088,7 @@ ;; 114 ((top_statement) (T_USE mixed_group_use_declaration ";")) (puthash 114 - (lambda(args terminals) + (lambda(args _terminals) `( ast-type mixed-group-use-declaration-top-statement @@ -1100,7 +1100,7 @@ ;; 115 ((top_statement) (T_USE use_type group_use_declaration ";")) (puthash 115 - (lambda(args terminals) + (lambda(args _terminals) `( ast-type type-group-use-declaration-top-statement @@ -1114,7 +1114,7 @@ ;; 116 ((top_statement) (T_USE use_declarations ";")) (puthash 116 - (lambda(args terminals) + (lambda(args _terminals) `( ast-type use-declarations-top-statement @@ -1126,7 +1126,7 @@ ;; 117 ((top_statement) (T_USE use_type use_declarations ";")) (puthash 117 - (lambda(args terminals) + (lambda(args _terminals) `( ast-type type-use-declarations-top-statement @@ -1138,7 +1138,7 @@ ;; 118 ((top_statement) (T_CONST const_list ";")) (puthash 118 - (lambda(args terminals) + (lambda(args _terminals) `( ast-type const-list-top-statement @@ -1151,12 +1151,12 @@ (puthash 119 (lambda(args terminals) args) phps-mode-parser--table-translations) ;; 120 ((use_type) (T_CONST)) -(puthash 120 (lambda(args terminals) args) phps-mode-parser--table-translations) +(puthash 120 (lambda(args _terminals) args) phps-mode-parser--table-translations) ;; 121 ((group_use_declaration) (legacy_namespace_name T_NS_SEPARATOR "{" unprefixed_use_declarations possible_comma "}")) (puthash 121 - (lambda(args terminals) + (lambda(args _terminals) `( ast-type legacy-group-use-declaration @@ -1168,7 +1168,7 @@ ;; 122 ((mixed_group_use_declaration) (legacy_namespace_name T_NS_SEPARATOR "{" inline_use_declarations possible_comma "}")) (puthash 122 - (lambda(args terminals) + (lambda(args _terminals) `( ast-type mixed-group-use-declaration @@ -1178,10 +1178,87 @@ phps-mode-parser--table-translations) ;; 123 ((possible_comma) (%empty)) -(puthash 123 (lambda(_args terminals) nil) phps-mode-parser--table-translations) +(puthash 123 (lambda(_args _terminals) nil) phps-mode-parser--table-translations) ;; 124 ((possible_comma) (",")) -(puthash 124 (lambda(_args terminals) nil) phps-mode-parser--table-translations) +(puthash 124 (lambda(_args _terminals) nil) phps-mode-parser--table-translations) + +;; 125 ((inline_use_declarations) (inline_use_declarations "," inline_use_declaration)) +(puthash + 125 + (lambda(args _terminals) + `( + ast-type + inline-use-declarations + ,(append (nth 0 args) (list (nth 2 args))) + )) + phps-mode-parser--table-translations) + +;; 126 ((inline_use_declarations) (inline_use_declaration)) +(puthash + 126 + (lambda(args terminals) + `( + ast-type + inline-use-declarations + ,(list (nth 1 args)) + )) + phps-mode-parser--table-translations) + +;; 127 ((unprefixed_use_declarations) (unprefixed_use_declarations "," unprefixed_use_declaration)) +(puthash + 127 + (lambda(args terminals) + `( + ast-type + unprefixed-use-declarations + ,(append (nth 0 args) (list (nth 2 args))) + )) + phps-mode-parser--table-translations) + +;; 128 ((unprefixed_use_declarations) (unprefixed_use_declaration)) +(puthash + 128 + (lambda(args terminals) + `( + ast-type + unprefixed-use-declarations + ,(args)) + ) + phps-mode-parser--table-translations) + +;; 129 ((use_declarations) (use_declarations "," use_declaration)) +(puthash + 129 + (lambda(args terminals) + `( + ast-type + use-declarations + ,(append (nth 0 args) (list (nth 2 args))) + )) + phps-mode-parser--table-translations) + +;; 130 ((use_declarations) (use_declaration)) +(puthash + 130 + (lambda(args terminals) + `( + ast-type + use-declarations + (args) + )) + phps-mode-parser--table-translations) + +;; 131 ((inline_use_declaration) (unprefixed_use_declaration)) +(puthash + 130 + (lambda(args terminals) + `( + ast-type + inline-use-declaration + (args) + )) + phps-mode-parser--table-translations) ;; 139 inner_statement_list -> (inner_statement_list inner_statement) (puthash