unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Sebastian Poeplau via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 69657@debbugs.gnu.org
Subject: bug#69657: Missing imenu entries with eglot
Date: Fri, 08 Mar 2024 21:01:24 +0100	[thread overview]
Message-ID: <87frx0ze5n.fsf@mailbox.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 883 bytes --]

For language servers that reply to the textDocument/documentSymbol
request with instances of DocumentSymbol rather than SymbolInformation,
eglot's imenu builder omits symbols containing other symbols. This
applies to eglot 1.17 from ELPA as well as the version in Emacs master
as of today.

You can use clangd to reproduce the problem:

1. Put this code in a C++ source file, e.g., test.cpp:

   class Foo {
     void bar() {}
   };

2. Start eglot with clangd.
3. Invoke imenu; there will be a single entry "bar", nested under "Foo".
   In particular, there is no entry that lets you jump to Foo.

This is inconsistent with how eglot handles language servers that return
SymbolInformation (e.g., pylsp), and I would argue that it's not what
users expect. The attached patch fixes the behavior by inserting a
dedicated entry for each symbol in addition to entries for its children.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Eglot-include-containers-in-imenu.patch --]
[-- Type: text/x-diff, Size: 1731 bytes --]

From 953372f4cb1eea435a21a66e72226c7b2a6be51b Mon Sep 17 00:00:00 2001
From: Sebastian Poeplau <sebastian.poeplau@mailbox.org>
Date: Fri, 8 Mar 2024 16:29:25 +0100
Subject: [PATCH] Eglot: include containers in imenu

When the language server provides symbols as instances of
DocumentSymbol, eglot now includes containers (i.e., symbols with
children) in the imenu listing. This is consistent with eglot's behavior
when symbols are given as SymbolInformation objects.

* lisp/progmodes/eglot.el (eglot--imenu-DocumentSymbol): Include an
entry for symbols with children.
---
 lisp/progmodes/eglot.el | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index f341428cac3..87366811efd 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -3454,10 +3454,13 @@ for which LSP on-type-formatting should be requested."
                                          'breadcrumb-region reg
                                          'breadcrumb-kind kind)))
                   (if (seq-empty-p children)
-                      (cons name (car reg))
-                    (cons name
-                            (mapcar (lambda (c) (apply #'dfs c)) children))))))
-    (mapcar (lambda (s) (apply #'dfs s)) res)))
+                      (list (cons name (car reg)))
+                    (list (cons name (car reg))
+                          (cons name
+                                (mapcan (lambda (c)
+                                          (apply #'dfs c))
+                                        children)))))))
+    (mapcan (lambda (s) (apply #'dfs s)) res)))
 
 (cl-defun eglot-imenu ()
   "Eglot's `imenu-create-index-function'.
-- 
2.43.2


             reply	other threads:[~2024-03-08 20:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-08 20:01 Sebastian Poeplau via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-03-08 21:44 ` bug#69657: Missing imenu entries with eglot Felician Nemeth
2024-03-08 22:28   ` Sebastian Poeplau via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-09 16:20     ` Felician Nemeth
2024-03-10  1:05       ` João Távora
2024-03-10 16:15         ` Sebastian Poeplau via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-10 19:15           ` Sebastian Poeplau via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-10 19:33             ` João Távora
2024-03-17 11:04               ` Sebastian Poeplau via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87frx0ze5n.fsf@mailbox.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=69657@debbugs.gnu.org \
    --cc=sebastian.poeplau@mailbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).