Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Make eglot works with speedbar #536

Closed
BooAA opened this issue Sep 8, 2020 · 6 comments
Closed

[Feature request] Make eglot works with speedbar #536

BooAA opened this issue Sep 8, 2020 · 6 comments

Comments

@BooAA
Copy link

BooAA commented Sep 8, 2020

Speedbar can use imenu to get definitions in a file and display them as tags. (if the return value of imenu-create-index-function is of the from (INDEX-NAME POSITION), speedbar can handle this for free) However, when I tried using speedbar with eglot, speedbar complained "speedbar-insert-generic-list: malformed list!" since it didn't know how to insert the result of eglot-imenu as tags.

It might be useful to make eglot work with speedbar so that we will have tree-like structure to show major definitions for each file.

@arbv
Copy link

arbv commented Nov 20, 2020

That would be a good addition. Speedbar is very handy when working with files with a lot of definitions.

@joaotavora
Copy link
Owner

Or maybe speedbar can understand the correct format of imenu. Eglot is doing nothing more than follow the established format:

imenu--index-alist is a variable defined in `imenu.el'.
Its value is nil

  Automatically becomes buffer-local when set.
  This variable may be risky if used as a file-local variable.

Documentation:
The buffer index alist computed for this buffer in Imenu.

Simple elements in the alist look like (INDEX-NAME . POSITION).
POSITION is the buffer position of the item; to go to the item
is simply to move point to that position.

POSITION is passed to `imenu-default-goto-function', so it can be
a non-number if that variable has been changed (e.g. Semantic
uses overlays for POSITIONs).

Special elements look like
(INDEX-NAME POSITION FUNCTION ARGUMENTS...).
To "go to" a special element means applying FUNCTION to
INDEX-NAME, POSITION, and the ARGUMENTS.

