GNU bug report logs -
#59945
[PATCH] Fix empty pairs in js tree-sitter imenu alist
Previous Next
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your message dated Tue, 20 Dec 2022 20:48:58 -0800
with message-id <7B3A9410-A4E4-4B32-83CE-FADB9588C7A7 <at> gmail.com>
and subject line Re: bug#59945: [PATCH] Fix empty pairs in js tree-sitter imenu alist
has caused the debbugs.gnu.org bug report #59945,
regarding [PATCH] Fix empty pairs in js tree-sitter imenu alist
to be marked as done.
(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)
--
59945: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=59945
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
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
[Message part 3 (message/rfc822, inline)]
"Charl P. Botha" <cpbotha <at> vxlabs.com> writes:
> On Fri, Dec 16, 2022, at 16:11, Robert Pluim wrote:
>>>>>>> On Fri, 16 Dec 2022 07:58:46 +0200, "Charl P. Botha" <cpbotha <at> vxlabs.com> said:
>> Charl> I followed the instructions at
>> Charl>
>> https://www.gnu.org/software/emacs/manual/html_node/emacs/Sending-Patches.html
>> Charl> which said to use "git format-patch master" and include
>> either inline
>> Charl> (which I did) or as a mime attachment.
>>
>> Not quite. You sent the result of 'git format-patch master' as an
>> email, not inline in an email (presumably with 'git send-email'). That
>> shouldnʼt matter, because 'git apply' should work in either case, but
>> attachments are sometimes easier to work with.
>
> Thank you for the correction, Robert! I thought that sending the
> output of `git format-patch master` as a plain-text email was what was
> meant by "inline". I'm sorry about this, I'll stick to attachments in
> the future.
Not really about attachment vs inline. The first patch doesn’t have
author, commit message, etc. I’m fine with either attachment or inline
:-)
> Yuan, can you confirm that the patch I eventually attached is OK?
Thanks! I applied your patch. I made a little change to it so it’s more
idiomatic.
Elisp tip of the day: if you want to make a list of possibly nil objects
and don’t want nil’s in the list, you can use append. Basically change
(list a b c)
to
(append (and xxx (list a)) (and yyy (list b)) (and zzz (list c)))
If the condition aren’t met, eg, (and xxx (list a)) returns nil, append
just appends an empty list.
Yuan
This bug report was last modified 2 years and 155 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.