unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Charl P. Botha" <cpbotha@vxlabs.com>
To: "Yuan Fu" <casouri@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>, 59945@debbugs.gnu.org
Subject: bug#59945: [PATCH] Fix empty pairs in js tree-sitter imenu alist
Date: Fri, 16 Dec 2022 07:58:46 +0200	[thread overview]
Message-ID: <a9400067-0b33-495d-92b6-b5d37cf84801@app.fastmail.com> (raw)
In-Reply-To: <94476C6A-CCEA-43CE-A6B7-0232998FCBCC@gmail.com>

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

Dear Yuan,

On Fri, Dec 16, 2022, at 03:40, Yuan Fu wrote:
> "Charl P. Botha" <cpbotha@vxlabs.com> writes:
>> In the meantime, I've sent my signed copyright assignment, and my employer's docusigned disclaimer of rights, to the FSF.
>>
>> I would be super grateful if you could add the commit when you can make the time.
>
> Thanks. Unless I’m missing something, your patch is a diff file rather
> than a patch file. You can generate one with
>
> git format-patch -1 --stdout >~/mypatch.patch
>
> Don’t worry about commit message this time, I’ll reword your commit and
> add it. But if you want to submit more patches in the future I recommend
> you to read CONTRIBUTE file under repo root, which describes the commit
> message format Emacs uses.

I followed the instructions at https://www.gnu.org/software/emacs/manual/html_node/emacs/Sending-Patches.html which said to use "git format-patch master" and include either inline (which I did) or as a mime attachment.

I have now re-done it using your advice above, and included the patch file as attachment to this email.

Next time (would be great if it happens), I'll attach by default.

Kind regards,
Charl

[-- Attachment #2: cpb-fix-empty-pairs-js-ts.patch --]
[-- Type: application/octet-stream, Size: 1859 bytes --]

From 01c4f3ade5c61b96718bbf36b2ed7b4b1ed84aa0 Mon Sep 17 00:00:00 2001
From: "Charl P. Botha" <cpbotha@vxlabs.com>
Date: Sat, 10 Dec 2022 19:09:38 +0200
Subject: [PATCH] Fix empty pairs in js tree-sitter imenu alist

The current js--treesit-imenu, used by the JavaScript, TypeScript and
TSX tree-sitter modes, would return empty pairs in the imenu alist if
there were none of that type of symbol.

This would break both the built in imenu and also packages like
consult-imenu.

See https://github.com/minad/consult/issues/697 for the discussion there.
---
 lisp/progmodes/js.el | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index e0625951b65..8fd0386e6ae 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3738,10 +3738,17 @@ js--treesit-imenu
          (func-tree (treesit-induce-sparse-tree
                      node "function_declaration" nil 1000))
          (var-tree (treesit-induce-sparse-tree
-                    node "lexical_declaration" nil 1000)))
-    `(("Class" . ,(js--treesit-imenu-1 class-tree))
-      ("Variable" . ,(js--treesit-imenu-1 var-tree))
-      ("Function" . ,(js--treesit-imenu-1 func-tree)))))
+                    node "lexical_declaration" nil 1000))
+         (imenu-alist nil))
+    ;; when a sub-tree is empty, we should not return that pair at all
+    ;; https://github.com/minad/consult/issues/697#issuecomment-1345302734
+    (when func-tree
+      (setq imenu-alist (cons `("Function" . ,(js--treesit-imenu-1 func-tree)) imenu-alist)))
+    (when var-tree
+      (setq imenu-alist (cons `("Variable" . ,(js--treesit-imenu-1 var-tree)) imenu-alist)))
+    (when class-tree
+      (setq imenu-alist (cons `("Class" . ,(js--treesit-imenu-1 class-tree)) imenu-alist)))
+    imenu-alist))
 
 ;;; Main Function
 
-- 
2.25.1


  reply	other threads:[~2022-12-16  5:58 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-10 17:17 bug#59945: [PATCH] Fix empty pairs in js tree-sitter imenu alist Charl P. Botha
2022-12-12 22:28 ` Yuan Fu
2022-12-13  7:48   ` Charl P. Botha
2022-12-13 12:40     ` Eli Zaretskii
2022-12-13 12:03   ` Eli Zaretskii
2022-12-15  9:13     ` Charl P. Botha
2022-12-15 10:41       ` Eli Zaretskii
2022-12-16  1:40 ` Yuan Fu
2022-12-16  5:58   ` Charl P. Botha [this message]
2022-12-16 14:11     ` Robert Pluim
2022-12-16 17:52       ` Charl P. Botha
2022-12-21  4:48 ` Yuan Fu
2022-12-21 10:15   ` Charl P. Botha
2022-12-21 17:25   ` Robert Pluim
2022-12-22  8:10     ` Yuan Fu

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=a9400067-0b33-495d-92b6-b5d37cf84801@app.fastmail.com \
    --to=cpbotha@vxlabs.com \
    --cc=59945@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 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).