A nested sub-alist element looks like (INDEX-NAME . SUB-ALIST).
The function `imenu--subalist-p' tests an element and returns t
if it is a sub-alist.

There is one simple element with negative POSITION; selecting that
element recalculates the buffer's index alist.

@joaotavora
Copy link
Owner

A now-deleted I received this morning by one "Tom F" stated the following:

"sb-imenu as described in https://stackoverflow.com/a/36893492 can do this. I'm using eglot with it."

@BooAA
Copy link
Author

BooAA commented Dec 15, 2020

"sb-imenu as described in https://stackoverflow.com/a/36893492 can do this. I'm using eglot with it."

After (require 'sb-imenu) and (setq speedbar-initial-expansion-list-name "sb-imenu") according to the comment in that stackoverflow question, I got speedbar display imenu index correctly

Screenshot_2020-12-15_19-12-16

But when I click or press return on the item, it reports error:

funcall-interactively: Wrong number of arguments: (lambda (text node indent) "Goto the current tag." (interactive) (condition-case nil (progn (speedbar-select-attached-frame) (raise-frame) (select-frame-set-input-focus (selected-frame))) (error nil)) (switch-to-buffer sb-imenu-active-buffer) (goto-char node)), 0

@joaotavora
Copy link
Owner

That probably explains why the poster deleted the comment. Get someone with Elisp skills to fix speedbar-imenu. Maybe talk to its author. It shouldn't be hard, but unfortunately, I have no time for this.

I do know that M-x imenu works.That's the thing that exists in Emacs, and that's what I'm coding for. Other extensions must also code for Emacs, then they will work with Eglot.

@BooAA
Copy link
Author

BooAA commented Jul 17, 2021

@joaotavora Below is my attempt to make eglot-imenu work with speedbar by transform the complex alist form to the simple form.

;; borrow from eglot-imenu
(defun eglot-imenu-get-point (one-obj-array)
  (car (eglot--range-region
        (eglot--dcase (aref one-obj-array 0)
          (((SymbolInformation) location)
           (plist-get location :range))
          (((DocumentSymbol) selectionRange)
           selectionRange)))))

(defun eglot-imenu-to-simple-form (menu)
  (cl-loop for form in menu
           collect (cons (car form)
                         (if (imenu--subalist-p form)
                             (eglot-imenu-to-simple-form (cdr form))
                           (eglot-imenu-get-point (cadr form))))))

(advice-add #'eglot-imenu :filter-return #'eglot-imenu-to-simple-form)

;; optional, prevent speedbar from creating additional tags for long entries
(setq speedbar-tag-regroup-maximum-length 100)

Testing on linux kernel with clangd, looks ok to me:
eglot_with_speedbar

I've made a bug report to ask support for complex imenu form in speedbar, see https://lists.gnu.org/archive/html/bug-gnu-emacs/2021-06/msg01058.html.

joaotavora added a commit that referenced this issue Sep 8, 2022
Fix #758, #536, #535.

Eglot's eglot-imenu returned a structure compliant with the rules
outlined in imenu--index-alist.  In particular, it returned some
elements of the form

  (INDEX-NAME POSITION GOTO-FN ARGUMENTS...)

The original intention (mine) must have been to allow fancy
highlighting of the position navigated to with a custom GOTO-FN.

Not only was access to that fanciness never implemented, but many
other imenu frontends do not support such elements.

See for example #758, #536, #535.  And also related issues in other
packages:

colonelpanic8/flimenu#6
bmag/imenu-list#58

So it's best to remove this problematic feature for now.  It can be
added back later.

* eglot.el (eglot-imenu): Simplify.

* NEWS.md: Mention change
bhankas pushed a commit to bhankas/emacs that referenced this issue Sep 18, 2022
Fix joaotavora/eglot#758, joaotavora/eglot#536, joaotavora/eglot#535.

Eglot's eglot-imenu returned a structure compliant with the rules
outlined in imenu--index-alist.  In particular, it returned some
elements of the form

  (INDEX-NAME POSITION GOTO-FN ARGUMENTS...)

The original intention (mine) must have been to allow fancy
highlighting of the position navigated to with a custom GOTO-FN.

Not only was access to that fanciness never implemented, but many
other imenu frontends do not support such elements.

See for example joaotavora/eglot#758, joaotavora/eglot#536, joaotavora/eglot#535.  And also related issues in other
packages:

colonelpanic8/flimenu#6
bmag/imenu-list#58

So it's best to remove this problematic feature for now.  It can be
added back later.

* eglot.el (eglot-imenu): Simplify.

* NEWS.md: Mention change
bhankas pushed a commit to bhankas/emacs that referenced this issue Sep 19, 2022
Fix joaotavora/eglot#758, joaotavora/eglot#536, joaotavora/eglot#535.

Eglot's eglot-imenu returned a structure compliant with the rules
outlined in imenu--index-alist.  In particular, it returned some
elements of the form

  (INDEX-NAME POSITION GOTO-FN ARGUMENTS...)

The original intention (mine) must have been to allow fancy
highlighting of the position navigated to with a custom GOTO-FN.

Not only was access to that fanciness never implemented, but many
other imenu frontends do not support such elements.

See for example joaotavora/eglot#758, joaotavora/eglot#536, joaotavora/eglot#535.  And also related issues in other
packages:

colonelpanic8/flimenu#6
bmag/imenu-list#58

So it's best to remove this problematic feature for now.  It can be
added back later.

* eglot.el (eglot-imenu): Simplify.

* NEWS.md: Mention change
bhankas pushed a commit to bhankas/emacs that referenced this issue Sep 19, 2022
Fix #758, #536, #535.

Eglot's eglot-imenu returned a structure compliant with the rules
outlined in imenu--index-alist.  In particular, it returned some
elements of the form

  (INDEX-NAME POSITION GOTO-FN ARGUMENTS...)

The original intention (mine) must have been to allow fancy
highlighting of the position navigated to with a custom GOTO-FN.

Not only was access to that fanciness never implemented, but many
other imenu frontends do not support such elements.

See for example #758, #536, #535.  And also related issues in other
packages:

colonelpanic8/flimenu#6
bmag/imenu-list#58

So it's best to remove this problematic feature for now.  It can be
added back later.

* eglot.el (eglot-imenu): Simplify.

* NEWS.md: Mention change

#758: joaotavora/eglot#758
#536: joaotavora/eglot#536
#535: joaotavora/eglot#535
#758: joaotavora/eglot#758
#536: joaotavora/eglot#536
#535: joaotavora/eglot#535
jollaitbot pushed a commit to sailfishos-mirror/emacs that referenced this issue Oct 12, 2022
Fix joaotavora/eglot#758, joaotavora/eglot#536, joaotavora/eglot#535.

Eglot's eglot-imenu returned a structure compliant with the rules
outlined in imenu--index-alist.  In particular, it returned some
elements of the form

  (INDEX-NAME POSITION GOTO-FN ARGUMENTS...)

The original intention (mine) must have been to allow fancy
highlighting of the position navigated to with a custom GOTO-FN.

Not only was access to that fanciness never implemented, but many
other imenu frontends do not support such elements.

See for example joaotavora/eglot#758, joaotavora/eglot#536, joaotavora/eglot#535.  And also related issues in other
packages:

colonelpanic8/flimenu#6
bmag/imenu-list#58

So it's best to remove this problematic feature for now.  It can be
added back later.

* eglot.el (eglot-imenu): Simplify.

* NEWS.md: Mention change
jollaitbot pushed a commit to sailfishos-mirror/emacs that referenced this issue Oct 20, 2022
Fix joaotavora/eglot#758, joaotavora/eglot#536, joaotavora/eglot#535.

Eglot's eglot-imenu returned a structure compliant with the rules
outlined in imenu--index-alist.  In particular, it returned some
elements of the form

  (INDEX-NAME POSITION GOTO-FN ARGUMENTS...)

The original intention (mine) must have been to allow fancy
highlighting of the position navigated to with a custom GOTO-FN.

Not only was access to that fanciness never implemented, but many
other imenu frontends do not support such elements.

See for example joaotavora/eglot#758, joaotavora/eglot#536, joaotavora/eglot#535.  And also related issues in other
packages:

colonelpanic8/flimenu#6
bmag/imenu-list#58

So it's best to remove this problematic feature for now.  It can be
added back later.

* eglot.el (eglot-imenu): Simplify.

* NEWS.md: Mention change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants