branch: externals/eglot commit fdd87b7dbb5730a82c908e0dae26f82d8c84207e Author: João Távora <joaotav...@gmail.com> Commit: João Távora <joaotav...@gmail.com>
Don't return poorly supported "special elements" in eglot-imenu 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: https://github.com/IvanMalison/flimenu/issues/6 https://github.com/bmag/imenu-list/issues/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 --- NEWS.md | 11 +++++++++++ eglot.el | 52 +++++++++++++++++++++++++--------------------------- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/NEWS.md b/NEWS.md index 7fb4b49992..6ee49d46ca 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,13 @@ # (upcoming) +##### `eglot-imenu` no longer uses problematic "special elements" ([#758][github#758], [#536][github#536], [#535][github#535]) + +Though Eglot's `eglot-imenu` returned a fully compliant `imenu` +structure, that object was not understood by many other frontends +other than `M-x imenu` itself. Since the special functionality it +enabled wasn't being used anyway, decided to remove it to fix these +longstanding problems. + ##### `eglot-workspace-configuration` can be a function ([#967][github#967]) ##### C-u M-. lists and completes arbitrary workspace symbols ([#131][github#131]) @@ -360,6 +368,8 @@ and now said bunch of references--> [github#463]: https://github.com/joaotavora/eglot/issues/463 [github#481]: https://github.com/joaotavora/eglot/issues/481 [github#494]: https://github.com/joaotavora/eglot/issues/494 +[github#535]: https://github.com/joaotavora/eglot/issues/535 +[github#536]: https://github.com/joaotavora/eglot/issues/536 [github#603]: https://github.com/joaotavora/eglot/issues/603 [github#637]: https://github.com/joaotavora/eglot/issues/637 [github#643]: https://github.com/joaotavora/eglot/issues/643 @@ -374,6 +384,7 @@ and now said bunch of references--> [github#742]: https://github.com/joaotavora/eglot/issues/742 [github#750]: https://github.com/joaotavora/eglot/issues/750 [github#751]: https://github.com/joaotavora/eglot/issues/751 +[github#758]: https://github.com/joaotavora/eglot/issues/758 [github#769]: https://github.com/joaotavora/eglot/issues/769 [github#787]: https://github.com/joaotavora/eglot/issues/787 [github#792]: https://github.com/joaotavora/eglot/issues/792 diff --git a/eglot.el b/eglot.el index 8088490363..2ac9b0dff6 100644 --- a/eglot.el +++ b/eglot.el @@ -2916,39 +2916,37 @@ for which LSP on-type-formatting should be requested." nil))) (defun eglot-imenu () - "EGLOT's `imenu-create-index-function'." + "EGLOT's `imenu-create-index-function'. +Returns a list as described in docstring of `imenu--index-alist'." (cl-labels - ((visit (_name one-obj-array) - (imenu-default-goto-function - nil (car (eglot--range-region - (eglot--dcase (aref one-obj-array 0) - (((SymbolInformation) location) - (plist-get location :range)) - (((DocumentSymbol) selectionRange) - selectionRange)))))) - (unfurl (obj) - (eglot--dcase obj - (((SymbolInformation)) (list obj)) - (((DocumentSymbol) name children) - (cons obj - (mapcar - (lambda (c) - (plist-put - c :containerName - (let ((existing (plist-get c :containerName))) - (if existing (format "%s::%s" name existing) - name)))) - (mapcan #'unfurl children))))))) + ((unfurl (obj) + (eglot--dcase obj + (((SymbolInformation)) (list obj)) + (((DocumentSymbol) name children) + (cons obj + (mapcar + (lambda (c) + (plist-put + c :containerName + (let ((existing (plist-get c :containerName))) + (if existing (format "%s::%s" name existing) + name)))) + (mapcan #'unfurl children))))))) (mapcar (pcase-lambda (`(,kind . ,objs)) (cons (alist-get kind eglot--symbol-kind-names "Unknown") (mapcan (pcase-lambda (`(,container . ,objs)) - (let ((elems (mapcar (lambda (obj) - (list (plist-get obj :name) - `[,obj] ;; trick - #'visit)) - objs))) + (let ((elems (mapcar + (lambda (obj) + (cons (plist-get obj :name) + (car (eglot--range-region + (eglot--dcase obj + (((SymbolInformation) location) + (plist-get location :range)) + (((DocumentSymbol) selectionRange) + selectionRange)))))) + objs))) (if container (list (cons container elems)) elems))) (seq-group-by (lambda (e) (plist-get e :containerName)) objs))))