From: Evgeni Kolev <evgeni.d.kolev@gmail.com>
To: 62371@debbugs.gnu.org
Subject: bug#62371: [PATCH] Fix go-ts-mode incorrect docstring inserted for methods
Date: Wed, 22 Mar 2023 10:05:56 +0200 [thread overview]
Message-ID: <CAMCrgaV+HnSvOqVeG+SAzymAgBd3otLENyULF_TQsQCOCORXRg@mail.gmail.com> (raw)
[-- 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
next reply other threads:[~2023-03-22 8:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-22 8:05 Evgeni Kolev [this message]
2023-03-24 18:21 ` bug#62371: [PATCH] Fix go-ts-mode incorrect docstring inserted for methods 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAMCrgaV+HnSvOqVeG+SAzymAgBd3otLENyULF_TQsQCOCORXRg@mail.gmail.com \
--to=evgeni.d.kolev@gmail.com \
--cc=62371@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.