1

I feel like something is wrong with my Imenu setup, because here is what it shows on a simple Python script:

enter image description here

It seems to show some variable definitions, but doesn't have separate entries for the function definitions (the def ... lines), or the classes. What I want is an Imenu that shows just the function and class definitions, in the order in which they appear. So, I want to see something like:

Function: foo(x)
Class: Bar
Function: Bar / __init__(s)
Function: Bar / buz(x, y)

Is that possible at all? Semantic is not an option because it does not parse functions that are typed using Python's type annotations (e.g. a function like def foo() -> None: ... does not appear in the list).

Drew
  • 75,699
  • 9
  • 109
  • 225
space_voyager
  • 709
  • 5
  • 19

2 Answers2

1

For any imenu problem, check the buffer's how-to-generate-imenu status (which is usually modified by major-mode, sometimes also some minor modes), mostly variable imenu-create-index-function and imenu-generic-expression:

  • if imenu-create-index-function is imenu-default-create-index-function, which is Emacs default, the imenu is generated by running the regexps in imenu-generic-expression against buffer content, then you only need to tweak the regexps.
  • if imenu-create-index-function is NOT imenu-default-create-index-function, then you need to dive into the actual value of imenu-create-index-function (which is a function, probably written and set by major mode) to see what's actually going wrong.
JJPandari
  • 251
  • 1
  • 9
  • How do I check the how-to-generate-imenu status? – space_voyager Oct 12 '20 at 19:12
  • C-h v (`describe-variable`) to check the values of the 2 variables I mentioned above (also read the documents there, which along with my answer above should give you the idea of how imenu works). – JJPandari Oct 13 '20 at 02:55
0

This is lsp-mode issue, which was reported and closed as wont fix. I have a better idea of how to fix it, so you may open issue lsp-mode bug tracker.