all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "João Távora" <joaotavora@gmail.com>
To: Yuan Fu <casouri@gmail.com>
Cc: eliz@gnu.org, 58431@debbugs.gnu.org
Subject: bug#58431: 29.0.50; [Eglot] Add "breadcrumb.el" feature based on imenu.el/project.el services
Date: Wed, 12 Oct 2022 00:50:09 +0100	[thread overview]
Message-ID: <87ilkpq5se.fsf@gmail.com> (raw)
In-Reply-To: <21C0D090-6EE1-45EB-B23A-8BECDD5A9447@gmail.com> (Yuan Fu's message of "Tue, 11 Oct 2022 08:38:30 -0700")

Yuan Fu <casouri@gmail.com> writes:

>> In the original Eglot request, users are requesting this UI feature for
>> the Eglot LSP client.  But this doesn't have any LSP-specific
>> interactions.  It can and should be done entirely by using the services
>> provided by imenu.el and project.el.
>>
>> Eglot already integrates with Imenu, so as soon as this hypothetical
>> breadcrumb.el is in place, then Eglot users can take advantage of it.
>>
>> This is similar to which-func.el, which displays the trailing element of
>> the breadcrumb in the headerline.  Perhaps the breadcrumb feature can be
>> thought of as an augmentation of which-func.el's functionality.  I don't
>> have a strong opinion there.
>
> I think which-func is closer to breadcrumb conceptually and api-wise:
> Both which-func and breadcrumb are about the current function, while
> imenu is about a list of _all_ functions/sections.

I think there is a slight misunderstanding here.

The information stored in imenu is what which-func.el uses by default.
See this comment in which-func.el

   ;; This package prints name of function where your current point is
   ;; located in mode line.  It assumes that you work with the imenu
   ;; package and `imenu--index-alist' is up to date.

Moreover, imenu--index-alist is not a list, but a tree (of which a flat
list is a particular case).

M-x which-function-mode works for any Eglot-managed buffer, but Eglot
doesn't have any code specific to which-func.el.  How can this be?
Well, Eglot stores the tree information is gets from LSP in Imenu's
imenu--index-alist and that information serves many Imenu frontends --
which-func.el being just one of them.

Moreover, the breadcrumb that the Eglot user is requesting -- and which
I am describing in detail -- also needs information that is owned by
project.el, namely the project root.

Let's use some M-x artist-mode magic to explain what is in place
and what I am proposing.

+---+----+   +---------+     +----------+
|eglot.el|   |python.el|     | ruby.el  |
+---+----+   +---+-----+     +----+-----+
    |            |                |
    |            |                |
    |            v                |
    |        +----------+         |
    +------->| imenu.el |<--------+
             +-+--------+
               |
+--------------+
|
|  +-------------------+
\->|which-func.el      |
|  |(already working)  |
|  +-------------------+
|
|  +-------------------+
\->|speedbar.el        |
|  |(also working)     |
|  +-------------------+
|
|  +-------------------+
\->|...                |
|  +-------------------+         +--------------+
|                                |  project.el  |
|  o-------------------o         +--------------+
\->|breadcrumb.el      |             /
   |(proposed addition)|<------------ 
   o-------------------o

So, Eglot already stores its LSP-gathered information "inside" imenu's
data structures using imenu-create-index-function.  As does the current
python.el, ruby.el, antlr-mode.el, cc-mode and many others when they are
used without Eglot.

which-func.el get this information from imenu and uses it for the limited
purpose of showing only the leaf of the tree where the point is at.

breadcrumb.el would function similarly, but instead use it to show the
_full path_ of that tree up until the leaf of the tree where the point
is at.  It would then prepend the path to the file by getting it from
project.el.

> which-func-function to accept a list of function names. In fact, the
> which-func function of tree-sitter powered python.el already generates
> a breadcrumb, I just joined all the function names along the path with
> “/“.

You can use that strategy in your new Python mode, but it seems
misguided to me.  You'll be supporting which-func.el directly instead of
indirectly, thus missing out on other imenu-using client frontends like
speedbar, "treemacs", M-x imenu or others.  They will not work
out-of-the-box with your new mode.

Therefore, my advice is that you keep the tree structure you get from
tree-sitter intact and stored in imenu--index-alist via
imenu-create-index-function -- see the docstring imenu--index-alist --
then let the imenu clients compose a breadcrumb iff they so desire.

breadcrumb.el would be such a client, that would work in your
tree-sitter powered python mode and in many other contexts.

João





  reply	other threads:[~2022-10-11 23:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-11  9:17 bug#58431: 29.0.50; [Eglot] Add "breadcrumb.el" feature based on imenu.el/project.el services João Távora
2022-10-11 15:38 ` Yuan Fu
2022-10-11 23:50   ` João Távora [this message]
2022-10-12  6:22     ` Yuan Fu
2022-10-12  8:30       ` João Távora
2023-05-12 13:09     ` João Távora
2023-05-17 21:31       ` Yuan Fu
2023-04-08 19:47 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-18 18:10 ` bug#58431: 29.0.50; [Eglot] Add "breadcrumb.el" feature based, " Adam Porter
2023-04-18 18:26   ` João Távora
2023-04-20  4:27     ` Adam Porter
2023-04-20  9:22       ` João Távora

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

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

  git send-email \
    --in-reply-to=87ilkpq5se.fsf@gmail.com \
    --to=joaotavora@gmail.com \
    --cc=58431@debbugs.gnu.org \
    --cc=casouri@gmail.com \
    --cc=eliz@gnu.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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.