Hi Yuan

Yes it was me that posted on reddit. I’ll look into the sparse tree method – that looks promising.  I’d be happy to add into the tree. What would the process be for that?

Ben

 

From: Yuan Fu <casouri@gmail.com>
Date: Monday, April 29, 2024 at 10:06
PM
To: Benjamin Leis <benjamin.leis@servicenow.com>
Cc: 70614@debbugs.gnu.org <70614@debbugs.gnu.org>, Theodor Thornhill <theo@thornhill.no>
Subject: Re: bug#70614: Wrong simple imenu definition for java

[External Email]



> On Apr 27, 2024, at 11:45 AM, Benjamin Leis via Bug reports for GNU Emacs, the Swiss army knife of text editors <bug-gnu-emacs@gnu.org> 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