From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Newsgroups: gmane.emacs.bugs 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 Message-ID: <87ilkpq5se.fsf@gmail.com> References: <87czayra73.fsf@gmail.com> <21C0D090-6EE1-45EB-B23A-8BECDD5A9447@gmail.com> Mime-Version: 1.0 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="33124"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: eliz@gnu.org, 58431@debbugs.gnu.org To: Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Oct 12 01:50:10 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 1oiP0k-0008Qv-6I for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 12 Oct 2022 01:50:10 +0200 Original-Received: from localhost ([::1]:59430 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oiP0i-00028w-Nb for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 11 Oct 2022 19:50:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51834) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiP0c-00028o-JS for bug-gnu-emacs@gnu.org; Tue, 11 Oct 2022 19:50:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:56021) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oiP0c-0002CB-8i for bug-gnu-emacs@gnu.org; Tue, 11 Oct 2022 19:50:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oiP0b-0000d6-SF for bug-gnu-emacs@gnu.org; Tue, 11 Oct 2022 19:50:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 11 Oct 2022 23:50:01 +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.16655321542299 (code B ref 58431); Tue, 11 Oct 2022 23:50:01 +0000 Original-Received: (at 58431) by debbugs.gnu.org; 11 Oct 2022 23:49:14 +0000 Original-Received: from localhost ([127.0.0.1]:55099 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oiOzp-0000b1-SZ for submit@debbugs.gnu.org; Tue, 11 Oct 2022 19:49:14 -0400 Original-Received: from mail-wr1-f47.google.com ([209.85.221.47]:46046) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oiOzm-0000aj-BQ for 58431@debbugs.gnu.org; Tue, 11 Oct 2022 19:49:12 -0400 Original-Received: by mail-wr1-f47.google.com with SMTP id a10so23802613wrm.12 for <58431@debbugs.gnu.org>; Tue, 11 Oct 2022 16:49:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rdZCFfxyC7UP6VQV1fWodDoH4yUjcYVikhT0CliBLeA=; b=dO8BpvxccEIsnVkjBch9nrw0/P000kL9h0QDf8oPg3gOsTkGi2VykVaiEpoKpf36Dc w1B5TBgoRn1iKNo6YgDSpXpCUWVAIzYoXFaDd+IG4P4YPeNgBL6r5IpXgvhOJbR8wK8c +J9EFdIbqPr/tgAIzYCkn8Nn9y1k/K+257qZoDW/fXVmmbYwawBF012MEj69LiTQcEXJ NWC6InTwjpkIC4JQGBIfm33v+pjICwP+sGWZpMYiTuWu/dJoApdWAU2IdHRwGHaTOXU5 6zp0jXKDow1xCsCZ3lpR9Vwts4PlqVeFDOFOUdNvvkMzrEMqTj3ADj7HTlIvTG2YFYO3 /9CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=rdZCFfxyC7UP6VQV1fWodDoH4yUjcYVikhT0CliBLeA=; b=WQQW2ifAZmGxzFAwkMF47geJ6oKnrxRpNUohUg5EY1EC7k9yclmM6eqLtXx98Q4goD YpGR4QRsn1YMmjX0vjO8xK+xxklYQlzWMS/aoKuDLeblESfPYP3U9DzXn7vEycs8ErG5 e/Y+hnZ3DhjR3HXHkGGNQPpqZIZnn7bU3Ldt8cLD51hN1sylGBS6nbGfV/HwsQtd3P9a Sc1vyb7L+Tt1dXHJTCWDquRk9HBE8PsvbMx2w/mEyMR2iLuQPZhyU4HEEeSvddoPFNb8 s5KIefTRTQ2XpraOms0iGT0NBsf6rBbWNp+UVEg8kZm9NJ8ZTtAW7RnZPlarZLh7y+p9 d62w== X-Gm-Message-State: ACrzQf2xD7yKRIW5hcEi0cT4CQr/OgHny+SOjX2RYkt3EMY8fH1FzqF3 ptFdD66KwyqKVuFqSnKW9iE= X-Google-Smtp-Source: AMsMyM4+EatvOviu/ofH2cPtHbA+Q6JmsKg8/3RgZ7sjJlrfj+queDSNGU5rzFQIJrTCKjUGw5u7vw== X-Received: by 2002:adf:ee0a:0:b0:22f:6a2a:92ab with SMTP id y10-20020adfee0a000000b0022f6a2a92abmr11428673wrn.545.1665532143237; Tue, 11 Oct 2022 16:49:03 -0700 (PDT) Original-Received: from krug (87-196-72-225.net.novis.pt. [87.196.72.225]) by smtp.gmail.com with ESMTPSA id g11-20020a5d488b000000b00228d7078c4esm12238021wrq.4.2022.10.11.16.49.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Oct 2022 16:49:02 -0700 (PDT) In-Reply-To: <21C0D090-6EE1-45EB-B23A-8BECDD5A9447@gmail.com> (Yuan Fu's message of "Tue, 11 Oct 2022 08:38:30 -0700") 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:245154 Archived-At: Yuan Fu 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)|<------------=20 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 > =E2=80=9C/=E2=80=9C. 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=C3=A3o