Subject: Re: bug#70614: Wrong simple imenu definition for java

From: Yuan Fu <[email-masked]>
Date: Mon, 29 Apr 2024 22:06:30 -0700

> On Apr 27, 2024, at 11:45 AM, Benjamin Leis via Bug reports for GNU Emacs, the Swiss army knife of text editors <[email-masked]> wrote:
> 
> I noticed the treesitter imenu definitions for java in java-ts-mode.el have the following:
>    ;; Imenu.
>   (setq-local treesit-simple-imenu-settings
>               '(("Class" \\`class_declaration\\' nil nil)
>                 ("Interface" \\`interface_declaration\\' nil nil)
>                 ("Enum" \\`record_declaration\\' nil nil)
>                 ("Method" \\`method_declaration\\' nil nil)))
>   (treesit-major-mode-setup))
>    The 3rd definition for enums should either be for “Record” if that was the intention or match against \\`enum_declaration   if it really was meant for enums.
>  Ben

Thanks for reporting that! Is that you who posted this post on reddit?

https://www.reddit.com/r/emacs/comments/1cej9fr/hierarchical_treesitter_based_imenulist_with_java/

It looks pretty nice, do you want to just put it in Emacs? Also, there’s a chance that your code can be simplified by using treesit-induce-sparse-tree. You can look at treesit-simple-imenu for now it’s used. Basically we use treesit-induce-sparse-tree to find all the interesting nodes in the buffer, and go through the returned tree to convert nodes into imenu labels.

Also CCing Theo; Theo, WDYT?

Yuan