summaryrefslogtreecommitdiff
path: root/lisp/progmodes/js.el
diff options
context:
space:
mode:
authorCharl P. Botha <cpbotha@vxlabs.com>2022-12-10 19:09:38 +0200
committerYuan Fu <casouri@gmail.com>2022-12-20 20:50:50 -0800
commit12b2b8864c295ce27594e8a907ebb3423e58a9d4 (patch)
treea8c66b9a16ca2e840697cc588f93b6b17b71577e /lisp/progmodes/js.el
parent6d9f367ead32c688bcfc6a0366073dff6740099c (diff)
downloademacs-12b2b8864c295ce27594e8a907ebb3423e58a9d4.tar.gz
Fix empty pairs in js tree-sitter imenu alist (bug#59945)
The current js--treesit-imenu, used by the JavaScript, TypeScript and TSX tree-sitter modes, would return empty pairs in the imenu alist if there were none of that type of symbol. This would break both the built in imenu and also packages like consult-imenu. See https://github.com/minad/consult/issues/697 for the discussion there. * lisp/progmodes/js.el (js--treesit-imenu): Don't add nil indexes. Copyright-paperwork-exempt: yes
Diffstat (limited to 'lisp/progmodes/js.el')
-rw-r--r--lisp/progmodes/js.el11
1 files changed, 8 insertions, 3 deletions
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 8c1ee495c2d..1b34c0de418 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3738,9 +3738,14 @@ definition*\"."
node "function_declaration" nil 1000))
(var-tree (treesit-induce-sparse-tree
node "lexical_declaration" nil 1000)))
- `(("Class" . ,(js--treesit-imenu-1 class-tree))
- ("Variable" . ,(js--treesit-imenu-1 var-tree))
- ("Function" . ,(js--treesit-imenu-1 func-tree)))))
+ ;; When a sub-tree is empty, we should not return that pair at all.
+ (append
+ (and func-tree
+ `(("Function" . ,(js--treesit-imenu-1 func-tree))))
+ (and var-tree
+ `(("Variable" . ,(js--treesit-imenu-1 var-tree))))
+ (and class-tree
+ `(("Class" . ,(js--treesit-imenu-1 class-tree)))))))
;;; Main Function