all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Randy Taylor <dev@rjt.dev>
To: Eshel Yaron <me@eshelyaron.com>
Cc: 59979@debbugs.gnu.org
Subject: bug#59979: 30.0.50; dockerfile-ts-mode imenu issue
Date: Mon, 12 Dec 2022 02:30:28 +0000	[thread overview]
Message-ID: <lQ6h_YSxTGOxDyIEGMFZU0NsIcCphtLsnand76B9BgjDNlPa1MFxb9y6oBq3a4tPe5Hdgirl2voiwKlxXQJsN9adWUTVQzVASwwPkaXFVkQ=@rjt.dev> (raw)
In-Reply-To: <Ro8fLJQkq01jOHD5bqpQMipUllQ6-ePmZTKbmG5i9OJL40FbmSFtm4ic4qfa1cYpe53AoQKa9pqtiGDQZcI8BwyUdR0sCYDvcUVeH-xO6lU=@rjt.dev>

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

On Sunday, December 11th, 2022 at 18:57, Randy Taylor <dev@rjt.dev> wrote:
> 
> On Sunday, December 11th, 2022 at 15:39, Eshel Yaron via "Bug reports for GNU Emacs, the Swiss army knife of text editors" bug-gnu-emacs@gnu.org wrote:
> 
> > I stumbled upon the following issue while checking out the new
> > dockerfile-ts-mode.
> > 
> > 1. emacs -Q
> > 2. C-x C-f /tmp/Dockerfile
> > 3. Insert the following contents (taken from
> > https://docs.docker.com/build/building/multi-stage/#use-a-previous-stage-as-a-new-stage):
> > 
> > FROM ubuntu AS base
> > RUN echo "base"
> > 
> > FROM base AS stage1
> > RUN echo "stage1"
> > 
> > FROM base AS stage2
> > RUN echo "stage2"
> > 
> > 4. Try to use M-x imenu to navigate to the last build stage
> > 4.a. We get the following imenu--index-alist:
> > 
> > (("Stage"
> > ("ubuntu" . #<marker at 1 in Dockerfile>)
> > 
> > ("base" . #<marker at 42 in Dockerfile>)
> > 
> > ("base" . #<marker at 81 in Dockerfile>)))
> > 
> > 4.b. Consequently, we can't choose and jump to the last stage, because
> > dockerfile-ts-mode calls both of the last two stages by the same name
> > ("base").
> > 
> > The crux of the issue is that dockerfile-ts-mode uses a stage's base
> > image as its name, which seems kinda wrong and leads to ambiguity since
> > many stages can have a common base image. Instead, it would be
> > preferable IMO to use the index of the stage or, when available, its
> > unique name (such as "stage1" in the example above).
> > 
> > Thanks!
> 
> 
> Thanks, I'll take a look and hopefully reply back with a patch in a bit.
> 

I didn't notice this because I use conult-imenu, which will add an index for any duplicates. imenu doesn't do this, and for other modes like c-mode, c++-mode, org-mode, etc., only the first entry gets shown.

I've attached a patch which will use the stage name if it's available, otherwise use the base image.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Improve-dockerfile-ts-mode-imenu-generation-Bug-5997.patch --]
[-- Type: text/x-patch; name=0001-Improve-dockerfile-ts-mode-imenu-generation-Bug-5997.patch, Size: 1708 bytes --]

From 09ffadd9f5db19174dced572f3f0ac98f7d2a3a3 Mon Sep 17 00:00:00 2001
From: Randy Taylor <dev@rjt.dev>
Date: Sun, 11 Dec 2022 20:50:54 -0500
Subject: [PATCH] Improve dockerfile-ts-mode imenu generation (Bug#59979)

* lisp/progmodes/dockerfile-ts-mode.el (treesit-node-child-by-field-name):
Declare.
(dockerfile-ts-mode--imenu-1): Use stage name if available.
---
 lisp/progmodes/dockerfile-ts-mode.el | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/dockerfile-ts-mode.el b/lisp/progmodes/dockerfile-ts-mode.el
index 544e0f82d6..40d90cc2df 100644
--- a/lisp/progmodes/dockerfile-ts-mode.el
+++ b/lisp/progmodes/dockerfile-ts-mode.el
@@ -33,6 +33,7 @@
 (declare-function treesit-parser-create "treesit.c")
 (declare-function treesit-induce-sparse-tree "treesit.c")
 (declare-function treesit-node-child "treesit.c")
+(declare-function treesit-node-child-by-field-name "treesit.c")
 (declare-function treesit-node-start "treesit.c")
 (declare-function treesit-node-type "treesit.c")
 
@@ -117,8 +118,10 @@ dockerfile-ts-mode--imenu-1
                            children))
          (name (when ts-node
                  (pcase (treesit-node-type ts-node)
-                   ("from_instruction" (treesit-node-text
-                                        (treesit-node-child ts-node 1) t)))))
+                   ("from_instruction"
+                    (treesit-node-text
+                     (or (treesit-node-child-by-field-name ts-node "as")
+                         (treesit-node-child ts-node 1)) t)))))
          (marker (when ts-node
                    (set-marker (make-marker)
                                (treesit-node-start ts-node)))))
-- 
2.38.1


  reply	other threads:[~2022-12-12  2:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-11 20:39 bug#59979: 30.0.50; dockerfile-ts-mode imenu issue Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-11 23:57 ` Randy Taylor
2022-12-12  2:30   ` Randy Taylor [this message]
2022-12-12  8:28     ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-12 20:16       ` Randy Taylor
2022-12-12 22:59 ` Yuan Fu
2022-12-13  0:41   ` Randy Taylor

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='lQ6h_YSxTGOxDyIEGMFZU0NsIcCphtLsnand76B9BgjDNlPa1MFxb9y6oBq3a4tPe5Hdgirl2voiwKlxXQJsN9adWUTVQzVASwwPkaXFVkQ=@rjt.dev' \
    --to=dev@rjt.dev \
    --cc=59979@debbugs.gnu.org \
    --cc=me@eshelyaron.com \
    /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.