Skip to content

Bug with lsp imenu processing (maybe golang only?) #659

@jtl5770

Description

@jtl5770

Thank you for the bug report

  • I am using the latest version of lsp-mode related packages.
  • I checked FAQ and Troubleshooting sections
  • You may also try reproduce the issue using clean environment using the following command
emacs -q -l lsp-start-plain.el

where lsp-start-plain.el can be downloaded here.

Bug description

Using lsp-ui-imenu, while editing golang files, I encountered the following problem: Please note how the Sensor struct is printed before the "Structs" header corrupting the display.

Screenshot-lsp-ui-imenu

This happens whenever the custom option lsp-imenu-index-function is different from it's default value lsp-imenu-create-uncategorized-index (in this case: lsp-imenu-create-top-level-categorized-index, but similar looking with lsp-imenu-categorized-index). Note the following image where it is set to this default value:

Screenshot-lsp-ui-imenu-index-function:uncategorized

Here it is essentially correct, but ofc missing lots of structural information.

Comparing this to lsp-treemacs-symbols, it seems that this ignores the value of the lsp-imenu-index-function, it always looks like this:

Screenshot-lsp-treemacs-symbols

essentially the same as the information of the default lsp-ui-imenu display.
Interestingly, trying to use the main lsp-treemacs display to click down into the file structure also reveals some weird display and behavior:

Screenshot-lsp-treemacs-main

one can see, that here the Sensor and Trigger structs are inserted as part of a "Functions" parent, which clearly is wrong. Maybe this is related to the same root cause of not being able to process tree of symbols correctly.

Steps to reproduce

I have attached a small self contained main package go file that I have used to try out some stuff while learning the language :-) it shows the same problem when setting lsp-imenu-index-function to lsp-imenu-categorized-index

Just open it with gopls server installed and use lsp-ui-imenu.

main.zip

Expected behavior

The expected behavior of lsp-ui-imenu is to construct the symbol tree correctly even when setting lsp-imenu-index-function to e.g. lsp-imenu-create-categorized-index.

Even better: lsp-treemacs-symbols respects that variable (and constructs a correct tree), and lsp-treemacs main display would not generate weird parent/child relations.

In the long run, a good solution would also group the methods belonging to one struct together with/below this struct, instead of lumping together all functions and methods.

Which Language Server did you use?

gopls

OS

Linux

Error callstack

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions