From debbugs-submit-bounces@debbugs.gnu.org Thu Dec 29 11:06:22 2022 Received: (at submit) by debbugs.gnu.org; 29 Dec 2022 16:06:22 +0000 Received: from localhost ([127.0.0.1]:60920 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pAvQD-0001W5-JN for submit@debbugs.gnu.org; Thu, 29 Dec 2022 11:06:22 -0500 Received: from lists.gnu.org ([209.51.188.17]:35128) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pAvQB-0001Vx-HA for submit@debbugs.gnu.org; Thu, 29 Dec 2022 11:06:20 -0500 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 1pAvQB-0004a3-CK for bug-gnu-emacs@gnu.org; Thu, 29 Dec 2022 11:06:19 -0500 Received: from mail-yb1-xb31.google.com ([2607:f8b0:4864:20::b31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pAvQ9-0006XG-GZ for bug-gnu-emacs@gnu.org; Thu, 29 Dec 2022 11:06:19 -0500 Received: by mail-yb1-xb31.google.com with SMTP id n78so20989074yba.12 for ; Thu, 29 Dec 2022 08:06:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=ltXNar22Su3E6C0NQNxFkfZClQ8vnGCgk8XmarqghsM=; b=NvOUfufkfNFFocz2Cr/dWlskhrKJUib31d5rAdTC/5Rt2hgTZIyFKmZwgQSWWjk539 XzumOMjovVRcuHGJ0FWH2XrDa7DkMGtEypmJ62f/+kIvcTax0pJTLwsJRs5SqwWhoRoz dgyto9ygu8Xk1L5l+d3hXywC7GdZPjqOanSgvWWQJzpGPQaJvC9+bTwqw9HjAxE7m81u PFkSXz8MHewy8mNxoSDdhHi0rW0+LjtQ8jlwOmfeRlJzBYfcny6q1rcpb7x14bNP/x8/ ksO8wehzwN7luJHr69kMl74ovuegT1bB6XG3IPFi6iXZVTsOBHOyHCupLHPhpbDePcCX mXXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ltXNar22Su3E6C0NQNxFkfZClQ8vnGCgk8XmarqghsM=; b=MeesEeZcwy5hKkXiFb9DmAZPSEAAcOExNg+FY6u/JECcxEtNe9ZOScYN2GdDyXs+XA JI3W2yORJgeaitma8UvGvpUsA8Dik376zNmUkTyk7VGPLhvBGRIvVZ/6W7wPCGhp4Xvl C91ypg6TqCc+r1hWuKdt9BXsfJBpL19jf/7WZBTtlYZXaMKlQncO07zy5Vz1uGMinSsx izKE2hPBRCj/0PAEKSd3/WVEtCW6w7GqZuUaQeLojV5m64ip0/bnFErM92RlWJ96x4MD +ZWhl+iLHV0pdszSW/w3/hp+vH1nwEPo9jkB4BY36EWRjaAugFMuEyuP69zaXzv9zkxR FWCg== X-Gm-Message-State: AFqh2kplapRmCtV13JgBkU7hNKgdCjIP156I0xBjViLtGxlEtocR7ozC r99u4gpRvAM4r7dpeELEiS7nELWHXoEd1+WNGvE4/4S1l5M= X-Google-Smtp-Source: AMrXdXsl3yg0aHsVrwPvLkoV/mck0Falo54wkjACrlq2k1ggLEdKsv+GpEZa+6Gr3VpbBP4Opzr2QD9Sg3hC5UPIE+Y= X-Received: by 2002:a25:ce8c:0:b0:78f:12e9:7e83 with SMTP id x134-20020a25ce8c000000b0078f12e97e83mr318697ybe.587.1672329975788; Thu, 29 Dec 2022 08:06:15 -0800 (PST) MIME-Version: 1.0 From: Evgeni Kolev Date: Thu, 29 Dec 2022 18:05:49 +0200 Message-ID: Subject: [PATCH] Update go-ts-mode to use Imenu facility To: bug-gnu-emacs@gnu.org Content-Type: text/plain; charset="UTF-8" Received-SPF: pass client-ip=2607:f8b0:4864:20::b31; envelope-from=evgenysw@gmail.com; helo=mail-yb1-xb31.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) This patch updates go-ts-mode to use Imenu facility added in https://git.savannah.gnu.org/cgit/emacs.git/commit/?h=emacs-29&id=b39dc7ab27a696a8607ab859aeff3c71509231f5 The Imenu items are extended to support "Method", in addition to "Function" and "Type". The current Imenu approach uses "type_spec" to identify "Type" which acts as a catch-all for many Go constructs, for example struct and interface definitions. This catch-all approach is not optimal because structs and interfaces are put in the same "Type" bucket. In a follow-up patch I'll try to change the approach and have separate "Interface" and "Struct" types. The patch is below. commit 71ff7b21fe92167313bd1761b68b6e6fd879b09f Author: Evgeni Kolev Date: Thu Dec 29 17:49:40 2022 +0200 Update go-ts-mode to use Imenu facility go-ts-mode is updated to use the Imenu facility added in commit b39dc7ab27a696a8607ab859aeff3c71509231f5. The Imenu items are extended to support "Method", in addition to "Function" and "Type". * lisp/progmodes/go-ts-mode.el (go-ts-mode--imenu-1) (go-ts-mode--imenu): Remove functions. (go-ts-mode--defun-name): New function. diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el index 124d9b044a2..c6c1c61d9f4 100644 --- a/lisp/progmodes/go-ts-mode.el +++ b/lisp/progmodes/go-ts-mode.el @@ -173,44 +173,6 @@ go-ts-mode--font-lock-settings '((ERROR) @font-lock-warning-face)) "Tree-sitter font-lock settings for `go-ts-mode'.") -(defun go-ts-mode--imenu () - "Return Imenu alist for the current buffer." - (let* ((node (treesit-buffer-root-node)) - (func-tree (treesit-induce-sparse-tree - node "function_declaration" nil 1000)) - (type-tree (treesit-induce-sparse-tree - node "type_spec" nil 1000)) - (func-index (go-ts-mode--imenu-1 func-tree)) - (type-index (go-ts-mode--imenu-1 type-tree))) - (append - (when func-index `(("Function" . ,func-index))) - (when type-index `(("Type" . ,type-index)))))) - -(defun go-ts-mode--imenu-1 (node) - "Helper for `go-ts-mode--imenu'. -Find string representation for NODE and set marker, then recurse -the subtrees." - (let* ((ts-node (car node)) - (children (cdr node)) - (subtrees (mapcan #'go-ts-mode--imenu-1 - children)) - (name (when ts-node - (treesit-node-text - (pcase (treesit-node-type ts-node) - ("function_declaration" - (treesit-node-child-by-field-name ts-node "name")) - ("type_spec" - (treesit-node-child-by-field-name ts-node "name")))))) - (marker (when ts-node - (set-marker (make-marker) - (treesit-node-start ts-node))))) - (cond - ((or (null ts-node) (null name)) subtrees) - (subtrees - `((,name ,(cons name marker) ,@subtrees))) - (t - `((,name . ,marker)))))) - ;;;###autoload (add-to-list 'auto-mode-alist '("\\.go\\'" . go-ts-mode)) @@ -228,9 +190,18 @@ go-ts-mode (setq-local comment-end "") (setq-local comment-start-skip (rx "//" (* (syntax whitespace)))) + ;; Navigation. + (setq-local treesit-defun-type-regexp + (regexp-opt '("method_declaration" + "function_declaration" + "type_spec"))) + (setq-local treesit-defun-name-function #'go-ts-mode--defun-name) + ;; Imenu. - (setq-local imenu-create-index-function #'go-ts-mode--imenu) - (setq-local which-func-functions nil) + (setq-local treesit-simple-imenu-settings + `(("Function" "\\`function_declaration\\'" nil nil) + ("Type" "\\`type_spec\\'" nil nil) + ("Method" "\\`method_declaration\\'" nil nil))) ;; Indent. (setq-local indent-tabs-mode t @@ -247,6 +218,18 @@ go-ts-mode (treesit-major-mode-setup))) +(defun go-ts-mode--defun-name (node) + "Return the defun name of NODE. +Return nil if there is no name or if NODE is not a defun node." + (pcase (treesit-node-type node) + ((or "function_declaration" + "method_declaration" + "type_spec") + (treesit-node-text + (treesit-node-child-by-field-name + node "name") + t)))) + ;; go.mod support. (defvar go-mod-ts-mode--syntax-table From debbugs-submit-bounces@debbugs.gnu.org Sun Jan 01 04:07:28 2023 Received: (at 60407) by debbugs.gnu.org; 1 Jan 2023 09:07:28 +0000 Received: from localhost ([127.0.0.1]:40276 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pBuJU-00022X-0s for submit@debbugs.gnu.org; Sun, 01 Jan 2023 04:07:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51078) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pBuJS-00022L-A4 for 60407@debbugs.gnu.org; Sun, 01 Jan 2023 04:07:26 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pBuJM-0008Pa-PF; Sun, 01 Jan 2023 04:07:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=gdyNmF5eNANcs3XMFhrlO9DxSFq9baZ7QOQ/qE0mDe0=; b=XQjVGBWjcDu4 GERSyVKFO4gqVdvvhPbZlvXkeo5AwM1bqa2yCEEPlIFWIeUVPzJJ/YdWO+VKOIWDTRFmMbzlfxJKU t4m6uvIUIpqM7fudYSaF8N+abWaPy3DDf68QeAzc14XOO+m/U7SS6Ki4O9t35Poj03oAdYR5sq8/2 U37qEhsXizeKOMo3TZC22Rc7rnjKCbC/BGQKmhJsvEhg4ZCg4u7NkmE80KfhIDiIAhOrdcIGi1JOL 0c+25xFWWGVdvIBFiQmGHg7I9QCNc3GjmcMKHIdPAQBSTlCmO6GOiSLQ1Ls9nnI72XY22CYEGbCcQ iFI0L5w6JDolbF81uiCHFA==; Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pBuJM-0006nv-7f; Sun, 01 Jan 2023 04:07:20 -0500 Date: Sun, 01 Jan 2023 11:07:24 +0200 Message-Id: <83y1qm39o3.fsf@gnu.org> From: Eli Zaretskii To: Evgeni Kolev , Randy Taylor In-Reply-To: (message from Evgeni Kolev on Thu, 29 Dec 2022 18:05:49 +0200) Subject: Re: bug#60407: [PATCH] Update go-ts-mode to use Imenu facility References: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 60407 Cc: 60407@debbugs.gnu.org, Yuan Fu X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Evgeni Kolev > Date: Thu, 29 Dec 2022 18:05:49 +0200 > > This patch updates go-ts-mode to use Imenu facility added in > https://git.savannah.gnu.org/cgit/emacs.git/commit/?h=emacs-29&id=b39dc7ab27a696a8607ab859aeff3c71509231f5 > > The Imenu items are extended to support "Method", in addition to > "Function" and "Type". > > The current Imenu approach uses "type_spec" to identify "Type" which > acts as a catch-all for many Go constructs, for example struct and > interface definitions. This catch-all approach is not optimal because > structs and interfaces are put in the same "Type" bucket. In a > follow-up patch I'll try to change the approach and have separate > "Interface" and "Struct" types. > > The patch is below. Randy, Yuan, are you looking into this? > commit 71ff7b21fe92167313bd1761b68b6e6fd879b09f > Author: Evgeni Kolev > Date: Thu Dec 29 17:49:40 2022 +0200 > > Update go-ts-mode to use Imenu facility > > go-ts-mode is updated to use the Imenu facility added in commit > b39dc7ab27a696a8607ab859aeff3c71509231f5. > > The Imenu items are extended to support "Method", in addition to > "Function" and "Type". > > * lisp/progmodes/go-ts-mode.el (go-ts-mode--imenu-1) (go-ts-mode--imenu): > Remove functions. > (go-ts-mode--defun-name): New function. > > diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el > index 124d9b044a2..c6c1c61d9f4 100644 > --- a/lisp/progmodes/go-ts-mode.el > +++ b/lisp/progmodes/go-ts-mode.el > @@ -173,44 +173,6 @@ go-ts-mode--font-lock-settings > '((ERROR) @font-lock-warning-face)) > "Tree-sitter font-lock settings for `go-ts-mode'.") > > -(defun go-ts-mode--imenu () > - "Return Imenu alist for the current buffer." > - (let* ((node (treesit-buffer-root-node)) > - (func-tree (treesit-induce-sparse-tree > - node "function_declaration" nil 1000)) > - (type-tree (treesit-induce-sparse-tree > - node "type_spec" nil 1000)) > - (func-index (go-ts-mode--imenu-1 func-tree)) > - (type-index (go-ts-mode--imenu-1 type-tree))) > - (append > - (when func-index `(("Function" . ,func-index))) > - (when type-index `(("Type" . ,type-index)))))) > - > -(defun go-ts-mode--imenu-1 (node) > - "Helper for `go-ts-mode--imenu'. > -Find string representation for NODE and set marker, then recurse > -the subtrees." > - (let* ((ts-node (car node)) > - (children (cdr node)) > - (subtrees (mapcan #'go-ts-mode--imenu-1 > - children)) > - (name (when ts-node > - (treesit-node-text > - (pcase (treesit-node-type ts-node) > - ("function_declaration" > - (treesit-node-child-by-field-name ts-node "name")) > - ("type_spec" > - (treesit-node-child-by-field-name ts-node "name")))))) > - (marker (when ts-node > - (set-marker (make-marker) > - (treesit-node-start ts-node))))) > - (cond > - ((or (null ts-node) (null name)) subtrees) > - (subtrees > - `((,name ,(cons name marker) ,@subtrees))) > - (t > - `((,name . ,marker)))))) > - > ;;;###autoload > (add-to-list 'auto-mode-alist '("\\.go\\'" . go-ts-mode)) > > @@ -228,9 +190,18 @@ go-ts-mode > (setq-local comment-end "") > (setq-local comment-start-skip (rx "//" (* (syntax whitespace)))) > > + ;; Navigation. > + (setq-local treesit-defun-type-regexp > + (regexp-opt '("method_declaration" > + "function_declaration" > + "type_spec"))) > + (setq-local treesit-defun-name-function #'go-ts-mode--defun-name) > + > ;; Imenu. > - (setq-local imenu-create-index-function #'go-ts-mode--imenu) > - (setq-local which-func-functions nil) > + (setq-local treesit-simple-imenu-settings > + `(("Function" "\\`function_declaration\\'" nil nil) > + ("Type" "\\`type_spec\\'" nil nil) > + ("Method" "\\`method_declaration\\'" nil nil))) > > ;; Indent. > (setq-local indent-tabs-mode t > @@ -247,6 +218,18 @@ go-ts-mode > > (treesit-major-mode-setup))) > > +(defun go-ts-mode--defun-name (node) > + "Return the defun name of NODE. > +Return nil if there is no name or if NODE is not a defun node." > + (pcase (treesit-node-type node) > + ((or "function_declaration" > + "method_declaration" > + "type_spec") > + (treesit-node-text > + (treesit-node-child-by-field-name > + node "name") > + t)))) > + > ;; go.mod support. > > (defvar go-mod-ts-mode--syntax-table > > > > From debbugs-submit-bounces@debbugs.gnu.org Sun Jan 01 08:05:41 2023 Received: (at 60407) by debbugs.gnu.org; 1 Jan 2023 13:05:41 +0000 Received: from localhost ([127.0.0.1]:40439 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pBy20-0004eH-M0 for submit@debbugs.gnu.org; Sun, 01 Jan 2023 08:05:41 -0500 Received: from mail-yw1-f176.google.com ([209.85.128.176]:44966) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pBy1x-0004e2-Jc for 60407@debbugs.gnu.org; Sun, 01 Jan 2023 08:05:39 -0500 Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-48641a481dfso186444377b3.11 for <60407@debbugs.gnu.org>; Sun, 01 Jan 2023 05:05:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=+Rfa60O02YKdEjg0Pmf0Lf8m6h6m4IdZOfqt02ru3RU=; b=kwagOFx5O1aMJ8sDzVs/QNvoJMhdw3s7u6XN+zU/0LYD+pu0Q5yCtS1l1e70qE/2Qq cqcultL9ApEb4zYSL35EfZ5Fi7ZaC2G3JdPBN7IymYAMhS+p2zkOjPsnhfkxf0nsdgUv VP0t0qQNnk5fmESbO/2QW8+1YM3Kql71IxLnSWr5pKlQwlwoJbgC6BdmOsdbm2PypJLl GIG6gKKDwSxXos/KzkRGcfLRzYCpWk0IHnEj1qLE2iry6aCwZX8A50/kt4bOejnjHYRx Ej6EtYV7xykPhY5k3SFDpFnZinKB9uMC7wmPBXzUyR6H583FUt0I4jQRkwbRscVbqmJe NfIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+Rfa60O02YKdEjg0Pmf0Lf8m6h6m4IdZOfqt02ru3RU=; b=ZSUMUx2xbFl9zRNjh8Y44eHHk+IOARVeg5EC3OQvo2CpC2ydNzIxQzfPsKSrDRgltb uUa/RsdFXy3dFMHD3urKNoLYWyX5OCx1cPwdvwYIT4CnB3n0PXM+XzgLYVUoYCfsQK/3 7EKpP7Y/OHk7P5EuFi0AxPVNuP0+xnoBpRSTTzYTBZRNd9W8X+5OR8mBj+SpJ+PVeD2H m3w/vefLxJ3s5GQcgReBb1j65xgicpTAb8yMl0UT/14Ydr3EHaxoqrK9qbp+beI/HIgb XCMP5Er/ALzLUikseV1TolfSe3tRfTwuyl5ELQ8x89mwf5OYBxSJ/P44AJHpMPvD7aJ9 kcVQ== X-Gm-Message-State: AFqh2koK0WD7+g4OgDLvilkmtbwxNLz5fZlpIN/7zrnnqF3r9A8cz9W/ 2cKPzlT2MHNbm4r7OjvysrEiwIetcwMJTVXK+L8= X-Google-Smtp-Source: AMrXdXufpxjhaI9xS3Cd06jN939xywUwGrasI3Au0j72RZ+j6RGoFJiUFgMbOEbpRag2KqlAGpDTm7JqtW+zRfS/moo= X-Received: by 2002:a0d:e5c7:0:b0:39a:afeb:f519 with SMTP id o190-20020a0de5c7000000b0039aafebf519mr3964772ywe.146.1672578331632; Sun, 01 Jan 2023 05:05:31 -0800 (PST) MIME-Version: 1.0 References: <83y1qm39o3.fsf@gnu.org> In-Reply-To: <83y1qm39o3.fsf@gnu.org> From: Evgeni Kolev Date: Sun, 1 Jan 2023 15:05:05 +0200 Message-ID: Subject: Re: bug#60407: [PATCH] Update go-ts-mode to use Imenu facility To: Eli Zaretskii Content-Type: text/plain; charset="UTF-8" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 60407 Cc: Randy Taylor , 60407@debbugs.gnu.org, Yuan Fu X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) To illustrate the change, here's a comparison before VS after (VS eglot). I'm using a sample .go file (at the bottom of this mail). Before: 4 candidates: Function: measure Type: geometry Type: rect Type: circle After: 8 candidates: Function: measure Type: geometry Type: rect Type: circle Method: area Method: perim Method: area Method: perim For comparison, here's eglot's Imenu (using Go's gopls language server): 13 candidates: Interface: geometry Struct: rect Struct: circle Field.rect: width Field.rect: height Field.circle: radius Method.geometry: area Method.geometry: perim Method: (rect).area Method: (rect).perim Method: (circle).area Method: (circle).perim Function: measure Sample .go file: > type geometry interface { > area() float64 > perim() float64 > } > > type rect struct { > width, height float64 > } > > type circle struct { > radius float64 > } > > func (r rect) area() float64 { > return r.width * r.height > } > > func (r rect) perim() float64 { > return 2*r.width + 2*r.height > } > > func (c circle) area() float64 { > return math.Pi * c.radius * c.radius > } > > func (c circle) perim() float64 { > return 2 * math.Pi * c.radius > } > > func measure(g geometry) { > fmt.Println(g) > fmt.Println(g.area()) > fmt.Println(g.perim()) > } On Sun, Jan 1, 2023 at 11:07 AM Eli Zaretskii wrote: > > > From: Evgeni Kolev > > Date: Thu, 29 Dec 2022 18:05:49 +0200 > > > > This patch updates go-ts-mode to use Imenu facility added in > > https://git.savannah.gnu.org/cgit/emacs.git/commit/?h=emacs-29&id=b39dc7ab27a696a8607ab859aeff3c71509231f5 > > > > The Imenu items are extended to support "Method", in addition to > > "Function" and "Type". > > > > The current Imenu approach uses "type_spec" to identify "Type" which > > acts as a catch-all for many Go constructs, for example struct and > > interface definitions. This catch-all approach is not optimal because > > structs and interfaces are put in the same "Type" bucket. In a > > follow-up patch I'll try to change the approach and have separate > > "Interface" and "Struct" types. > > > > The patch is below. > > Randy, Yuan, are you looking into this? > > > commit 71ff7b21fe92167313bd1761b68b6e6fd879b09f > > Author: Evgeni Kolev > > Date: Thu Dec 29 17:49:40 2022 +0200 > > > > Update go-ts-mode to use Imenu facility > > > > go-ts-mode is updated to use the Imenu facility added in commit > > b39dc7ab27a696a8607ab859aeff3c71509231f5. > > > > The Imenu items are extended to support "Method", in addition to > > "Function" and "Type". > > > > * lisp/progmodes/go-ts-mode.el (go-ts-mode--imenu-1) (go-ts-mode--imenu): > > Remove functions. > > (go-ts-mode--defun-name): New function. > > > > diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el > > index 124d9b044a2..c6c1c61d9f4 100644 > > --- a/lisp/progmodes/go-ts-mode.el > > +++ b/lisp/progmodes/go-ts-mode.el > > @@ -173,44 +173,6 @@ go-ts-mode--font-lock-settings > > '((ERROR) @font-lock-warning-face)) > > "Tree-sitter font-lock settings for `go-ts-mode'.") > > > > -(defun go-ts-mode--imenu () > > - "Return Imenu alist for the current buffer." > > - (let* ((node (treesit-buffer-root-node)) > > - (func-tree (treesit-induce-sparse-tree > > - node "function_declaration" nil 1000)) > > - (type-tree (treesit-induce-sparse-tree > > - node "type_spec" nil 1000)) > > - (func-index (go-ts-mode--imenu-1 func-tree)) > > - (type-index (go-ts-mode--imenu-1 type-tree))) > > - (append > > - (when func-index `(("Function" . ,func-index))) > > - (when type-index `(("Type" . ,type-index)))))) > > - > > -(defun go-ts-mode--imenu-1 (node) > > - "Helper for `go-ts-mode--imenu'. > > -Find string representation for NODE and set marker, then recurse > > -the subtrees." > > - (let* ((ts-node (car node)) > > - (children (cdr node)) > > - (subtrees (mapcan #'go-ts-mode--imenu-1 > > - children)) > > - (name (when ts-node > > - (treesit-node-text > > - (pcase (treesit-node-type ts-node) > > - ("function_declaration" > > - (treesit-node-child-by-field-name ts-node "name")) > > - ("type_spec" > > - (treesit-node-child-by-field-name ts-node "name")))))) > > - (marker (when ts-node > > - (set-marker (make-marker) > > - (treesit-node-start ts-node))))) > > - (cond > > - ((or (null ts-node) (null name)) subtrees) > > - (subtrees > > - `((,name ,(cons name marker) ,@subtrees))) > > - (t > > - `((,name . ,marker)))))) > > - > > ;;;###autoload > > (add-to-list 'auto-mode-alist '("\\.go\\'" . go-ts-mode)) > > > > @@ -228,9 +190,18 @@ go-ts-mode > > (setq-local comment-end "") > > (setq-local comment-start-skip (rx "//" (* (syntax whitespace)))) > > > > + ;; Navigation. > > + (setq-local treesit-defun-type-regexp > > + (regexp-opt '("method_declaration" > > + "function_declaration" > > + "type_spec"))) > > + (setq-local treesit-defun-name-function #'go-ts-mode--defun-name) > > + > > ;; Imenu. > > - (setq-local imenu-create-index-function #'go-ts-mode--imenu) > > - (setq-local which-func-functions nil) > > + (setq-local treesit-simple-imenu-settings > > + `(("Function" "\\`function_declaration\\'" nil nil) > > + ("Type" "\\`type_spec\\'" nil nil) > > + ("Method" "\\`method_declaration\\'" nil nil))) > > > > ;; Indent. > > (setq-local indent-tabs-mode t > > @@ -247,6 +218,18 @@ go-ts-mode > > > > (treesit-major-mode-setup))) > > > > +(defun go-ts-mode--defun-name (node) > > + "Return the defun name of NODE. > > +Return nil if there is no name or if NODE is not a defun node." > > + (pcase (treesit-node-type node) > > + ((or "function_declaration" > > + "method_declaration" > > + "type_spec") > > + (treesit-node-text > > + (treesit-node-child-by-field-name > > + node "name") > > + t)))) > > + > > ;; go.mod support. > > > > (defvar go-mod-ts-mode--syntax-table > > > > > > > > From debbugs-submit-bounces@debbugs.gnu.org Sun Jan 01 08:08:50 2023 Received: (at 60407) by debbugs.gnu.org; 1 Jan 2023 13:08:50 +0000 Received: from localhost ([127.0.0.1]:40444 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pBy54-0004ix-GA for submit@debbugs.gnu.org; Sun, 01 Jan 2023 08:08:50 -0500 Received: from mail-4022.proton.ch ([185.70.40.22]:35947) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pBy51-0004ig-2i for 60407@debbugs.gnu.org; Sun, 01 Jan 2023 08:08:48 -0500 Date: Sun, 01 Jan 2023 13:08:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rjt.dev; s=protonmail2; t=1672578520; x=1672837720; bh=iJLtvKD8AQSdcIK3aWL3BmEd4N3NM+YmwW3ARyySAlo=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=I3OlIfxjvZmUr27nACh5ma62AKmKBMh/Id6jd0EKMtxS78GFiPGpXvaKP0nh3V+s0 Gd1wA234eYJY8DWaLu6RTkbX9/tree+NhiBk4NTJMlNQzSmT5f6hlErQvqhS7it34z 2fMlywnry+Nr5R/RXf4bDqsZ4YpGJkRysniWB7glJPureLHAWH0T5Um6TEp1Z6ojy/ 5WhIcQm04Aa+z2weMOYfZUnZ4TCSiad4WNlHA7/3t1+xLRuG7va+C4hC6ZdmGJV1CR osmliZVBHYBPBMQ4VZ89gYQs5DUzl1zzzW119CfzSetHK+gfPh48hXxsTvs+uu3kH8 sAdSJNE0ntV2A== To: Eli Zaretskii From: Randy Taylor Subject: Re: bug#60407: [PATCH] Update go-ts-mode to use Imenu facility Message-ID: <9d56GnQJmiljnB4ZyywBFQc5TUzr19_OEQaO8ujwM8_cftSULjDL5pKCM3z1jknmwndVbBsejsyvMK9ZzCchuuDLN5IBwDkHwYp4QMcWlH4=@rjt.dev> In-Reply-To: <83y1qm39o3.fsf@gnu.org> References: <83y1qm39o3.fsf@gnu.org> Feedback-ID: 44397038:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 60407 Cc: Evgeni Kolev , 60407@debbugs.gnu.org, Yuan Fu X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On Sunday, January 1st, 2023 at 04:07, Eli Zaretskii wrote: >=20 > > From: Evgeni Kolev evgenysw@gmail.com >=20 > > Date: Thu, 29 Dec 2022 18:05:49 +0200 > >=20 > > This patch updates go-ts-mode to use Imenu facility added in > > https://git.savannah.gnu.org/cgit/emacs.git/commit/?h=3Demacs-29&id=3Db= 39dc7ab27a696a8607ab859aeff3c71509231f5 > >=20 > > The Imenu items are extended to support "Method", in addition to > > "Function" and "Type". > >=20 > > The current Imenu approach uses "type_spec" to identify "Type" which > > acts as a catch-all for many Go constructs, for example struct and > > interface definitions. This catch-all approach is not optimal because > > structs and interfaces are put in the same "Type" bucket. In a > > follow-up patch I'll try to change the approach and have separate > > "Interface" and "Struct" types. > >=20 > > The patch is below. >=20 >=20 > Randy, Yuan, are you looking into this? Sorry, been preoccupied recently. It's on my radar and I'll take a look and= test it out later today. From debbugs-submit-bounces@debbugs.gnu.org Sun Jan 01 12:08:46 2023 Received: (at 60407) by debbugs.gnu.org; 1 Jan 2023 17:08:46 +0000 Received: from localhost ([127.0.0.1]:41619 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pC1pF-0003QK-Jc for submit@debbugs.gnu.org; Sun, 01 Jan 2023 12:08:46 -0500 Received: from mail-yb1-f176.google.com ([209.85.219.176]:45961) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pC1pD-0003Q6-9d for 60407@debbugs.gnu.org; Sun, 01 Jan 2023 12:08:44 -0500 Received: by mail-yb1-f176.google.com with SMTP id n78so28297266yba.12 for <60407@debbugs.gnu.org>; Sun, 01 Jan 2023 09:08:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=sK2Ou2Lmo1iR772sYaV7Gn95/bjwjNrWxIa7xOELCd4=; b=YI2j3yFOPlcB8SUH9DjVpQpShOEJVzR0JpySG2egCwaWSCnqaECE0+UXy6YfS5dzuA xSPZGgFCudv5DCh6W8vle8kMbXVEZzGimTSSWDN/DSNyzmvAyL+vtkcFNSftDhOG/TMG gCY2qBw0yRVpVkf9ZrGN3tWY3prEKw+7TtNIEc1Pz/PzyicNlTaA1oOdySTe5RXQV2Z5 89Ic8xTcs/Fqg/+/p1/zbPovfACe6KvgEvjgvq5nIE5EyoFn2wsitQTk+uN/jja4Su7n yj5PoLyBuY8ba3zCAr2JRI4440P6nASfRzesHuxPk1c5dxQkUi/PJlCEJ0A/pnL1JfPc OVkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=sK2Ou2Lmo1iR772sYaV7Gn95/bjwjNrWxIa7xOELCd4=; b=H7gCAXnmAu277fbm6HjcXp5Pf210dKIse4xWKlarfOEV1EL7uDnN5nkiHRBSwBexD8 FN/ThmdzIOSB+6sCBUcQU+QP7+TNp74QmceMRuGhCEsq/rqS63Up6XFJ3HnY+Ujce38c 02WRy9vduI3UGiDpJxhO6EuoRsULyxSTs08l20+EQjTcoRB3vTko+v5hCGBjqhDkCYUa SkWf0RrANFT7fpXBo17UKTelcgwAxEJ3utZJ43dtiiowk83V4c5mYFaCYlFqfMU2LDGz N71JvPpBG9i4wVNLj8QDVGoOFPmYROwcYaBEN3kdymkkA2o8hifCKN05nd5+BiBsABcG x/iw== X-Gm-Message-State: AFqh2koTc0IlJ1ZQDuLKofe0J6fUrh6ohNtwmd0OXJ25ztGVAKA8UeBy aIlqdihiiXWpdGipmm9kz5W+Z/mUsTrJ7SlbKKU= X-Google-Smtp-Source: AMrXdXuIsierQu7ERU0D1i+8aoa0PTNdJzXYD1XXLCypyFv+gsrjBkvpn1lTwGW5eZ1ux1UuvWs7tfwuG4kQsQRL6gc= X-Received: by 2002:a25:bf8c:0:b0:708:c3d2:a2bd with SMTP id l12-20020a25bf8c000000b00708c3d2a2bdmr4916381ybk.138.1672592917471; Sun, 01 Jan 2023 09:08:37 -0800 (PST) MIME-Version: 1.0 References: <83y1qm39o3.fsf@gnu.org> In-Reply-To: From: Evgeni Kolev Date: Sun, 1 Jan 2023 19:08:11 +0200 Message-ID: Subject: Re: bug#60407: [PATCH] Update go-ts-mode to use Imenu facility To: Eli Zaretskii Content-Type: text/plain; charset="UTF-8" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 60407 Cc: Randy Taylor , 60407@debbugs.gnu.org, Yuan Fu X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) As I mentioned in the start of the mail thread - go-ts-mode's Imenu puts Go interfaces and structs in the same "Type" bucket. This can be improved in go-ts-mode. I'm providing a second patch below which splits the interfaces and structs into their own Imenu categories. Please let me know if I should provide the second patch later, in a separate thread, after the first patch is finished. I'm assuming it's simpler to review the patches together. If it's not - I'll provide them in a way to make the review easier, just let me know. The second patch is below. commit a5c4a0b25e0385516ad1f8c3444830111d467843 Author: Evgeni Kolev Date: Sun Jan 1 18:57:26 2023 +0200 Improve go-ts-mode Imenu go-ts-mode Imenu is improved to distinguish between Go interfaces and structs. Previously both were put in "Type" category. Now each has its own category: "Interface" and "Struct" respectively. * lisp/progmodes/go-ts-mode.el (go-ts-mode--interface-node-p) (go-ts-mode--struct-node-p): New functions. diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el index c6c1c61d9f4..cb8d740727a 100644 --- a/lisp/progmodes/go-ts-mode.el +++ b/lisp/progmodes/go-ts-mode.el @@ -194,13 +194,14 @@ go-ts-mode (setq-local treesit-defun-type-regexp (regexp-opt '("method_declaration" "function_declaration" - "type_spec"))) + "type_declaration"))) (setq-local treesit-defun-name-function #'go-ts-mode--defun-name) ;; Imenu. (setq-local treesit-simple-imenu-settings `(("Function" "\\`function_declaration\\'" nil nil) - ("Type" "\\`type_spec\\'" nil nil) + ("Interface" "\\`type_declaration\\'" go-ts-mode--interface-node-p nil) + ("Struct" "\\`type_declaration\\'" go-ts-mode--struct-node-p nil) ("Method" "\\`method_declaration\\'" nil nil))) ;; Indent. @@ -223,13 +224,30 @@ go-ts-mode--defun-name Return nil if there is no name or if NODE is not a defun node." (pcase (treesit-node-type node) ((or "function_declaration" - "method_declaration" - "type_spec") + "method_declaration") (treesit-node-text (treesit-node-child-by-field-name node "name") + t)) + ((or "type_declaration") + (treesit-node-text + (treesit-node-child-by-field-name + (treesit-node-child node 0 t) "name") t)))) +(defun go-ts-mode--interface-node-p (node) + "Return t if NODE is a Go interface." + (string-equal "interface_type" + (treesit-node-type + (treesit-node-child-by-field-name + (treesit-node-child node 0 t) "type")))) + +(defun go-ts-mode--struct-node-p (node) + "Return t if NODE is a Go struct" + (string-equal "struct_type" (treesit-node-type + (treesit-node-child-by-field-name + (treesit-node-child node 0 t) "type")))) + ;; go.mod support. (defvar go-mod-ts-mode--syntax-table On Sun, Jan 1, 2023 at 3:05 PM Evgeni Kolev wrote: > > To illustrate the change, here's a comparison before VS after (VS eglot). > > I'm using a sample .go file (at the bottom of this mail). > > Before: > 4 candidates: > Function: measure > Type: geometry > Type: rect > Type: circle > > After: > 8 candidates: > Function: measure > Type: geometry > Type: rect > Type: circle > Method: area > Method: perim > Method: area > Method: perim > > For comparison, here's eglot's Imenu (using Go's gopls language server): > 13 candidates: > Interface: geometry > Struct: rect > Struct: circle > Field.rect: width > Field.rect: height > Field.circle: radius > Method.geometry: area > Method.geometry: perim > Method: (rect).area > Method: (rect).perim > Method: (circle).area > Method: (circle).perim > Function: measure > > Sample .go file: > > > type geometry interface { > > area() float64 > > perim() float64 > > } > > > > type rect struct { > > width, height float64 > > } > > > > type circle struct { > > radius float64 > > } > > > > func (r rect) area() float64 { > > return r.width * r.height > > } > > > > func (r rect) perim() float64 { > > return 2*r.width + 2*r.height > > } > > > > func (c circle) area() float64 { > > return math.Pi * c.radius * c.radius > > } > > > > func (c circle) perim() float64 { > > return 2 * math.Pi * c.radius > > } > > > > func measure(g geometry) { > > fmt.Println(g) > > fmt.Println(g.area()) > > fmt.Println(g.perim()) > > } > > On Sun, Jan 1, 2023 at 11:07 AM Eli Zaretskii wrote: > > > > > From: Evgeni Kolev > > > Date: Thu, 29 Dec 2022 18:05:49 +0200 > > > > > > This patch updates go-ts-mode to use Imenu facility added in > > > https://git.savannah.gnu.org/cgit/emacs.git/commit/?h=emacs-29&id=b39dc7ab27a696a8607ab859aeff3c71509231f5 > > > > > > The Imenu items are extended to support "Method", in addition to > > > "Function" and "Type". > > > > > > The current Imenu approach uses "type_spec" to identify "Type" which > > > acts as a catch-all for many Go constructs, for example struct and > > > interface definitions. This catch-all approach is not optimal because > > > structs and interfaces are put in the same "Type" bucket. In a > > > follow-up patch I'll try to change the approach and have separate > > > "Interface" and "Struct" types. > > > > > > The patch is below. > > > > Randy, Yuan, are you looking into this? > > > > > commit 71ff7b21fe92167313bd1761b68b6e6fd879b09f > > > Author: Evgeni Kolev > > > Date: Thu Dec 29 17:49:40 2022 +0200 > > > > > > Update go-ts-mode to use Imenu facility > > > > > > go-ts-mode is updated to use the Imenu facility added in commit > > > b39dc7ab27a696a8607ab859aeff3c71509231f5. > > > > > > The Imenu items are extended to support "Method", in addition to > > > "Function" and "Type". > > > > > > * lisp/progmodes/go-ts-mode.el (go-ts-mode--imenu-1) (go-ts-mode--imenu): > > > Remove functions. > > > (go-ts-mode--defun-name): New function. > > > > > > diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el > > > index 124d9b044a2..c6c1c61d9f4 100644 > > > --- a/lisp/progmodes/go-ts-mode.el > > > +++ b/lisp/progmodes/go-ts-mode.el > > > @@ -173,44 +173,6 @@ go-ts-mode--font-lock-settings > > > '((ERROR) @font-lock-warning-face)) > > > "Tree-sitter font-lock settings for `go-ts-mode'.") > > > > > > -(defun go-ts-mode--imenu () > > > - "Return Imenu alist for the current buffer." > > > - (let* ((node (treesit-buffer-root-node)) > > > - (func-tree (treesit-induce-sparse-tree > > > - node "function_declaration" nil 1000)) > > > - (type-tree (treesit-induce-sparse-tree > > > - node "type_spec" nil 1000)) > > > - (func-index (go-ts-mode--imenu-1 func-tree)) > > > - (type-index (go-ts-mode--imenu-1 type-tree))) > > > - (append > > > - (when func-index `(("Function" . ,func-index))) > > > - (when type-index `(("Type" . ,type-index)))))) > > > - > > > -(defun go-ts-mode--imenu-1 (node) > > > - "Helper for `go-ts-mode--imenu'. > > > -Find string representation for NODE and set marker, then recurse > > > -the subtrees." > > > - (let* ((ts-node (car node)) > > > - (children (cdr node)) > > > - (subtrees (mapcan #'go-ts-mode--imenu-1 > > > - children)) > > > - (name (when ts-node > > > - (treesit-node-text > > > - (pcase (treesit-node-type ts-node) > > > - ("function_declaration" > > > - (treesit-node-child-by-field-name ts-node "name")) > > > - ("type_spec" > > > - (treesit-node-child-by-field-name ts-node "name")))))) > > > - (marker (when ts-node > > > - (set-marker (make-marker) > > > - (treesit-node-start ts-node))))) > > > - (cond > > > - ((or (null ts-node) (null name)) subtrees) > > > - (subtrees > > > - `((,name ,(cons name marker) ,@subtrees))) > > > - (t > > > - `((,name . ,marker)))))) > > > - > > > ;;;###autoload > > > (add-to-list 'auto-mode-alist '("\\.go\\'" . go-ts-mode)) > > > > > > @@ -228,9 +190,18 @@ go-ts-mode > > > (setq-local comment-end "") > > > (setq-local comment-start-skip (rx "//" (* (syntax whitespace)))) > > > > > > + ;; Navigation. > > > + (setq-local treesit-defun-type-regexp > > > + (regexp-opt '("method_declaration" > > > + "function_declaration" > > > + "type_spec"))) > > > + (setq-local treesit-defun-name-function #'go-ts-mode--defun-name) > > > + > > > ;; Imenu. > > > - (setq-local imenu-create-index-function #'go-ts-mode--imenu) > > > - (setq-local which-func-functions nil) > > > + (setq-local treesit-simple-imenu-settings > > > + `(("Function" "\\`function_declaration\\'" nil nil) > > > + ("Type" "\\`type_spec\\'" nil nil) > > > + ("Method" "\\`method_declaration\\'" nil nil))) > > > > > > ;; Indent. > > > (setq-local indent-tabs-mode t > > > @@ -247,6 +218,18 @@ go-ts-mode > > > > > > (treesit-major-mode-setup))) > > > > > > +(defun go-ts-mode--defun-name (node) > > > + "Return the defun name of NODE. > > > +Return nil if there is no name or if NODE is not a defun node." > > > + (pcase (treesit-node-type node) > > > + ((or "function_declaration" > > > + "method_declaration" > > > + "type_spec") > > > + (treesit-node-text > > > + (treesit-node-child-by-field-name > > > + node "name") > > > + t)))) > > > + > > > ;; go.mod support. > > > > > > (defvar go-mod-ts-mode--syntax-table > > > > > > > > > > > > From debbugs-submit-bounces@debbugs.gnu.org Sun Jan 01 17:31:44 2023 Received: (at 60407) by debbugs.gnu.org; 1 Jan 2023 22:31:44 +0000 Received: from localhost ([127.0.0.1]:41967 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pC6ro-0003rk-HP for submit@debbugs.gnu.org; Sun, 01 Jan 2023 17:31:44 -0500 Received: from mail-4022.proton.ch ([185.70.40.22]:11967) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pC6rm-0003rQ-Fa for 60407@debbugs.gnu.org; Sun, 01 Jan 2023 17:31:43 -0500 Date: Sun, 01 Jan 2023 22:31:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rjt.dev; s=protonmail2; t=1672612295; x=1672871495; bh=iq+sx+raPGlzPxbKSsum4DB2x48llhabs1icPxh9rsw=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=ZPauOYD5MsuhgWqke5H9He+SLhaVSeE2tHmkOwKNmU04Y3SGc2sMjKsGrWmF6M55u eZHoZeRra+7tePTJECtOqJkCq9pGjKHQb4Z47KUQBoANYiZeyfnXariXmJhQjkd3XV QLzDoYlLf04GRrsGtl7WxJgQsLRyzcHWJVaEcX9Fg44d51cYF4KeAKRlbA/4S93vA7 5XjIC74odYNjO7tZuhyygK7nE1hV9yaifedCqrVnJwa59pkgQSvKUruuHmVit2OAQn qrovDoQ7E3qufdG7MptXAUGaCHPYBQinaeEvVCAXJTTTxIYhjtnBgL9PQsdBhh75xC itAvIHDahwk2g== To: Evgeni Kolev From: Randy Taylor Subject: Re: bug#60407: [PATCH] Update go-ts-mode to use Imenu facility Message-ID: In-Reply-To: References: <83y1qm39o3.fsf@gnu.org> Feedback-ID: 44397038:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 60407 Cc: Eli Zaretskii , Yuan Fu , 60407@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On Sunday, January 1st, 2023 at 12:08, Evgeni Kolev wr= ote: >=20 > As I mentioned in the start of the mail thread - go-ts-mode's Imenu > puts Go interfaces and structs in the same "Type" bucket. This can be > improved in go-ts-mode. >=20 > I'm providing a second patch below which splits the interfaces and > structs into their own Imenu categories. >=20 > Please let me know if I should provide the second patch later, in a > separate thread, after the first patch is finished. I'm assuming it's > simpler to review the patches together. If it's not - I'll provide > them in a way to make the review easier, just let me know. > Hi Evgeni! Thanks for working on this, and apologies for the delay. The patches look good to me and work well, except for one issue (and a few = minor nits) mentioned below. All in one patch is probably best. - Type definitions are no longer captured. For example: type Quack int Does not show up anymore. - go-ts-mode--struct-node-p's docstring is missing a period at the end. - In go-ts-mode--interface-node-p and go-ts-mode--struct-node-p's docstring= s, I'm not sure it's worthwhile to mention "Go". Just interface and struct = should be fine. - Should the commit message mention changes to go-ts-mode (as in the actual= define-derived-mode mode part)? From debbugs-submit-bounces@debbugs.gnu.org Tue Jan 03 04:02:01 2023 Received: (at 60407) by debbugs.gnu.org; 3 Jan 2023 09:02:01 +0000 Received: from localhost ([127.0.0.1]:44694 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pCdBJ-0002AM-07 for submit@debbugs.gnu.org; Tue, 03 Jan 2023 04:02:01 -0500 Received: from mail-yb1-f169.google.com ([209.85.219.169]:41684) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pCdBF-00029k-8m for 60407@debbugs.gnu.org; Tue, 03 Jan 2023 04:01:58 -0500 Received: by mail-yb1-f169.google.com with SMTP id 186so32361127ybe.8 for <60407@debbugs.gnu.org>; Tue, 03 Jan 2023 01:01:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=SclL3Q6I4BBPacj+EK9bInRICi6K2YFeeW21CcsUGFc=; b=VY+iCGAf4ktAgubv1cQDImRHfLYeALGS7Er3Q5JRMK+3oHdY9DZI4o8R9eCxeimBwo jjXWxsA0NFEPs3dvyrK21PWJW8SARMluerzhpRTx1EVBrjbRjNy0jHf1rvKc76FHEXIO ANrGSuLnNSPPQ/YZqAQWh6pJqiC9ybHfUTU/1S0zCGgStr6yoxgpQP6+9U0ay7HSxVGT a609GimU2UoYoayiLD03YxLolVhm5GvY+uCAW0owIMDFzemim+1tsq9ru5nPN9h2BYpp 196MLy24Gsb9WrjQAQY/A6h2IFwyVNtsMfhQ3mjQApbPvM8MgW2Qmm4W8lo9sq+btsRd f9Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SclL3Q6I4BBPacj+EK9bInRICi6K2YFeeW21CcsUGFc=; b=D+PQeSVx0Svjp+iFFXX6Z56iMdE9QvM7rVzXyOaixXb/EPEjUTa4ya63InCeBwhBcq NqPE7CUoHTM3UZ1LbKudeLgstEwzK+TRQARbGIyH/64BcNMeLYbUTXcpxIMkfyaGCOm9 yZSiGtbrPgglZJ/XrkXLorKmPhs84OWl5CrwgrdVaNb40ZsgYwNsSKjxZEfx3Dx6+zSp exUZNQ2+oOEHQMnWfsE4K0vnp8qetZviCbk7TUaTl6/gkfTFCTi/G0u6b4C4pC3Y4Jr9 KKnyTNVMj8EyqaRT7BQoR3fZCQmXJ0h375iqouLHqg8KmsgmhmKAm+wiq8KlC9ywQ+FH oNqg== X-Gm-Message-State: AFqh2krVEz2iV/NMkMg1x36mthDjr0LKNnL2ZHjK72NhstblbFjiyfZz 3zxM5X4op+REtU2whVdgeQX7Nx4syBnKLAY5l+w= X-Google-Smtp-Source: AMrXdXuocvFtvd1PXZxuL7fPR16otKOJYisM2K2pwkJIp4DTxbAl2E7aPa1L6EzlaGxajwHbrOiHGQGGTVdyTO9LkvM= X-Received: by 2002:a25:ce8c:0:b0:78f:12e9:7e83 with SMTP id x134-20020a25ce8c000000b0078f12e97e83mr1354698ybe.587.1672736511664; Tue, 03 Jan 2023 01:01:51 -0800 (PST) MIME-Version: 1.0 References: <83y1qm39o3.fsf@gnu.org> In-Reply-To: From: Evgeni Kolev Date: Tue, 3 Jan 2023 11:01:25 +0200 Message-ID: Subject: Re: bug#60407: [PATCH] Update go-ts-mode to use Imenu facility To: Randy Taylor Content-Type: text/plain; charset="UTF-8" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 60407 Cc: Eli Zaretskii , Yuan Fu , 60407@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hi Randy, thank you for your feedback! I'm providing an updated patch below. I tested with "type Quack int" and other cases such as: type MyInt = int type Option func(s string) type List[T any] struct { head, tail *element[T] } type Number interface { int64 | float64 } After experimenting, I decided to add additional Imenu categories: "Alias" and "Type". So the final list of newly added categories is "Method", "Struct", "Interface", "Alias" and "Type". Structs and interfaces are technically a private case for "Type", but are put in their own Imenu category. Hence the "Type" category now holds all types except structs, interfaces and aliases (aliases have their own tree sitter type defined in Go's grammar.js). For reference, eglot's Imenu uses category "Class" instead of "Type". But I decided to not replicate this behavior - "Class" is not a widely used Go concept. However, I decided to replicate another eglot behaviour - prefixing the method names with the type of the receiver (for example, "(rect).area" for "func (r rect) area() float64..."). I've also addressed the other comments. I'm a bit unsure how the git commit should be formatted - the part of the message which describes changed functions/files. Please let me know if the patch can be improved. The patch is below. commit a96e70052a79881ac666ab699ffd63ed916eaf83 Author: Evgeni Kolev Date: Thu Dec 29 17:49:40 2022 +0200 Improve go-ts-mode Imenu The Imenu items are extended to support "Method", "Struct", "Interface", "Alias" and "Type". go-ts-mode is updated to use the Imenu facility added in commit b39dc7ab27a696a8607ab859aeff3c71509231f5. * lisp/progmodes/go-ts-mode.el (go-ts-mode--imenu-1) (go-ts-mode--imenu): Remove functions. (go-ts-mode--defun-name) (go-ts-mode--interface-node-p) (go-ts-mode--struct-node-p) (go-ts-mode--other-type-node-p) (go-ts-mode--alias-node-p): New functions. (go-ts-mode): Improve Imenu settings. diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el index 1d6a8a30db5..d91b555e03e 100644 --- a/lisp/progmodes/go-ts-mode.el +++ b/lisp/progmodes/go-ts-mode.el @@ -173,44 +173,6 @@ go-ts-mode--font-lock-settings '((ERROR) @font-lock-warning-face)) "Tree-sitter font-lock settings for `go-ts-mode'.") -(defun go-ts-mode--imenu () - "Return Imenu alist for the current buffer." - (let* ((node (treesit-buffer-root-node)) - (func-tree (treesit-induce-sparse-tree - node "function_declaration" nil 1000)) - (type-tree (treesit-induce-sparse-tree - node "type_spec" nil 1000)) - (func-index (go-ts-mode--imenu-1 func-tree)) - (type-index (go-ts-mode--imenu-1 type-tree))) - (append - (when func-index `(("Function" . ,func-index))) - (when type-index `(("Type" . ,type-index)))))) - -(defun go-ts-mode--imenu-1 (node) - "Helper for `go-ts-mode--imenu'. -Find string representation for NODE and set marker, then recurse -the subtrees." - (let* ((ts-node (car node)) - (children (cdr node)) - (subtrees (mapcan #'go-ts-mode--imenu-1 - children)) - (name (when ts-node - (treesit-node-text - (pcase (treesit-node-type ts-node) - ("function_declaration" - (treesit-node-child-by-field-name ts-node "name")) - ("type_spec" - (treesit-node-child-by-field-name ts-node "name")))))) - (marker (when ts-node - (set-marker (make-marker) - (treesit-node-start ts-node))))) - (cond - ((or (null ts-node) (null name)) subtrees) - (subtrees - `((,name ,(cons name marker) ,@subtrees))) - (t - `((,name . ,marker)))))) - ;;;###autoload (add-to-list 'auto-mode-alist '("\\.go\\'" . go-ts-mode)) @@ -228,9 +190,21 @@ go-ts-mode (setq-local comment-end "") (setq-local comment-start-skip (rx "//" (* (syntax whitespace)))) + ;; Navigation. + (setq-local treesit-defun-type-regexp + (regexp-opt '("method_declaration" + "function_declaration" + "type_declaration"))) + (setq-local treesit-defun-name-function #'go-ts-mode--defun-name) + ;; Imenu. - (setq-local imenu-create-index-function #'go-ts-mode--imenu) - (setq-local which-func-functions nil) + (setq-local treesit-simple-imenu-settings + `(("Function" "\\`function_declaration\\'" nil nil) + ("Method" "\\`method_declaration\\'" nil nil) + ("Struct" "\\`type_declaration\\'" go-ts-mode--struct-node-p nil) + ("Interface" "\\`type_declaration\\'" go-ts-mode--interface-node-p nil) + ("Type" "\\`type_declaration\\'" go-ts-mode--other-type-node-p nil) + ("Alias" "\\`type_declaration\\'" go-ts-mode--alias-node-p nil))) ;; Indent. (setq-local indent-tabs-mode t @@ -247,6 +221,53 @@ go-ts-mode (treesit-major-mode-setup))) +(defun go-ts-mode--defun-name (node) + "Return the defun name of NODE. +Return nil if there is no name or if NODE is not a defun node." + (pcase (treesit-node-type node) + ("function_declaration" + (treesit-node-text + (treesit-node-child-by-field-name + node "name") + t)) + ("method_declaration" + (let* ((receiver-node (treesit-node-child-by-field-name node "receiver")) + (type-node (treesit-search-subtree receiver-node "type_identifier")) + (name-node (treesit-node-child-by-field-name node "name"))) + (concat + "(" (treesit-node-text type-node) ")." + (treesit-node-text name-node)))) + ("type_declaration" + (treesit-node-text + (treesit-node-child-by-field-name + (treesit-node-child node 0 t) "name") + t)))) + +(defun go-ts-mode--interface-node-p (node) + "Return t if NODE is an interface." + (and + (string-equal "type_declaration" (treesit-node-type node)) + (treesit-search-subtree node "interface_type" nil nil 2))) + +(defun go-ts-mode--struct-node-p (node) + "Return t if NODE is a struct." + (and + (string-equal "type_declaration" (treesit-node-type node)) + (treesit-search-subtree node "struct_type" nil nil 2))) + +(defun go-ts-mode--alias-node-p (node) + "Return t if NODE is a type alias." + (and + (string-equal "type_declaration" (treesit-node-type node)) + (treesit-search-subtree node "type_alias" nil nil 1))) + +(defun go-ts-mode--other-type-node-p (node) + "Return t if NODE is a type, other than interface or struct." + (and + (string-equal "type_declaration" (treesit-node-type node)) + (not (go-ts-mode--interface-node-p node)) + (not (go-ts-mode--struct-node-p node)))) + ;; go.mod support. (defvar go-mod-ts-mode--syntax-table On Mon, Jan 2, 2023 at 12:31 AM Randy Taylor wrote: > > On Sunday, January 1st, 2023 at 12:08, Evgeni Kolev wrote: > > > > As I mentioned in the start of the mail thread - go-ts-mode's Imenu > > puts Go interfaces and structs in the same "Type" bucket. This can be > > improved in go-ts-mode. > > > > I'm providing a second patch below which splits the interfaces and > > structs into their own Imenu categories. > > > > Please let me know if I should provide the second patch later, in a > > separate thread, after the first patch is finished. I'm assuming it's > > simpler to review the patches together. If it's not - I'll provide > > them in a way to make the review easier, just let me know. > > > > Hi Evgeni! > > Thanks for working on this, and apologies for the delay. > > The patches look good to me and work well, except for one issue (and a few minor nits) mentioned below. All in one patch is probably best. > > - Type definitions are no longer captured. For example: > type Quack int > Does not show up anymore. > - go-ts-mode--struct-node-p's docstring is missing a period at the end. > - In go-ts-mode--interface-node-p and go-ts-mode--struct-node-p's docstrings, I'm not sure it's worthwhile to mention "Go". Just interface and struct should be fine. > - Should the commit message mention changes to go-ts-mode (as in the actual define-derived-mode mode part)? From debbugs-submit-bounces@debbugs.gnu.org Tue Jan 03 09:31:23 2023 Received: (at 60407) by debbugs.gnu.org; 3 Jan 2023 14:31:24 +0000 Received: from localhost ([127.0.0.1]:45028 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pCiK3-0007Ea-3N for submit@debbugs.gnu.org; Tue, 03 Jan 2023 09:31:23 -0500 Received: from mail-4018.proton.ch ([185.70.40.18]:37167) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pCiJy-0007EK-GR for 60407@debbugs.gnu.org; Tue, 03 Jan 2023 09:31:21 -0500 Date: Tue, 03 Jan 2023 14:30:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rjt.dev; s=protonmail2; t=1672756271; x=1673015471; bh=Ff17HKrc29sDxifvwgRE0e4b7wCFOKazs4xEwINJiug=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=MahC2tQDA+zkVqvUdTbKD4FXt5YkotWsk5xVrMNI6OjmxBQOJRRyQBzGi2eim89nO AtQToH98tfw+FAtdjCoTaWP5+qUYtfsGCUd+CNgkHGUgI41ditbBKh3tZSgbA2MCqs z/cmGYAJlCJOdD5PTEw1T91oI+jMeUaVBqQtK9w0d7qcc0DjJ1O86uYAfjPG/TCnm0 RC1XFdY/d5HWJPd8ORLZyUBmnYzzepXKcNo368WNMwL8mEJEwRt3pZ/lXIYd8E8eCN wYz954vTY6PZ5IPjkP8L9nl7RWhgnEnvIr5OAHiB6WYoZaBn1lOOhuOiPrtmfaZtv7 k4MRaC73wShFQ== To: Evgeni Kolev From: Randy Taylor Subject: Re: bug#60407: [PATCH] Update go-ts-mode to use Imenu facility Message-ID: In-Reply-To: References: <83y1qm39o3.fsf@gnu.org> Feedback-ID: 44397038:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 60407 Cc: Eli Zaretskii , Yuan Fu , 60407@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On Tuesday, January 3rd, 2023 at 04:01, Evgeni Kolev w= rote: > > Hi Randy, thank you for your feedback! >=20 > I'm providing an updated patch below. I tested with "type Quack int" > and other cases such as: > type MyInt =3D int > type Option func(s string) > type List[T any] struct { > head, tail *element[T] > } > type Number interface { > int64 | float64 > } >=20 > After experimenting, I decided to add additional Imenu categories: > "Alias" and "Type". > So the final list of newly added categories is "Method", "Struct", > "Interface", "Alias" and "Type". Sounds good to me. It looks like the alias type MyInt =3D int shows up in both categories: Ali= as and Type. It should probably belong just in the Alias category. >=20 > Structs and interfaces are technically a private case for "Type", but > are put in their own Imenu category. > Hence the "Type" category now holds all types except structs, > interfaces and aliases (aliases have their own tree sitter type > defined in Go's grammar.js). >=20 > For reference, eglot's Imenu uses category "Class" instead of "Type". > But I decided to not replicate this behavior - "Class" is not a widely > used Go concept. > However, I decided to replicate another eglot behaviour - prefixing > the method names with the type of the receiver (for example, > "(rect).area" for "func (r rect) area() float64..."). Great! I was going to suggest that but forgot. >=20 > I've also addressed the other comments. I'm a bit unsure how the git > commit should be formatted - the part of the message which describes > changed functions/files. >=20 > Please let me know if the patch can be improved. The patch is below. Comments below. >=20 > commit a96e70052a79881ac666ab699ffd63ed916eaf83 > Author: Evgeni Kolev evgenysw@gmail.com >=20 > Date: Thu Dec 29 17:49:40 2022 +0200 >=20 > Improve go-ts-mode Imenu Maybe this should also say "and add navigation support" (or something simil= ar)? >=20 > The Imenu items are extended to support "Method", "Struct", > "Interface", "Alias" and "Type". >=20 > go-ts-mode is updated to use the Imenu facility added in commit > b39dc7ab27a696a8607ab859aeff3c71509231f5. >=20 > * lisp/progmodes/go-ts-mode.el (go-ts-mode--imenu-1) (go-ts-mode--imenu): > Remove functions. > (go-ts-mode--defun-name) (go-ts-mode--interface-node-p) I'm no commit format expert, but I think this can be (go-ts-mode--defun-nam= e, go-ts-mode--interface-node-p) Whenever it fits on a single line, you can combine them like that. Same for= the line below. > (go-ts-mode--struct-node-p) (go-ts-mode--other-type-node-p) > (go-ts-mode--alias-node-p): New functions. > (go-ts-mode): Improve Imenu settings. I think the (go-ts-mode) part should mention that navigation support was ad= ded. >=20 > diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el > index 1d6a8a30db5..d91b555e03e 100644 > --- a/lisp/progmodes/go-ts-mode.el > +++ b/lisp/progmodes/go-ts-mode.el > @@ -173,44 +173,6 @@ go-ts-mode--font-lock-settings > '((ERROR) @font-lock-warning-face)) > "Tree-sitter font-lock settings for `go-ts-mode'.") -(defun go-ts-mode--i= menu () - "Return Imenu alist for the current buffer." - (let* ((node (tree= sit-buffer-root-node)) - (func-tree (treesit-induce-sparse-tree - node "fun= ction_declaration" nil 1000)) - (type-tree (treesit-induce-sparse-tree - no= de "type_spec" nil 1000)) - (func-index (go-ts-mode--imenu-1 func-tree)) - = (type-index (go-ts-mode--imenu-1 type-tree))) - (append - (when func-index`= (("Function" . ,func-index))) > - (when type-index `(("Type" . ,type-index)))))) - -(defun go-ts-mode--im= enu-1 (node) - "Helper for` go-ts-mode--imenu'. > -Find string representation for NODE and set marker, then recurse > -the subtrees." > - (let* ((ts-node (car node)) > - (children (cdr node)) > - (subtrees (mapcan #'go-ts-mode--imenu-1 > - children)) > - (name (when ts-node > - (treesit-node-text > - (pcase (treesit-node-type ts-node) > - ("function_declaration" > - (treesit-node-child-by-field-name ts-node "name")) > - ("type_spec" > - (treesit-node-child-by-field-name ts-node "name")))))) > - (marker (when ts-node > - (set-marker (make-marker) > - (treesit-node-start ts-node))))) > - (cond > - ((or (null ts-node) (null name)) subtrees) > - (subtrees > - `((,name ,(cons name marker) ,@subtrees))) - (t -` ((,name . ,marker)))= ))) > - > ;;;###autoload > (add-to-list 'auto-mode-alist '("\\.go\\'" . go-ts-mode)) >=20 > @@ -228,9 +190,21 @@ go-ts-mode > (setq-local comment-end "") > (setq-local comment-start-skip (rx "//" (* (syntax whitespace)))) >=20 > + ;; Navigation. > + (setq-local treesit-defun-type-regexp > + (regexp-opt '("method_declaration" > + "function_declaration" > + "type_declaration"))) > + (setq-local treesit-defun-name-function #'go-ts-mode--defun-name) > + > ;; Imenu. > - (setq-local imenu-create-index-function #'go-ts-mode--imenu) > - (setq-local which-func-functions nil) > + (setq-local treesit-simple-imenu-settings > + `(("Function" "\\\\`function_declaration\\'" nil nil) > + ("Method" "\\`method_declaration\\\\'" nil nil) + ("Struct" "\\\\`type_= declaration\\'" > go-ts-mode--struct-node-p nil) > + ("Interface" "\\`type_declaration\\\\'" go-ts-mode--interface-node-p ni= l) + ("Type" "\\\\`type_declaration\\'" > go-ts-mode--other-type-node-p nil) > + ("Alias" "\\`type_declaration\\'" > go-ts-mode--alias-node-p nil))) >=20 > ;; Indent. > (setq-local indent-tabs-mode t > @@ -247,6 +221,53 @@ go-ts-mode >=20 > (treesit-major-mode-setup))) >=20 > +(defun go-ts-mode--defun-name (node) > + "Return the defun name of NODE. > +Return nil if there is no name or if NODE is not a defun node." > + (pcase (treesit-node-type node) > + ("function_declaration" > + (treesit-node-text > + (treesit-node-child-by-field-name > + node "name") > + t)) > + ("method_declaration" > + (let* ((receiver-node (treesit-node-child-by-field-name node "receiver"= )) > + (type-node (treesit-search-subtree receiver-node > "type_identifier")) > + (name-node (treesit-node-child-by-field-name node "name"))) > + (concat > + "(" (treesit-node-text type-node) ")." > + (treesit-node-text name-node)))) > + ("type_declaration" > + (treesit-node-text > + (treesit-node-child-by-field-name > + (treesit-node-child node 0 t) "name") > + t)))) > + > +(defun go-ts-mode--interface-node-p (node) > + "Return t if NODE is an interface." > + (and > + (string-equal "type_declaration" (treesit-node-type node)) > + (treesit-search-subtree node "interface_type" nil nil 2))) I think you need to add (declare-function treesit-search-subtree "treesit.c= ") after the last one at the top of the file. > + > +(defun go-ts-mode--struct-node-p (node) > + "Return t if NODE is a struct." > + (and > + (string-equal "type_declaration" (treesit-node-type node)) > + (treesit-search-subtree node "struct_type" nil nil 2))) > + > +(defun go-ts-mode--alias-node-p (node) > + "Return t if NODE is a type alias." > + (and > + (string-equal "type_declaration" (treesit-node-type node)) > + (treesit-search-subtree node "type_alias" nil nil 1))) > + > +(defun go-ts-mode--other-type-node-p (node) > + "Return t if NODE is a type, other than interface or struct." > + (and > + (string-equal "type_declaration" (treesit-node-type node)) > + (not (go-ts-mode--interface-node-p node)) > + (not (go-ts-mode--struct-node-p node)))) Here I guess we just need a (not alias) (and the docstring updated) to fix = the issue mentioned above. > + > ;; go.mod support. >=20 > (defvar go-mod-ts-mode--syntax-table > From debbugs-submit-bounces@debbugs.gnu.org Thu Jan 05 02:25:31 2023 Received: (at 60407) by debbugs.gnu.org; 5 Jan 2023 07:25:31 +0000 Received: from localhost ([127.0.0.1]:50102 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pDKd0-000742-FL for submit@debbugs.gnu.org; Thu, 05 Jan 2023 02:25:31 -0500 Received: from mail-yw1-f175.google.com ([209.85.128.175]:45016) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pDKcx-00073m-IS for 60407@debbugs.gnu.org; Thu, 05 Jan 2023 02:25:28 -0500 Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-4b6255ce5baso61875167b3.11 for <60407@debbugs.gnu.org>; Wed, 04 Jan 2023 23:25:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=uknwCbvvNZAthCUyZzzH7jtN/kIBW6jwtyVYIrAvs4Y=; b=WXzbpEzFzNSw3LhCb2Pmq6VI+bJ8OVckAoWB2vthwNl4jeH6dY/lFmpw6L8SiSJkxa ZXeW3M0pOCyVM7WJjLK0Ny0fLvCwDSnPzHp4B84GaPxYtZti+gwAC7daiImUmxEwYEiW Pj7haF+Ed+cZgCDBH7VvH0NFf5bqhCNDqMgbmhvy1VtLDtrlFuFF/2INNkVoYe1d7fwb JacP/njqbLmGRY1cqJoG6FN3ts/erMmJXHS3GQkahfssFPSXYMQYD5wpTmM/HC4XL3dU cNsFoljlzzNo+nLbWSAwmjfbHKnSNDCfvIwssXJ3fZTzAXj7CkFQCe6SmyQNWwxwYyTw EEVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uknwCbvvNZAthCUyZzzH7jtN/kIBW6jwtyVYIrAvs4Y=; b=pUNmsBndy9qMrrXsBHCc0/hnJ57fuIMIvEk5H2MB+hE6wojvx+7oBK1NCV+1HFlVYW RUjqtYU2/NpqsMWEcRDib6YBWd9QqI66JgI6E+VWBs3ruvOvQptKqEsJQC40gXsmqAl8 r+1qjKi37viqURqYgwCJWe4CwLLHJMlQlt/1sBVOiF3hHwF6y4s/Xc66w6AGftsHw1uN d8LqAcJsPgu4k/NfjJp9Q8X7AMKn9moW7p32Swa3H8aseWgRhh33wL+c7LFgkRAkftoJ tFUS7gmtlceotLnDZZb8GwRlVoyEVX7b2gVIP0lcHgDETmlWV3D1eq/pFgmvZG6Z7UTJ XBcw== X-Gm-Message-State: AFqh2kpj6VjGeUR1ph+DehbnWMAVIeCTBlVegOIS1qCWUEPOxQXhkIlJ WiopB86bfJZ6iXelJCEzjagY4S8wPBxYGgdhkxw= X-Google-Smtp-Source: AMrXdXtvJhSpSsZ7/cs7wsskM/Q1K9xbKLednu0hmkRN1iw2VqJVryzr5OiI6zBHBzvRIrdYlILSok2ouqUEEsYFmxQ= X-Received: by 2002:a0d:df89:0:b0:4b6:dce2:93 with SMTP id i131-20020a0ddf89000000b004b6dce20093mr655392ywe.164.1672903521509; Wed, 04 Jan 2023 23:25:21 -0800 (PST) MIME-Version: 1.0 References: <83y1qm39o3.fsf@gnu.org> In-Reply-To: From: Evgeni Kolev Date: Thu, 5 Jan 2023 09:24:55 +0200 Message-ID: Subject: Re: bug#60407: [PATCH] Update go-ts-mode to use Imenu facility To: Randy Taylor Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 60407 Cc: Eli Zaretskii , Yuan Fu , 60407@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hi Randy, I'm providing the updated patch - I've addressed your comments and also added Electric Pair mode settings (variable electric-indent-chars). Thanks for your feedback. Again, please let me know if the patch can be improved. The patch is below. commit c38df01b088c3fdc0b86340a230b7397b5c81317 Author: Evgeni Kolev Date: Thu Dec 29 17:49:40 2022 +0200 Improve go-ts-mode Imenu, navigation and electric pair configuration The Imenu items are extended to support "Method", "Struct", "Interface", "Alias" and "Type". go-ts-mode is updated to use the Imenu facility added in commit b39dc7ab27a696a8607ab859aeff3c71509231f5. Variable electric-indent-chars is set in order to improve integration with Electric Pair mode. * lisp/progmodes/go-ts-mode.el (go-ts-mode--imenu-1) (go-ts-mode--imenu= ): Remove functions. (go-ts-mode--defun-name, go-ts-mode--interface-node-p) (go-ts-mode--struct-node-p, go-ts-mode--other-type-node-p) (go-ts-mode--alias-node-p): New functions. (go-ts-mode): Improve Imenu settings, navigation, add Electric Pair mode settings. diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el index 1d6a8a30db5..64e761d2f72 100644 --- a/lisp/progmodes/go-ts-mode.el +++ b/lisp/progmodes/go-ts-mode.el @@ -36,6 +36,7 @@ (declare-function treesit-node-child-by-field-name "treesit.c") (declare-function treesit-node-start "treesit.c") (declare-function treesit-node-type "treesit.c") +(declare-function treesit-search-subtree "treesit.c") (defcustom go-ts-mode-indent-offset 4 "Number of spaces for each indentation step in `go-ts-mode'." @@ -173,44 +174,6 @@ go-ts-mode--font-lock-settings '((ERROR) @font-lock-warning-face)) "Tree-sitter font-lock settings for `go-ts-mode'.") -(defun go-ts-mode--imenu () - "Return Imenu alist for the current buffer." - (let* ((node (treesit-buffer-root-node)) - (func-tree (treesit-induce-sparse-tree - node "function_declaration" nil 1000)) - (type-tree (treesit-induce-sparse-tree - node "type_spec" nil 1000)) - (func-index (go-ts-mode--imenu-1 func-tree)) - (type-index (go-ts-mode--imenu-1 type-tree))) - (append - (when func-index `(("Function" . ,func-index))) - (when type-index `(("Type" . ,type-index)))))) - -(defun go-ts-mode--imenu-1 (node) - "Helper for `go-ts-mode--imenu'. -Find string representation for NODE and set marker, then recurse -the subtrees." - (let* ((ts-node (car node)) - (children (cdr node)) - (subtrees (mapcan #'go-ts-mode--imenu-1 - children)) - (name (when ts-node - (treesit-node-text - (pcase (treesit-node-type ts-node) - ("function_declaration" - (treesit-node-child-by-field-name ts-node "name")) - ("type_spec" - (treesit-node-child-by-field-name ts-node "name")))))= ) - (marker (when ts-node - (set-marker (make-marker) - (treesit-node-start ts-node))))) - (cond - ((or (null ts-node) (null name)) subtrees) - (subtrees - `((,name ,(cons name marker) ,@subtrees))) - (t - `((,name . ,marker)))))) - ;;;###autoload (add-to-list 'auto-mode-alist '("\\.go\\'" . go-ts-mode)) @@ -228,14 +191,30 @@ go-ts-mode (setq-local comment-end "") (setq-local comment-start-skip (rx "//" (* (syntax whitespace)))) + ;; Navigation. + (setq-local treesit-defun-type-regexp + (regexp-opt '("method_declaration" + "function_declaration" + "type_declaration"))) + (setq-local treesit-defun-name-function #'go-ts-mode--defun-name) + ;; Imenu. - (setq-local imenu-create-index-function #'go-ts-mode--imenu) - (setq-local which-func-functions nil) + (setq-local treesit-simple-imenu-settings + `(("Function" "\\`function_declaration\\'" nil nil) + ("Method" "\\`method_declaration\\'" nil nil) + ("Struct" "\\`type_declaration\\'" go-ts-mode--struct-node-p nil) + ("Interface" "\\`type_declaration\\'" go-ts-mode--interface-node-p nil) + ("Type" "\\`type_declaration\\'" go-ts-mode--other-type-node-p nil) + ("Alias" "\\`type_declaration\\'" go-ts-mode--alias-node-p nil))) ;; Indent. (setq-local indent-tabs-mode t treesit-simple-indent-rules go-ts-mode--indent-rules) + ;; Electric + (setq-local electric-indent-chars + (append "{}()" electric-indent-chars)) + ;; Font-lock. (setq-local treesit-font-lock-settings go-ts-mode--font-lock-settings) (setq-local treesit-font-lock-feature-list @@ -247,6 +226,54 @@ go-ts-mode (treesit-major-mode-setup))) +(defun go-ts-mode--defun-name (node) + "Return the defun name of NODE. +Return nil if there is no name or if NODE is not a defun node." + (pcase (treesit-node-type node) + ("function_declaration" + (treesit-node-text + (treesit-node-child-by-field-name + node "name") + t)) + ("method_declaration" + (let* ((receiver-node (treesit-node-child-by-field-name node "receive= r")) + (type-node (treesit-search-subtree receiver-node "type_identifier")) + (name-node (treesit-node-child-by-field-name node "name"))) + (concat + "(" (treesit-node-text type-node) ")." + (treesit-node-text name-node)))) + ("type_declaration" + (treesit-node-text + (treesit-node-child-by-field-name + (treesit-node-child node 0 t) "name") + t)))) + +(defun go-ts-mode--interface-node-p (node) + "Return t if NODE is an interface." + (and + (string-equal "type_declaration" (treesit-node-type node)) + (treesit-search-subtree node "interface_type" nil nil 2))) + +(defun go-ts-mode--struct-node-p (node) + "Return t if NODE is a struct." + (and + (string-equal "type_declaration" (treesit-node-type node)) + (treesit-search-subtree node "struct_type" nil nil 2))) + +(defun go-ts-mode--alias-node-p (node) + "Return t if NODE is a type alias." + (and + (string-equal "type_declaration" (treesit-node-type node)) + (treesit-search-subtree node "type_alias" nil nil 1))) + +(defun go-ts-mode--other-type-node-p (node) + "Return t if NODE is a type, other than interface, struct or alias." + (and + (string-equal "type_declaration" (treesit-node-type node)) + (not (go-ts-mode--interface-node-p node)) + (not (go-ts-mode--struct-node-p node)) + (not (go-ts-mode--alias-node-p node)))) + ;; go.mod support. (defvar go-mod-ts-mode--syntax-table On Tue, Jan 3, 2023 at 4:31 PM Randy Taylor wrote: > > On Tuesday, January 3rd, 2023 at 04:01, Evgeni Kolev = wrote: > > > > Hi Randy, thank you for your feedback! > > > > I'm providing an updated patch below. I tested with "type Quack int" > > and other cases such as: > > type MyInt =3D int > > type Option func(s string) > > type List[T any] struct { > > head, tail *element[T] > > } > > type Number interface { > > int64 | float64 > > } > > > > After experimenting, I decided to add additional Imenu categories: > > "Alias" and "Type". > > So the final list of newly added categories is "Method", "Struct", > > "Interface", "Alias" and "Type". > > Sounds good to me. > > It looks like the alias type MyInt =3D int shows up in both categories: A= lias and Type. > It should probably belong just in the Alias category. > > > > > Structs and interfaces are technically a private case for "Type", but > > are put in their own Imenu category. > > Hence the "Type" category now holds all types except structs, > > interfaces and aliases (aliases have their own tree sitter type > > defined in Go's grammar.js). > > > > For reference, eglot's Imenu uses category "Class" instead of "Type". > > But I decided to not replicate this behavior - "Class" is not a widely > > used Go concept. > > However, I decided to replicate another eglot behaviour - prefixing > > the method names with the type of the receiver (for example, > > "(rect).area" for "func (r rect) area() float64..."). > > Great! I was going to suggest that but forgot. > > > > > I've also addressed the other comments. I'm a bit unsure how the git > > commit should be formatted - the part of the message which describes > > changed functions/files. > > > > Please let me know if the patch can be improved. The patch is below. > > Comments below. > > > > > commit a96e70052a79881ac666ab699ffd63ed916eaf83 > > Author: Evgeni Kolev evgenysw@gmail.com > > > > Date: Thu Dec 29 17:49:40 2022 +0200 > > > > Improve go-ts-mode Imenu > > Maybe this should also say "and add navigation support" (or something sim= ilar)? > > > > > The Imenu items are extended to support "Method", "Struct", > > "Interface", "Alias" and "Type". > > > > go-ts-mode is updated to use the Imenu facility added in commit > > b39dc7ab27a696a8607ab859aeff3c71509231f5. > > > > * lisp/progmodes/go-ts-mode.el (go-ts-mode--imenu-1) (go-ts-mode--imenu= ): > > Remove functions. > > (go-ts-mode--defun-name) (go-ts-mode--interface-node-p) > > I'm no commit format expert, but I think this can be (go-ts-mode--defun-n= ame, go-ts-mode--interface-node-p) > Whenever it fits on a single line, you can combine them like that. Same f= or the line below. > > > (go-ts-mode--struct-node-p) (go-ts-mode--other-type-node-p) > > (go-ts-mode--alias-node-p): New functions. > > (go-ts-mode): Improve Imenu settings. > > I think the (go-ts-mode) part should mention that navigation support was = added. > > > > > diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.e= l > > index 1d6a8a30db5..d91b555e03e 100644 > > --- a/lisp/progmodes/go-ts-mode.el > > +++ b/lisp/progmodes/go-ts-mode.el > > @@ -173,44 +173,6 @@ go-ts-mode--font-lock-settings > > '((ERROR) @font-lock-warning-face)) > > "Tree-sitter font-lock settings for `go-ts-mode'.") -(defun go-ts-mode-= -imenu () - "Return Imenu alist for the current buffer." - (let* ((node (tr= eesit-buffer-root-node)) - (func-tree (treesit-induce-sparse-tree - node "f= unction_declaration" nil 1000)) - (type-tree (treesit-induce-sparse-tree - = node "type_spec" nil 1000)) - (func-index (go-ts-mode--imenu-1 func-tree)) = - (type-index (go-ts-mode--imenu-1 type-tree))) - (append - (when func-inde= x` (("Function" . ,func-index))) > > - (when type-index `(("Type" . ,type-index)))))) - -(defun go-ts-mode--= imenu-1 (node) - "Helper for` go-ts-mode--imenu'. > > -Find string representation for NODE and set marker, then recurse > > -the subtrees." > > - (let* ((ts-node (car node)) > > - (children (cdr node)) > > - (subtrees (mapcan #'go-ts-mode--imenu-1 > > - children)) > > - (name (when ts-node > > - (treesit-node-text > > - (pcase (treesit-node-type ts-node) > > - ("function_declaration" > > - (treesit-node-child-by-field-name ts-node "name")) > > - ("type_spec" > > - (treesit-node-child-by-field-name ts-node "name")))))) > > - (marker (when ts-node > > - (set-marker (make-marker) > > - (treesit-node-start ts-node))))) > > - (cond > > - ((or (null ts-node) (null name)) subtrees) > > - (subtrees > > - `((,name ,(cons name marker) ,@subtrees))) - (t -` ((,name . ,marker)= ))))) > > - > > ;;;###autoload > > (add-to-list 'auto-mode-alist '("\\.go\\'" . go-ts-mode)) > > > > @@ -228,9 +190,21 @@ go-ts-mode > > (setq-local comment-end "") > > (setq-local comment-start-skip (rx "//" (* (syntax whitespace)))) > > > > + ;; Navigation. > > + (setq-local treesit-defun-type-regexp > > + (regexp-opt '("method_declaration" > > + "function_declaration" > > + "type_declaration"))) > > + (setq-local treesit-defun-name-function #'go-ts-mode--defun-name) > > + > > ;; Imenu. > > - (setq-local imenu-create-index-function #'go-ts-mode--imenu) > > - (setq-local which-func-functions nil) > > + (setq-local treesit-simple-imenu-settings > > + `(("Function" "\\\\`function_declaration\\'" nil nil) > > + ("Method" "\\`method_declaration\\\\'" nil nil) + ("Struct" "\\\\`typ= e_declaration\\'" > > go-ts-mode--struct-node-p nil) > > + ("Interface" "\\`type_declaration\\\\'" go-ts-mode--interface-node-p = nil) + ("Type" "\\\\`type_declaration\\'" > > go-ts-mode--other-type-node-p nil) > > + ("Alias" "\\`type_declaration\\'" > > go-ts-mode--alias-node-p nil))) > > > > ;; Indent. > > (setq-local indent-tabs-mode t > > @@ -247,6 +221,53 @@ go-ts-mode > > > > (treesit-major-mode-setup))) > > > > +(defun go-ts-mode--defun-name (node) > > + "Return the defun name of NODE. > > +Return nil if there is no name or if NODE is not a defun node." > > + (pcase (treesit-node-type node) > > + ("function_declaration" > > + (treesit-node-text > > + (treesit-node-child-by-field-name > > + node "name") > > + t)) > > + ("method_declaration" > > + (let* ((receiver-node (treesit-node-child-by-field-name node "receive= r")) > > + (type-node (treesit-search-subtree receiver-node > > "type_identifier")) > > + (name-node (treesit-node-child-by-field-name node "name"))) > > + (concat > > + "(" (treesit-node-text type-node) ")." > > + (treesit-node-text name-node)))) > > + ("type_declaration" > > + (treesit-node-text > > + (treesit-node-child-by-field-name > > + (treesit-node-child node 0 t) "name") > > + t)))) > > + > > +(defun go-ts-mode--interface-node-p (node) > > + "Return t if NODE is an interface." > > + (and > > + (string-equal "type_declaration" (treesit-node-type node)) > > + (treesit-search-subtree node "interface_type" nil nil 2))) > > I think you need to add (declare-function treesit-search-subtree "treesit= .c") after the last one at the top of the file. > > > + > > +(defun go-ts-mode--struct-node-p (node) > > + "Return t if NODE is a struct." > > + (and > > + (string-equal "type_declaration" (treesit-node-type node)) > > + (treesit-search-subtree node "struct_type" nil nil 2))) > > + > > +(defun go-ts-mode--alias-node-p (node) > > + "Return t if NODE is a type alias." > > + (and > > + (string-equal "type_declaration" (treesit-node-type node)) > > + (treesit-search-subtree node "type_alias" nil nil 1))) > > + > > +(defun go-ts-mode--other-type-node-p (node) > > + "Return t if NODE is a type, other than interface or struct." > > + (and > > + (string-equal "type_declaration" (treesit-node-type node)) > > + (not (go-ts-mode--interface-node-p node)) > > + (not (go-ts-mode--struct-node-p node)))) > > Here I guess we just need a (not alias) (and the docstring updated) to fi= x the issue mentioned above. > > > + > > ;; go.mod support. > > > > (defvar go-mod-ts-mode--syntax-table > > From debbugs-submit-bounces@debbugs.gnu.org Thu Jan 05 09:21:54 2023 Received: (at 60407) by debbugs.gnu.org; 5 Jan 2023 14:21:55 +0000 Received: from localhost ([127.0.0.1]:50566 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pDR7y-0008Is-K4 for submit@debbugs.gnu.org; Thu, 05 Jan 2023 09:21:54 -0500 Received: from mail-4317.proton.ch ([185.70.43.17]:54725) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pDR7w-0008Id-M0 for 60407@debbugs.gnu.org; Thu, 05 Jan 2023 09:21:53 -0500 Date: Thu, 05 Jan 2023 14:21:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rjt.dev; s=protonmail2; t=1672928505; x=1673187705; bh=2ykfPODxCQFZRIJibQhrkHMXCsFLGH5Hopdvv2K01S0=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=VDLFE/ThVR7ycGcVgphxsyBxlACeauCeKjCrlhfpBFwBJcRmVkOD+r9TB9EbpB5Gh xr03yfAPmnspLr8mFKHV7C3JMuvrVBihev3WXtn8SQlrx7BTvvs2/9VWs7r/udrU2t YXWMy9yt7dq//VIrtI9PRHyEVnWyO8qyUVFYak7WG1ebKYXuKQBtfMjE8DZ0JwPTgi srk/qN9K1OfjZJrFRBUbZh9pDrfdlGQHB56L8LCkyuoefm+wMhohKOrjzv3nY93JNj afMPabhPQk+wJ1Tdmq5ktL1pnNWb/8mW5kpkmzAd0bK6qeug0JSyJ/LdPk6Kg3e3iC XSJ/4U/ypJZ9A== To: Evgeni Kolev From: Randy Taylor Subject: Re: bug#60407: [PATCH] Update go-ts-mode to use Imenu facility Message-ID: In-Reply-To: References: <83y1qm39o3.fsf@gnu.org> Feedback-ID: 44397038:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 60407 Cc: Eli Zaretskii , 60407@debbugs.gnu.org, Yuan Fu X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On Thursday, January 5th, 2023 at 02:24, Evgeni Kolev = wrote:=20 >=20 > Hi Randy, >=20 > I'm providing the updated patch - I've addressed your comments and > also added Electric Pair mode settings (variable > electric-indent-chars). >=20 > Thanks for your feedback. Again, please let me know if the patch can > be improved. I can't speak to the electric stuff, but everything else looks good to me! Thanks for working on this. Yuan, feel free to apply if it looks good to you. From debbugs-submit-bounces@debbugs.gnu.org Sat Jan 07 19:20:16 2023 Received: (at 60407) by debbugs.gnu.org; 8 Jan 2023 00:20:16 +0000 Received: from localhost ([127.0.0.1]:59333 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pEJQ7-0007mU-SN for submit@debbugs.gnu.org; Sat, 07 Jan 2023 19:20:16 -0500 Received: from mail-pl1-f182.google.com ([209.85.214.182]:39889) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pEJQ7-0007mD-06 for 60407@debbugs.gnu.org; Sat, 07 Jan 2023 19:20:15 -0500 Received: by mail-pl1-f182.google.com with SMTP id d15so5684256pls.6 for <60407@debbugs.gnu.org>; Sat, 07 Jan 2023 16:20:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:from:to:cc:subject:date:message-id :reply-to; bh=1frELNFbYzf76evMJORRdYqpku9Ooot7mzNN3jIX6Jo=; b=km0dyvIEFJ43uLoQMQBiRQk7ojlHpbvZuWRuH4dx05hGLdYmKNueQFcRlIwB3Q1s+R ZTYS6XeYW6vTa8v+oxoWEa1ojgj3gzms1TVcWDk5TqGeXe6yPZkLZzEwclOwhJt2d5CG 61LmK5CXH/Rem6a2TA1mbUnHv1sL8lMln2NSaMqKmpeJU2DDLioVMcKA8UFUmkQBSwa8 etRSFwgYECX1Vo2Kh7BdsG/WFs7qfSwS1UopuZmd1fRfzuKMwW/l+SkdU9u/9lUTM3Pn occ2m0p5oRXhnJ4q9s0JtcTJXOXn8xBPYZenEIZmsrokpYUbyureLOpjs8ETMsd9DgtQ qU2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1frELNFbYzf76evMJORRdYqpku9Ooot7mzNN3jIX6Jo=; b=YKL6oaxdwjwP2QLhqF6IWEGuiITjKrZlsv2kLoWSVzmpKUk051jaS/HOdh6k8YVAZV 8HQoCcwRJDGaN9ZGkMMeG5HkD/ZYqGsMtQgN9N3HfvvOmK7Njovh2elfckLvqaY6dXYW 7hx8bkKOn2UwennT/NqYW4fvlWH9AkdjBcSR2w0hy9oaKySbFtPAtmtRFlhusR466d9T VwLAXsQMpVQ8zyihOCdq2gU4noafVGeg8yNfIj52TAnSiSVvUr2hLstncguprdSpx2f0 DJB2HIWtcdSBkgVbH8Qj5gemaGV59MSO/pBshu7HnVrKaXbesEYYGevt4wkA41o1nzJp gHVA== X-Gm-Message-State: AFqh2koUc/FSgXk/LBHSPPGDGe0+eTMqOEoUx0f3EyeZ/dlFKNpnAlx7 hHq8iJHl+3rlDf4+yXPUH14= X-Google-Smtp-Source: AMrXdXvrMtQs30BQNBPHWSjomx0QdFfPdpZ9ShXUl0FNBuTfHlmagCaIQJm1X9fuFGVv7M0O4UublA== X-Received: by 2002:a17:902:7596:b0:191:6239:5331 with SMTP id j22-20020a170902759600b0019162395331mr59710953pll.60.1673137209218; Sat, 07 Jan 2023 16:20:09 -0800 (PST) Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id ik9-20020a170902ab0900b00183c67844aesm3333949plb.22.2023.01.07.16.20.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Jan 2023 16:20:08 -0800 (PST) From: Yuan Fu Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Subject: Re: bug#60407: [PATCH] Update go-ts-mode to use Imenu facility Message-Id: Date: Sat, 7 Jan 2023 16:20:07 -0800 To: Randy Taylor X-Mailer: Apple Mail (2.3696.120.41.1.1) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 60407 Cc: evgenysw@gmail.com, Eli Zaretskii , 60407@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Randy Taylor writes: > On Thursday, January 5th, 2023 at 02:24, Evgeni Kolev = wrote:=20 >>=20 >> Hi Randy, >>=20 >> I'm providing the updated patch - I've addressed your comments and >> also added Electric Pair mode settings (variable >> electric-indent-chars). >>=20 >> Thanks for your feedback. Again, please let me know if the patch can >> be improved. > > I can't speak to the electric stuff, but everything else looks good to = me! > Thanks for working on this. > > Yuan, feel free to apply if it looks good to you. Ok! However, Evgeni, could you resend your patch as a attachment please? My ad-hoc setup couldn=E2=80=99t apply the inline patch directly :-) Yuan From debbugs-submit-bounces@debbugs.gnu.org Sun Jan 08 03:11:07 2023 Received: (at 60407) by debbugs.gnu.org; 8 Jan 2023 08:11:07 +0000 Received: from localhost ([127.0.0.1]:59788 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pEQln-0008DD-42 for submit@debbugs.gnu.org; Sun, 08 Jan 2023 03:11:07 -0500 Received: from mail-yw1-f181.google.com ([209.85.128.181]:37691) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pEQlk-0008Cg-U0 for 60407@debbugs.gnu.org; Sun, 08 Jan 2023 03:11:05 -0500 Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-4c15c4fc8ccso76423647b3.4 for <60407@debbugs.gnu.org>; Sun, 08 Jan 2023 00:11:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=PdoKwIAD6VjzM7KPIrCGRnZHOrsolVVO7fZSkB7DnfQ=; b=SniQpgriy9Yy0OaVAOVoKL895E9OKmxxM2Z2vunGYEy6X2e3CQOkX/Rs09PuPaBNLK CVxVPcwOQGOiFLEB+JT/dJyWJ6KIGGqRAv91AKbKPA27UAVJkrYZ/R4deH5ZDIDmFJEj Ik8aQEE8UB3P08J1Z6CSVX6N4M+VnIvVn5DpwKLA5ocEdpPgy1RYcNv6HIWGUrI4KqNg PFabVlAVfZQGns62Ijx1O/APfYjaEWboiRJ20g6OWIUMI9eBYm6iZuuVIgkYLpAzAh4v KuPFbsOjAOC0SuEGUI2EEu71VwluBLkB8UqzXwM8oyXquXFR3mJwPcjO98rLHngNK1JE Z/Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=PdoKwIAD6VjzM7KPIrCGRnZHOrsolVVO7fZSkB7DnfQ=; b=4mVC+F0Gy5k1Wc5okjQz179R9UQb/tSwT/eLOLek36CaqBEua61UfjCp3a8o0YlxME Kan1h82b9iIU0uK+fuLc4KgqJlgdAG9aGvG4e5/KXtFzRCa2lPLKivt0Jg+3yicA/zCB rk0TWt4yHBcKhQG5RmkjpMt+OckAqW32LxYKEbeVWFqshDNlgV80Xhrz+iNG0FHNoTg7 u0MjmX3ugA+TP2OPrQ02jKW5euBC5Dpu2yBVM7vxM7b9wuAdhnvr1EmD1IgXKJ5V1Con ELLixUwCNWECUPJlB93khyv3/OxDIWz8bXkq+G2ZcdIf+OC0JmnlU/IgpizQMr25YQ2x cV5Q== X-Gm-Message-State: AFqh2kqshWOQFy56DlFiEz5UBiEDeIsgW92Wz4P6bEqd1aY0mg7k0orx qImriLCvxjrv/jpTQBHFrVuATc6uMZp903L/lfg= X-Google-Smtp-Source: AMrXdXuNcSq66Pd9JVgl9ezWFA3UjLcz3c0zKcIxReKT21G5otRzr61XLveEYbcHcRKd1/5odxdSfRESQx7VptGpsO4= X-Received: by 2002:a81:7386:0:b0:391:c415:f872 with SMTP id o128-20020a817386000000b00391c415f872mr444134ywc.318.1673165459317; Sun, 08 Jan 2023 00:10:59 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Evgeni Kolev Date: Sun, 8 Jan 2023 10:10:33 +0200 Message-ID: Subject: Re: bug#60407: [PATCH] Update go-ts-mode to use Imenu facility To: Yuan Fu Content-Type: multipart/mixed; boundary="000000000000db0e2705f1bc3045" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 60407 Cc: Randy Taylor , Eli Zaretskii , 60407@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --000000000000db0e2705f1bc3045 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Yuan, sure, the .patch is attached. A side question - does it make sense to extend go-ts-mode with interactive functions? For example a function (go-ts-mode-docstring) which adds a docstring for the current type: with Go code: func sum(a, b int) int {...} the function would add a comment above the func: // sum func sum(a, b int) int {...} This is something I've implemented for myself, I'm wondering if it makes sense to contribute it to go-ts-mode. Or should I first discuss this in the devel mail list? Or maybe send another patch and have the discussion there? On Sun, Jan 8, 2023 at 2:20 AM Yuan Fu wrote: > > > Randy Taylor writes: > > > On Thursday, January 5th, 2023 at 02:24, Evgeni Kolev wrote: > >> > >> Hi Randy, > >> > >> I'm providing the updated patch - I've addressed your comments and > >> also added Electric Pair mode settings (variable > >> electric-indent-chars). > >> > >> Thanks for your feedback. Again, please let me know if the patch can > >> be improved. > > > > I can't speak to the electric stuff, but everything else looks good to = me! > > Thanks for working on this. > > > > Yuan, feel free to apply if it looks good to you. > > Ok! However, Evgeni, could you resend your patch as a attachment please? > My ad-hoc setup couldn=E2=80=99t apply the inline patch directly :-) > > Yuan --000000000000db0e2705f1bc3045 Content-Type: application/octet-stream; name="0001-Improve-go-ts-mode-Imenu-navigation-and-electric-pai.patch" Content-Disposition: attachment; filename="0001-Improve-go-ts-mode-Imenu-navigation-and-electric-pai.patch" Content-Transf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AgKGxldCog KCh0cy1ub2RlIChjYXIgbm9kZSkpCi0gICAgICAgICAoY2hpbGRyZW4gKGNkciBub2RlKSkKLSAg ICAgICAgIChzdWJ0cmVlcyAobWFwY2FuICMnZ28tdHMtbW9kZS0taW1lbnUtMQotICAgICAgICAg ICAgICAgICAgICAgICAgICAgY2hpbGRyZW4pKQotICAgICAgICAgKG5hbWUgKHdoZW4gdHMtbm9k ZQotICAgICAgICAgICAgICAgICAodHJlZXNpdC1ub2RlLXRleHQKLSAgICAgICAgICAgICAgICAg IChwY2FzZSAodHJlZXNpdC1ub2RlLXR5cGUgdHMtbm9kZSkKLSAgICAgICAgICAgICAgICAgICAg KCJmdW5jdGlvbl9kZWNsYXJhdGlvbiIKLSAgICAgICAgICAgICAgICAgICAgICh0cmVlc2l0LW5v ZGUtY2hpbGQtYnktZmllbGQtbmFtZSB0cy1ub2RlICJuYW1lIikpCi0gICAgICAgICAgICAgICAg ICAgICgidHlwZV9zcGVjIgotICAgICAgICAgICAgICAgICAgICAgKHRyZWVzaXQtbm9kZS1jaGls ZC1ieS1maWVsZC1uYW1lIHRzLW5vZGUgIm5hbWUiKSkpKSkpCi0gICAgICAgICAobWFya2VyICh3 aGVuIHRzLW5vZGUKLSAgICAgICAgICAgICAgICAgICAoc2V0LW1hcmtlciAobWFrZS1tYXJrZXIp Ci0gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKHRyZWVzaXQtbm9kZS1zdGFydCB0cy1u b2RlKSkpKSkKLSAgICAoY29uZAotICAgICAoKG9yIChudWxsIHRzLW5vZGUpIChudWxsIG5hbWUp KSBzdWJ0cmVlcykKLSAgICAgKHN1YnRyZWVzCi0gICAgICBgKCgsbmFtZSAsKGNvbnMgbmFtZSBt YXJrZXIpICxAc3VidHJlZXMpKSkKLSAgICAgKHQKLSAgICAgIGAoKCxuYW1lIC4gLG1hcmtlcikp KSkpKQotCiA7OzsjIyNhdXRvbG9hZAogKGFkZC10by1saXN0ICdhdXRvLW1vZGUtYWx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LXN0cnVjdC1ub2RlLXAgbm9kZSkpCisg ICAobm90IChnby10cy1tb2RlLS1hbGlhcy1ub2RlLXAgbm9kZSkpKSkKKwogOzsgZ28ubW9kIHN1 cHBvcnQuCiAKIChkZWZ2YXIgZ28tbW9kLXRzLW1vZGUtLXN5bnRheC10YWJsZQotLSAKMi4zMC4y Cgo= --000000000000db0e2705f1bc3045-- From debbugs-submit-bounces@debbugs.gnu.org Sun Jan 08 05:58:58 2023 Received: (at 60407) by debbugs.gnu.org; 8 Jan 2023 10:58:58 +0000 Received: from localhost ([127.0.0.1]:60006 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pETOE-0004AY-Gh for submit@debbugs.gnu.org; Sun, 08 Jan 2023 05:58:58 -0500 Received: from eggs.gnu.org ([209.51.188.92]:44648) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pETOD-0004AJ-C9 for 60407@debbugs.gnu.org; Sun, 08 Jan 2023 05:58:57 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pETO8-000795-1W; Sun, 08 Jan 2023 05:58:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=T22wLaiuVuVURn715qmAOkliseBAB6jLh0pwJ+ArIq0=; b=EKEwciCVfHoT bW6uuBd8t69tjqmNsgYRQRtbGw8mSw8wM/RXVRayEEXmwcy/ZNFLECN2TwqlnNmoVGoVxrKBq2ifC iCShqrT4KlF9Rh6YghYm6VHcRWbrThNpKS0fNgfwTg4bWmDCSL3Lg54lF5NXmbk14wa+IZ7WX7t4Y JhrS/rYS/vTwyiKlu2CdDlzwi+qzTaaO6qCJFZIorxCwCXm2bWl2mirNm3orLfDK9P+RfJ3WWzc2H j3JJA/df+QIJJcm6nN+wextc0hDCCDq7KkWDjF+TfKfjus8nOvsZllQXPtDAok/uTBxLkV3r+mb5k igg2gJmUBTFLoG7z/W3tzg==; Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pETO7-0001dy-Ha; Sun, 08 Jan 2023 05:58:51 -0500 Date: Sun, 08 Jan 2023 12:59:14 +0200 Message-Id: <83a62tqol9.fsf@gnu.org> From: Eli Zaretskii To: Evgeni Kolev In-Reply-To: (message from Evgeni Kolev on Sun, 8 Jan 2023 10:10:33 +0200) Subject: Re: bug#60407: [PATCH] Update go-ts-mode to use Imenu facility References: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 60407 Cc: dev@rjt.dev, casouri@gmail.com, 60407@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Evgeni Kolev > Date: Sun, 8 Jan 2023 10:10:33 +0200 > Cc: Randy Taylor , Eli Zaretskii , 60407@debbugs.gnu.org > > A side question - does it make sense to extend go-ts-mode with > interactive functions? > > For example a function (go-ts-mode-docstring) which adds a docstring > for the current type: > with Go code: > func sum(a, b int) int {...} > the function would add a comment above the func: > // sum > func sum(a, b int) int {...} > > This is something I've implemented for myself, I'm wondering if it > makes sense to contribute it to go-ts-mode. It makes sense, but it will have to wait until Emacs 30. The release branch is frozen, and no new features are accepted. > Or should I first discuss this in the devel mail list? Or maybe send > another patch and have the discussion there? Either one would be good. Thanks. From debbugs-submit-bounces@debbugs.gnu.org Sun Jan 08 19:35:47 2023 Received: (at 60407-done) by debbugs.gnu.org; 9 Jan 2023 00:35:47 +0000 Received: from localhost ([127.0.0.1]:35047 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pEg8h-0001f6-IO for submit@debbugs.gnu.org; Sun, 08 Jan 2023 19:35:47 -0500 Received: from mail-pf1-f170.google.com ([209.85.210.170]:47043) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pEg8e-0001ei-C5 for 60407-done@debbugs.gnu.org; Sun, 08 Jan 2023 19:35:46 -0500 Received: by mail-pf1-f170.google.com with SMTP id z7so4980594pfq.13 for <60407-done@debbugs.gnu.org>; Sun, 08 Jan 2023 16:35:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:from:to:cc:subject:date:message-id :reply-to; bh=gg+mUVu6qFAPwpyUZ488Q3DQLQj5dywF2TpV2Tym5hA=; b=Sm+QOs4+hsSbPTNOfJepHYRlpTM6UrpFwacfydnrZHnJsbeXfe6FYV1XKXhWEcmYnR ffYbAPRhMOeojBgeOVCFlMXmLJ+nZRbSVvq11ke0qYxZZGfnR1mFOQYYzllIE9VWuZ84 AaVLOG/miaSG6tYEwjS+p0otzputtLY/puYQsu0NDX2hI6prCgL+xSBDdSSyzT4cyPO6 u1CJJ3yiwyKF6VjcjthyWzt862YZtrDh+DPoGLVGwroQ29hR0k4RryfgwBp1mWrDomjR vCC8d7onjdeqR22uUR0Bud262IOMMZ0SaEcGHvkN0XOoTbrJ1lUH/OPyMfG5MOC+EhHf 1Ctw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gg+mUVu6qFAPwpyUZ488Q3DQLQj5dywF2TpV2Tym5hA=; b=5IHSU/2BvI7bNNlQ+EboSBHNNPjv/YQiqSnlS7SSMlgMtK9SfdqMybeOb7KwPl8O/Z ZCuvs4jJKlVALQbsseQl+c0+dwRk0sVv+kLbA+AZU3im/JdKO5oow2Gf8aVLCMHM+bRz agBdF5WY/PBz4BaoXB7u9G3oToSBUgAEv2VOA7Jxj227e/D8P1iKU+bq4RJ4H+T0b4Yd dXWDCddepHAR5oZOxak/18P6DAqENX+5mxmO5AmJjDdfTBFTW2HqDWeYS7ty140qYgy9 MhZsLtnW5qrc5ezZKSVm3bC2g9WTV7ekpwab8WIjG4yGHQPbWjx+BKcRa8NSHv4WqDpH QA8g== X-Gm-Message-State: AFqh2kp7smnTwhEtnCK0JDtpRUNsXipTShrssd+T7UWB7U/Axg7XtNMU saFF6vd1cfyaEoQoZssZQmE= X-Google-Smtp-Source: AMrXdXsvPXx9h4+nwGdHYCd/Gk+gMDb0fQekGMQ6a56chKTN8lMxMPPRuRExrs1IYi0d5bKFVahd7g== X-Received: by 2002:a62:834b:0:b0:582:998a:bed5 with SMTP id h72-20020a62834b000000b00582998abed5mr24298047pfe.23.1673224538276; Sun, 08 Jan 2023 16:35:38 -0800 (PST) Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id h12-20020aa796cc000000b0058248f4a02esm4689681pfq.156.2023.01.08.16.35.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Jan 2023 16:35:37 -0800 (PST) From: Yuan Fu Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Subject: Re: bug#60407: [PATCH] Update go-ts-mode to use Imenu facility Message-Id: Date: Sun, 8 Jan 2023 16:35:36 -0800 To: evgenysw@gmail.com X-Mailer: Apple Mail (2.3696.120.41.1.1) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 60407-done Cc: 60407-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Evgeni Kolev writes: > Hi Yuan, sure, the .patch is attached. Thanks. I applied the patch. Yuan From unknown Sun Jul 27 00:54:41 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Mon, 06 Feb 2023 12:24:05 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator