From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Charl P. Botha" Newsgroups: gmane.emacs.bugs Subject: bug#59945: [PATCH] Fix empty pairs in js tree-sitter imenu alist Date: Sat, 10 Dec 2022 19:17:41 +0200 Message-ID: <43c6e6ed-3ddc-4ae0-a150-f86e852bd83b@app.fastmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17905"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Cyrus-JMAP/3.7.0-alpha0-1115-g8b801eadce-fm-20221102.001-g8b801ead To: 59945@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 10 18:46:36 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 1p43vm-0004TS-P7 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 10 Dec 2022 18:46:35 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p43vR-00029k-1S; Sat, 10 Dec 2022 12:46:13 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p43vI-00028b-Dl for bug-gnu-emacs@gnu.org; Sat, 10 Dec 2022 12:46:06 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p43vH-0007Op-Sr for bug-gnu-emacs@gnu.org; Sat, 10 Dec 2022 12:46:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p43vH-0001US-N9 for bug-gnu-emacs@gnu.org; Sat, 10 Dec 2022 12:46:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: "Charl P. Botha" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 10 Dec 2022 17:46:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 59945 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16706943535682 (code B ref -1); Sat, 10 Dec 2022 17:46:03 +0000 Original-Received: (at submit) by debbugs.gnu.org; 10 Dec 2022 17:45:53 +0000 Original-Received: from localhost ([127.0.0.1]:44153 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p43v6-0001TW-P9 for submit@debbugs.gnu.org; Sat, 10 Dec 2022 12:45:53 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:44402) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p43UM-00019c-5Y for submit@debbugs.gnu.org; Sat, 10 Dec 2022 12:18:15 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p43UH-0003B0-5c for bug-gnu-emacs@gnu.org; Sat, 10 Dec 2022 12:18:10 -0500 Original-Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p43UD-0002PX-Gc for bug-gnu-emacs@gnu.org; Sat, 10 Dec 2022 12:18:07 -0500 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 6E3455C00C3 for ; Sat, 10 Dec 2022 12:18:02 -0500 (EST) Original-Received: from imap44 ([10.202.2.94]) by compute2.internal (MEProxy); Sat, 10 Dec 2022 12:18:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vxlabs.com; h=cc :content-type:date:date:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to; s=fm2; t= 1670692682; x=1670779082; bh=TzZLeRGxIUTNkg9eexsZiOxs+RaBojjyYnv MEEoLNHg=; b=R5dTD/yC7fBa2Ttl7G9c617GYGlO79nXPxJG7Jnu6vNHwKFj120 jAGO1mcSau9rYuq7NBsHYhGd5IiOM0aLt6y1tBDhGyABcG1ftUiR5eBQX8Ag0DZg IHL/NbQ2LU1aB+svwo9ea92s8jdQfOl46ajU81NXk9JY8WddTX6+Mj8pNnCQxj8I iNva5zsFbOCt8L4x5IO+poEQCXCC/anbm0d492hHHDD8luWMvf457BqTCQLmXGPE nRpNkE89HxOYy66LANTaSTcv9T+NUYV/gLWI74YqyyrJ+JxHwY305OdBaTzNvhV3 J8YPzUvYmnjZe2qnb/o3fos4mO51p3FqxNA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:message-id:mime-version :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1670692682; x= 1670779082; bh=TzZLeRGxIUTNkg9eexsZiOxs+RaBojjyYnvMEEoLNHg=; b=M WGFO802S+FQXfIOJIsDn2ebD9XYqAiL+wCqq15Nic8EtUMONusvhYal4J78a1Uku v0DvtGCDmqNUiF+vdZLAwE8x3FeJagAHO2f5xllKTrS7xsaSRVYD+n3N3bE63QeS U2EBankUHiXsuVsXiITACjBZwl3Smq8RDNdXDkJfLZvWZjGt2qFjDiiZomQHDqF5 i1I1K8FyHVSvqfQ5CFf3yZNMj9+SGeX1A3DykfPcYjURhk0XmVdI30rLroCpd/qO 1JydTV9T/HzycucS9YS209L/tw7Fi/S1pw4zE1Su/IFldMEXYHbVGMIVjO3DnjWc bHPMLYsCRCgrFLtA9S4dA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdeggdelkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepofgfggfkfffhvffutgesthdtredtre ertdenucfhrhhomhepfdevhhgrrhhlucfrrdcuuehothhhrgdfuceotghpsghothhhrges vhiglhgrsghsrdgtohhmqeenucggtffrrghtthgvrhhnpefhgfejheekfefgleegtdetle egvdehhfdvkeefhfegjedvjedtfeduudeiudegkeenucffohhmrghinhepghhithhhuhgs rdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh eptghpsghothhhrgesvhiglhgrsghsrdgtohhm X-ME-Proxy: Feedback-ID: i502842e6:Fastmail Original-Received: by mailuser.nyi.internal (Postfix, from userid 501) id 06B3F36A0073; Sat, 10 Dec 2022 12:18:01 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface Received-SPF: pass client-ip=66.111.4.27; envelope-from=cpbotha@vxlabs.com; helo=out3-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 10 Dec 2022 12:45:51 -0500 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:250533 Archived-At: 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 45dfef372cd..6ca260ad8ad 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -3732,10 +3732,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