From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.bugs Subject: bug#58431: 29.0.50; [Eglot] Add "breadcrumb.el" feature based on imenu.el/project.el services Date: Tue, 11 Oct 2022 23:22:48 -0700 Message-ID: References: <87czayra73.fsf@gmail.com> <21C0D090-6EE1-45EB-B23A-8BECDD5A9447@gmail.com> <87ilkpq5se.fsf@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19953"; mail-complaints-to="usenet@ciao.gmane.io" Cc: eliz@gnu.org, 58431@debbugs.gnu.org To: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Oct 12 08:24:48 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oiVAe-00054C-6F for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 12 Oct 2022 08:24:48 +0200 Original-Received: from localhost ([::1]:44272 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oiVAc-0000xz-HG for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 12 Oct 2022 02:24:46 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33466) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiV8w-0000wl-Q1 for bug-gnu-emacs@gnu.org; Wed, 12 Oct 2022 02:23:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:56327) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oiV8w-0001YP-HF for bug-gnu-emacs@gnu.org; Wed, 12 Oct 2022 02:23:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oiV8w-0004pR-9z for bug-gnu-emacs@gnu.org; Wed, 12 Oct 2022 02:23:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 12 Oct 2022 06:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58431 X-GNU-PR-Package: emacs Original-Received: via spool by 58431-submit@debbugs.gnu.org id=B58431.166555578118539 (code B ref 58431); Wed, 12 Oct 2022 06:23:02 +0000 Original-Received: (at 58431) by debbugs.gnu.org; 12 Oct 2022 06:23:01 +0000 Original-Received: from localhost ([127.0.0.1]:55405 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oiV8u-0004ox-F7 for submit@debbugs.gnu.org; Wed, 12 Oct 2022 02:23:00 -0400 Original-Received: from mail-pj1-f47.google.com ([209.85.216.47]:46966) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oiV8p-0004og-Ni for 58431@debbugs.gnu.org; Wed, 12 Oct 2022 02:22:58 -0400 Original-Received: by mail-pj1-f47.google.com with SMTP id t12-20020a17090a3b4c00b0020b04251529so1099845pjf.5 for <58431@debbugs.gnu.org>; Tue, 11 Oct 2022 23:22:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=eBIuxBPm4ZVWLfLu3OOZpPvSZwJhYTJ0UBE/ve4EMy0=; b=T8yWyp7WKYwIRtKLjbI+oXrfG7gi9XOfS6pH9F8aHsNGY3DigBYBGDLIzsiq0XxSE+ HpDHYOvjF6WJtvmFcbMA6kVjiSOReOyQjXYQnAgWgJeFrk5DZxOTqDaXBEYr0TLQd6fO 0aGfc9FwtPuDTY9My6+5EpcUd4i5u+oH4xFkLic/VrEY/ke74b9V7HFWe6vRP6Tkks4N UTALJ6H9ju9XyvHwrSbm3hOL4GbOsnLsfwmqwXedewioOAtyClvfD0b61Y0R2EIOzugo quL8mH/RtA4J0VgwBVHQQSL6APJoTaDWysXTem2VIOuOMWFd/uJbeSbtrGJik/LF/E1o EiZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eBIuxBPm4ZVWLfLu3OOZpPvSZwJhYTJ0UBE/ve4EMy0=; b=ACFOyih+tOiQDwonhfFIIBbMlLO1Gn+99KAgIxEVA/C2bbJmkgdBowZ1qjoZ4wHS+O Nq9259TKrslh0AeR3F3wdtcDog7o9UxTIB5dJCADgRxjr9oRH4HffRTCTz43xFvRGMaz /B8dbis2oaCeoKXhUKFA8rTMtC5cxdA9N3IeZeRpRORAiWjgw0RG2JmYNoxn7fl2eZGu AYhPrN0IdRYq57rsUiL4AoQAJTAO7Je5ILNFodieboaj6H+k5Fdsa1PgO5DXGygiPC/L 3L4SKvgokA2RsexFMGKFMp63rIbj0x9nc4eXZcAC7CXJcTrtX6XcvR7p0B3KtZt8R3IW N+KQ== X-Gm-Message-State: ACrzQf1EX6cGPMP4ihjP9OE4Pk29L72EWnVGKDBT9aBNpvTIpgoazQb4 N5dbLNrZQrjU36oEtTWQbi3xaRIXP6l/eQ== X-Google-Smtp-Source: AMsMyM6VmP8Rwo/IESmJIgeQa2aY79gZh+5vC4JAdlcbs6B/IiAqRYDv7yQtJ4EP6D0B0qnmaDJ4Mg== X-Received: by 2002:a17:903:2284:b0:178:349b:d21b with SMTP id b4-20020a170903228400b00178349bd21bmr28290586plh.49.1665555769717; Tue, 11 Oct 2022 23:22:49 -0700 (PDT) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id j6-20020a170903024600b00178a9b193cfsm9781404plh.140.2022.10.11.23.22.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Oct 2022 23:22:49 -0700 (PDT) In-Reply-To: <87ilkpq5se.fsf@gmail.com> X-Mailer: Apple Mail (2.3696.120.41.1.1) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:245162 Archived-At: > On Oct 11, 2022, at 4:50 PM, Jo=C3=A3o T=C3=A1vora = wrote: >=20 > Yuan Fu writes: >=20 >>> 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. >>>=20 >>> Eglot already integrates with Imenu, so as soon as this hypothetical >>> breadcrumb.el is in place, then Eglot users can take advantage of = it. >>>=20 >>> 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. >>=20 >> 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. >=20 > I think there is a slight misunderstanding here. >=20 > The information stored in imenu is what which-func.el uses by default. > See this comment in which-func.el >=20 > ;; 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. >=20 > Moreover, imenu--index-alist is not a list, but a tree (of which a = flat > list is a particular case). >=20 > 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. >=20 > 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. >=20 > Let's use some M-x artist-mode magic to explain what is in place > and what I am proposing. >=20 > +---+----+ +---------+ +----------+ > |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)|<------------=20 > o-------------------o >=20 > 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. >=20 > 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. >=20 > 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. >=20 >> 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 >> =E2=80=9C/=E2=80=9C. >=20 > 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. >=20 > 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. >=20 > breadcrumb.el would be such a client, that would work in your > tree-sitter powered python mode and in many other contexts. >=20 > Jo=C3=A3o Thanks for your explanation! I didn=E2=80=99t know which-func can just = use imenu--index-alist. I already have support for imenu, just need to = let which-func do its thing.=20 What you said for breakcumb.el makes total sense. It sounds pretty = straightforward, just get file path from project.el and function path = from imenu and put them together. I can work on it later if no one come = around and adopt it, I=E2=80=99ve got a lot of stuff on my plate already = ;-) Yuan