all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#59945: [PATCH] Fix empty pairs in js tree-sitter imenu alist
@ 2022-12-10 17:17 Charl P. Botha
  2022-12-12 22:28 ` Yuan Fu
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Charl P. Botha @ 2022-12-10 17:17 UTC (permalink / raw)
  To: 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 | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 45dfef372cd..6ca260ad8ad 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3732,10 +3732,17 @@ js--treesit-imenu
          (func-tree (treesit-induce-sparse-tree
                      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)))))
+                    node "lexical_declaration" nil 1000))
+         (imenu-alist nil))
+    ;; when a sub-tree is empty, we should not return that pair at all
+    ;; https://github.com/minad/consult/issues/697#issuecomment-1345302734
+    (when func-tree
+      (setq imenu-alist (cons `("Function" . ,(js--treesit-imenu-1 func-tree)) imenu-alist)))
+    (when var-tree
+      (setq imenu-alist (cons `("Variable" . ,(js--treesit-imenu-1 var-tree)) imenu-alist)))
+    (when class-tree
+      (setq imenu-alist (cons `("Class" . ,(js--treesit-imenu-1 class-tree)) imenu-alist)))
+    imenu-alist))

 ;;; Main Function

--
2.25.1





^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2022-12-22  8:10 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-10 17:17 bug#59945: [PATCH] Fix empty pairs in js tree-sitter imenu alist Charl P. Botha
2022-12-12 22:28 ` Yuan Fu
2022-12-13  7:48   ` Charl P. Botha
2022-12-13 12:40     ` Eli Zaretskii
2022-12-13 12:03   ` Eli Zaretskii
2022-12-15  9:13     ` Charl P. Botha
2022-12-15 10:41       ` Eli Zaretskii
2022-12-16  1:40 ` Yuan Fu
2022-12-16  5:58   ` Charl P. Botha
2022-12-16 14:11     ` Robert Pluim
2022-12-16 17:52       ` Charl P. Botha
2022-12-21  4:48 ` Yuan Fu
2022-12-21 10:15   ` Charl P. Botha
2022-12-21 17:25   ` Robert Pluim
2022-12-22  8:10     ` Yuan Fu

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.