* bug#62371: [PATCH] Fix go-ts-mode incorrect docstring inserted for methods
@ 2023-03-22 8:05 Evgeni Kolev
2023-03-24 18:21 ` Yuan Fu
2023-03-25 12:17 ` Eli Zaretskii
0 siblings, 2 replies; 11+ messages in thread
From: Evgeni Kolev @ 2023-03-22 8:05 UTC (permalink / raw)
To: 62371
[-- Attachment #1: Type: text/plain, Size: 894 bytes --]
The docstring inserted with go-ts-mode's C-c C-d was incorrectly
prefixed with the receiver "(myStruct).":
// (myStruct).act
func (m *myStruct) act () {...}
The above docstring is not correct because the receiver "myStruct"
should not be in the docstring.
The issue is caused by imenu and go-ts-mode--defun-name using the same
code to determine the defun name. Instead, they should produce
different results - imenu should show the "myStruct" prefix, but the
docstring should not.
This commit fixes the incorrect behavior by introducing an optional
SKIP-PREFIX parameter to (go-ts-mode--defun-name). Pressing C-c C-d
now inserts just the method name:
// act
func (m *myStruct) act () {...}
* lisp/progmodes/go-ts-mode.el (go-ts-mode--defun-name): New optional
parameter SKIP-PREFIX. (go-ts-mode-docstring):
Call (go-ts-mode--defun-name t) instead of (treesit-defun-name).
[-- Attachment #2: 0001-Fix-go-ts-mode-incorrect-docstring-inserted-for-meth.patch --]
[-- Type: application/octet-stream, Size: 3069 bytes --]
From 43ec08412868099735b229e4aeff5eb276c4f082 Mon Sep 17 00:00:00 2001
From: Evgeni Kolev <evgenysw@gmail.com>
Date: Wed, 8 Feb 2023 17:16:02 +0200
Subject: [PATCH] Fix go-ts-mode incorrect docstring inserted for methods
The docstring inserted with go-ts-mode's C-c C-d was incorrectly
prefixed with the receiver "(myStruct).":
// (myStruct).act
func (m *myStruct) act () {...}
The above docstring is not correct because the receiver "myStruct"
should not be in the docstring.
The issue is caused by imenu and go-ts-mode--defun-name using the same
code to determine the defun name. Instead, they should produce
different results - imenu should show the "myStruct" prefix, but the
docstring should not.
This commit fixes the incorrect behavior by introducing an optional
SKIP-PREFIX parameter to (go-ts-mode--defun-name). Pressing C-c C-d
now inserts just the method name:
// act
func (m *myStruct) act () {...}
* lisp/progmodes/go-ts-mode.el (go-ts-mode--defun-name): New optional
parameter SKIP-PREFIX. (go-ts-mode-docstring):
Call (go-ts-mode--defun-name t) instead of (treesit-defun-name).
---
lisp/progmodes/go-ts-mode.el | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el
index e6e8abd6445..fda6a36e42d 100644
--- a/lisp/progmodes/go-ts-mode.el
+++ b/lisp/progmodes/go-ts-mode.el
@@ -255,9 +255,10 @@ go-ts-mode
(if (treesit-ready-p 'go)
(add-to-list 'auto-mode-alist '("\\.go\\'" . go-ts-mode)))
-(defun go-ts-mode--defun-name (node)
+(defun go-ts-mode--defun-name (node &optional skip-prefix)
"Return the defun name of NODE.
-Return nil if there is no name or if NODE is not a defun node."
+Return nil if there is no name or if NODE is not a defun node.
+Methods are prefixed with the receiver name, unless SKIP-PREFIX is t."
(pcase (treesit-node-type node)
("function_declaration"
(treesit-node-text
@@ -266,11 +267,10 @@ go-ts-mode--defun-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))))
+ (receiver (treesit-node-text (treesit-search-subtree receiver-node "type_identifier")))
+ (method (treesit-node-text (treesit-node-child-by-field-name node "name"))))
+ (if skip-prefix method
+ (concat "(" receiver ")." method))))
("type_declaration"
(treesit-node-text
(treesit-node-child-by-field-name
@@ -314,7 +314,7 @@ go-ts-mode-docstring
;; go to top comment line
(while (go-ts-mode--comment-on-previous-line-p)
(forward-line -1))
- (insert "// " (treesit-defun-name defun-node))
+ (insert "// " (go-ts-mode--defun-name defun-node t))
(newline)
(backward-char))))
--
2.39.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* bug#62371: [PATCH] Fix go-ts-mode incorrect docstring inserted for methods
2023-03-22 8:05 bug#62371: [PATCH] Fix go-ts-mode incorrect docstring inserted for methods Evgeni Kolev
@ 2023-03-24 18:21 ` Yuan Fu
2023-03-25 0:58 ` Randy Taylor
2023-03-25 12:17 ` Eli Zaretskii
1 sibling, 1 reply; 11+ messages in thread
From: Yuan Fu @ 2023-03-24 18:21 UTC (permalink / raw)
To: evgeni.d.kolev; +Cc: Randy Taylor, 62371
Evgeni Kolev <evgeni.d.kolev@gmail.com> writes:
> The docstring inserted with go-ts-mode's C-c C-d was incorrectly
> prefixed with the receiver "(myStruct).":
>
> // (myStruct).act
> func (m *myStruct) act () {...}
>
> The above docstring is not correct because the receiver "myStruct"
> should not be in the docstring.
>
> The issue is caused by imenu and go-ts-mode--defun-name using the same
> code to determine the defun name. Instead, they should produce
> different results - imenu should show the "myStruct" prefix, but the
> docstring should not.
>
> This commit fixes the incorrect behavior by introducing an optional
> SKIP-PREFIX parameter to (go-ts-mode--defun-name). Pressing C-c C-d
> now inserts just the method name:
>
> // act
> func (m *myStruct) act () {...}
>
Thanks! CC’ing Randy.
Yuan
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#62371: [PATCH] Fix go-ts-mode incorrect docstring inserted for methods
2023-03-24 18:21 ` Yuan Fu
@ 2023-03-25 0:58 ` Randy Taylor
0 siblings, 0 replies; 11+ messages in thread
From: Randy Taylor @ 2023-03-25 0:58 UTC (permalink / raw)
To: Yuan Fu; +Cc: evgeni.d.kolev, 62371
On Friday, March 24th, 2023 at 14:21, Yuan Fu <casouri@gmail.com> wrote:
> Evgeni Kolev evgeni.d.kolev@gmail.com writes:
>
> > The docstring inserted with go-ts-mode's C-c C-d was incorrectly
> > prefixed with the receiver "(myStruct).":
> >
> > // (myStruct).act
> > func (m *myStruct) act () {...}
> >
> > The above docstring is not correct because the receiver "myStruct"
> > should not be in the docstring.
> >
> > The issue is caused by imenu and go-ts-mode--defun-name using the same
> > code to determine the defun name. Instead, they should produce
> > different results - imenu should show the "myStruct" prefix, but the
> > docstring should not.
> >
> > This commit fixes the incorrect behavior by introducing an optional
> > SKIP-PREFIX parameter to (go-ts-mode--defun-name). Pressing C-c C-d
> > now inserts just the method name:
> >
> > // act
> > func (m *myStruct) act () {...}
>
>
> Thanks! CC’ing Randy.
>
> Yuan
>
Thanks, I was going to look yesterday but I forgot :D.
Looks good to me!
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#62371: [PATCH] Fix go-ts-mode incorrect docstring inserted for methods
2023-03-22 8:05 bug#62371: [PATCH] Fix go-ts-mode incorrect docstring inserted for methods Evgeni Kolev
2023-03-24 18:21 ` Yuan Fu
@ 2023-03-25 12:17 ` Eli Zaretskii
2023-03-25 19:37 ` Randy Taylor
2023-03-26 1:56 ` Dmitry Gutov
1 sibling, 2 replies; 11+ messages in thread
From: Eli Zaretskii @ 2023-03-25 12:17 UTC (permalink / raw)
To: Evgeni Kolev, Randy Taylor, Dmitry Gutov, Yuan Fu; +Cc: 62371
> From: Evgeni Kolev <evgeni.d.kolev@gmail.com>
> Date: Wed, 22 Mar 2023 10:05:56 +0200
>
> The docstring inserted with go-ts-mode's C-c C-d was incorrectly
> prefixed with the receiver "(myStruct).":
>
> // (myStruct).act
> func (m *myStruct) act () {...}
>
> The above docstring is not correct because the receiver "myStruct"
> should not be in the docstring.
>
> The issue is caused by imenu and go-ts-mode--defun-name using the same
> code to determine the defun name. Instead, they should produce
> different results - imenu should show the "myStruct" prefix, but the
> docstring should not.
>
> This commit fixes the incorrect behavior by introducing an optional
> SKIP-PREFIX parameter to (go-ts-mode--defun-name). Pressing C-c C-d
> now inserts just the method name:
>
> // act
> func (m *myStruct) act () {...}
>
> * lisp/progmodes/go-ts-mode.el (go-ts-mode--defun-name): New optional
> parameter SKIP-PREFIX. (go-ts-mode-docstring):
> Call (go-ts-mode--defun-name t) instead of (treesit-defun-name).
Thanks.
Dmitry, Yuan, Randy: any comments?
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#62371: [PATCH] Fix go-ts-mode incorrect docstring inserted for methods
2023-03-25 12:17 ` Eli Zaretskii
@ 2023-03-25 19:37 ` Randy Taylor
2023-03-26 4:34 ` Eli Zaretskii
2023-03-26 1:56 ` Dmitry Gutov
1 sibling, 1 reply; 11+ messages in thread
From: Randy Taylor @ 2023-03-25 19:37 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: Evgeni Kolev, 62371, Yuan Fu, Dmitry Gutov
On Saturday, March 25th, 2023 at 08:17, Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: Evgeni Kolev evgeni.d.kolev@gmail.com
>
> > Date: Wed, 22 Mar 2023 10:05:56 +0200
> >
> > The docstring inserted with go-ts-mode's C-c C-d was incorrectly
> > prefixed with the receiver "(myStruct).":
> >
> > // (myStruct).act
> > func (m *myStruct) act () {...}
> >
> > The above docstring is not correct because the receiver "myStruct"
> > should not be in the docstring.
> >
> > The issue is caused by imenu and go-ts-mode--defun-name using the same
> > code to determine the defun name. Instead, they should produce
> > different results - imenu should show the "myStruct" prefix, but the
> > docstring should not.
> >
> > This commit fixes the incorrect behavior by introducing an optional
> > SKIP-PREFIX parameter to (go-ts-mode--defun-name). Pressing C-c C-d
> > now inserts just the method name:
> >
> > // act
> > func (m *myStruct) act () {...}
> >
> > * lisp/progmodes/go-ts-mode.el (go-ts-mode--defun-name): New optional
> > parameter SKIP-PREFIX. (go-ts-mode-docstring):
> > Call (go-ts-mode--defun-name t) instead of (treesit-defun-name).
>
>
> Thanks.
>
> Dmitry, Yuan, Randy: any comments?
I guess my email yesterday didn't make it through or got missed?
It looks good to me, feel free to install.
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#62371: [PATCH] Fix go-ts-mode incorrect docstring inserted for methods
2023-03-25 12:17 ` Eli Zaretskii
2023-03-25 19:37 ` Randy Taylor
@ 2023-03-26 1:56 ` Dmitry Gutov
2023-03-26 5:22 ` Eli Zaretskii
1 sibling, 1 reply; 11+ messages in thread
From: Dmitry Gutov @ 2023-03-26 1:56 UTC (permalink / raw)
To: Eli Zaretskii, Evgeni Kolev, Randy Taylor, Yuan Fu; +Cc: 62371
On 25/03/2023 14:17, Eli Zaretskii wrote:
> Dmitry, Yuan, Randy: any comments?
It also looks good to me. The commit message might be a little too
verbose, though -- what do you think?
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#62371: [PATCH] Fix go-ts-mode incorrect docstring inserted for methods
2023-03-25 19:37 ` Randy Taylor
@ 2023-03-26 4:34 ` Eli Zaretskii
2023-03-26 11:44 ` Randy Taylor
0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2023-03-26 4:34 UTC (permalink / raw)
To: evgeni.d.kolev, Randy Taylor; +Cc: casouri, 62371, dgutov
> Date: Sat, 25 Mar 2023 19:37:17 +0000
> From: Randy Taylor <dev@rjt.dev>
> Cc: Evgeni Kolev <evgeni.d.kolev@gmail.com>, Dmitry Gutov <dgutov@yandex.ru>, Yuan Fu <casouri@gmail.com>, 62371@debbugs.gnu.org
>
> On Saturday, March 25th, 2023 at 08:17, Eli Zaretskii <eliz@gnu.org> wrote:
> >
> > > From: Evgeni Kolev evgeni.d.kolev@gmail.com
> >
> > > Date: Wed, 22 Mar 2023 10:05:56 +0200
> > >
> > > The docstring inserted with go-ts-mode's C-c C-d was incorrectly
> > > prefixed with the receiver "(myStruct).":
> > >
> > > // (myStruct).act
> > > func (m *myStruct) act () {...}
> > >
> > > The above docstring is not correct because the receiver "myStruct"
> > > should not be in the docstring.
> > >
> > > The issue is caused by imenu and go-ts-mode--defun-name using the same
> > > code to determine the defun name. Instead, they should produce
> > > different results - imenu should show the "myStruct" prefix, but the
> > > docstring should not.
> > >
> > > This commit fixes the incorrect behavior by introducing an optional
> > > SKIP-PREFIX parameter to (go-ts-mode--defun-name). Pressing C-c C-d
> > > now inserts just the method name:
> > >
> > > // act
> > > func (m *myStruct) act () {...}
> > >
> > > * lisp/progmodes/go-ts-mode.el (go-ts-mode--defun-name): New optional
> > > parameter SKIP-PREFIX. (go-ts-mode-docstring):
> > > Call (go-ts-mode--defun-name t) instead of (treesit-defun-name).
> >
> >
> > Thanks.
> >
> > Dmitry, Yuan, Randy: any comments?
>
> I guess my email yesterday didn't make it through or got missed?
It didn't. But gnu.org had severe DNS problems all day yesterday, so
many email messages were delivered with a long delay. I wrote the
above before I saw your response.
> It looks good to me, feel free to install.
I tried, but it failed to apply. Evgeni, could you please resubmit,
relative to the emacs-29 branch?
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#62371: [PATCH] Fix go-ts-mode incorrect docstring inserted for methods
2023-03-26 1:56 ` Dmitry Gutov
@ 2023-03-26 5:22 ` Eli Zaretskii
0 siblings, 0 replies; 11+ messages in thread
From: Eli Zaretskii @ 2023-03-26 5:22 UTC (permalink / raw)
To: Dmitry Gutov; +Cc: dev, evgeni.d.kolev, 62371, casouri
> Date: Sun, 26 Mar 2023 04:56:25 +0300
> Cc: 62371@debbugs.gnu.org
> From: Dmitry Gutov <dgutov@yandex.ru>
>
> On 25/03/2023 14:17, Eli Zaretskii wrote:
> > Dmitry, Yuan, Randy: any comments?
>
> It also looks good to me. The commit message might be a little too
> verbose, though -- what do you think?
It could use some editing, yes.
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#62371: [PATCH] Fix go-ts-mode incorrect docstring inserted for methods
2023-03-26 4:34 ` Eli Zaretskii
@ 2023-03-26 11:44 ` Randy Taylor
2023-03-26 12:05 ` Eli Zaretskii
0 siblings, 1 reply; 11+ messages in thread
From: Randy Taylor @ 2023-03-26 11:44 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: evgeni.d.kolev, 62371, casouri, dgutov
On Sunday, March 26th, 2023 at 00:34, Eli Zaretskii <eliz@gnu.org> wrote:
> > Date: Sat, 25 Mar 2023 19:37:17 +0000
>
> > From: Randy Taylor dev@rjt.dev
> > Cc: Evgeni Kolev evgeni.d.kolev@gmail.com, Dmitry Gutov dgutov@yandex.ru, Yuan Fu casouri@gmail.com, 62371@debbugs.gnu.org
> >
> > On Saturday, March 25th, 2023 at 08:17, Eli Zaretskii eliz@gnu.org wrote:
> >
> > > > From: Evgeni Kolev evgeni.d.kolev@gmail.com
> > >
> > > > Date: Wed, 22 Mar 2023 10:05:56 +0200
> > > >
> > > > The docstring inserted with go-ts-mode's C-c C-d was incorrectly
> > > > prefixed with the receiver "(myStruct).":
> > > >
> > > > // (myStruct).act
> > > > func (m *myStruct) act () {...}
> > > >
> > > > The above docstring is not correct because the receiver "myStruct"
> > > > should not be in the docstring.
> > > >
> > > > The issue is caused by imenu and go-ts-mode--defun-name using the same
> > > > code to determine the defun name. Instead, they should produce
> > > > different results - imenu should show the "myStruct" prefix, but the
> > > > docstring should not.
> > > >
> > > > This commit fixes the incorrect behavior by introducing an optional
> > > > SKIP-PREFIX parameter to (go-ts-mode--defun-name). Pressing C-c C-d
> > > > now inserts just the method name:
> > > >
> > > > // act
> > > > func (m *myStruct) act () {...}
> > > >
> > > > * lisp/progmodes/go-ts-mode.el (go-ts-mode--defun-name): New optional
> > > > parameter SKIP-PREFIX. (go-ts-mode-docstring):
> > > > Call (go-ts-mode--defun-name t) instead of (treesit-defun-name).
> > >
> > > Thanks.
> > >
> > > Dmitry, Yuan, Randy: any comments?
> >
> > I guess my email yesterday didn't make it through or got missed?
>
>
> It didn't. But gnu.org had severe DNS problems all day yesterday, so
> many email messages were delivered with a long delay. I wrote the
> above before I saw your response.
>
> > It looks good to me, feel free to install.
>
>
> I tried, but it failed to apply. Evgeni, could you please resubmit,
> relative to the emacs-29 branch?
It's for master, this feature didn't make it in to emacs-29.
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#62371: [PATCH] Fix go-ts-mode incorrect docstring inserted for methods
2023-03-26 11:44 ` Randy Taylor
@ 2023-03-26 12:05 ` Eli Zaretskii
2023-03-27 10:04 ` Evgeni Kolev
0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2023-03-26 12:05 UTC (permalink / raw)
To: Randy Taylor; +Cc: evgeni.d.kolev, 62371-done, casouri, dgutov
> Date: Sun, 26 Mar 2023 11:44:05 +0000
> From: Randy Taylor <dev@rjt.dev>
> Cc: evgeni.d.kolev@gmail.com, dgutov@yandex.ru, casouri@gmail.com, 62371@debbugs.gnu.org
>
> > > It looks good to me, feel free to install.
> >
> >
> > I tried, but it failed to apply. Evgeni, could you please resubmit,
> > relative to the emacs-29 branch?
>
> It's for master, this feature didn't make it in to emacs-29.
Thanks, now installed on master, and closing the bug.
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#62371: [PATCH] Fix go-ts-mode incorrect docstring inserted for methods
2023-03-26 12:05 ` Eli Zaretskii
@ 2023-03-27 10:04 ` Evgeni Kolev
0 siblings, 0 replies; 11+ messages in thread
From: Evgeni Kolev @ 2023-03-27 10:04 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: Randy Taylor, casouri, 62371-done, dgutov
Thank you Eli, and everyone else!
The patch was meant for master, not emacs-29 - I should have stated
this. I also incorrectly sent the patch from my alternate mail
address, but the email in the patch was correct, so no harm done.
Thanks again!
On Sun, Mar 26, 2023 at 3:05 PM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > Date: Sun, 26 Mar 2023 11:44:05 +0000
> > From: Randy Taylor <dev@rjt.dev>
> > Cc: evgeni.d.kolev@gmail.com, dgutov@yandex.ru, casouri@gmail.com, 62371@debbugs.gnu.org
> >
> > > > It looks good to me, feel free to install.
> > >
> > >
> > > I tried, but it failed to apply. Evgeni, could you please resubmit,
> > > relative to the emacs-29 branch?
> >
> > It's for master, this feature didn't make it in to emacs-29.
>
> Thanks, now installed on master, and closing the bug.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2023-03-27 10:04 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-22 8:05 bug#62371: [PATCH] Fix go-ts-mode incorrect docstring inserted for methods Evgeni Kolev
2023-03-24 18:21 ` Yuan Fu
2023-03-25 0:58 ` Randy Taylor
2023-03-25 12:17 ` Eli Zaretskii
2023-03-25 19:37 ` Randy Taylor
2023-03-26 4:34 ` Eli Zaretskii
2023-03-26 11:44 ` Randy Taylor
2023-03-26 12:05 ` Eli Zaretskii
2023-03-27 10:04 ` Evgeni Kolev
2023-03-26 1:56 ` Dmitry Gutov
2023-03-26 5:22 ` Eli Zaretskii
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).