1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-02-04 22:50:59 -08:00

Fix 'go-ts-mode's 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.  This commit fixes the incorrect
behavior.
* lisp/progmodes/go-ts-mode.el (go-ts-mode--defun-name): New
optional argument SKIP-PREFIX.
(go-ts-mode-docstring): Call (go-ts-mode--defun-name t)
instead of (treesit-defun-name).  (Bug#62371)
This commit is contained in:
Evgeni Kolev 2023-02-08 17:16:02 +02:00 committed by Eli Zaretskii
parent 28db56d5f0
commit 1671e2db8a

View file

@ -255,9 +255,10 @@
(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 @@ Return nil if there is no name or if NODE is not a defun node."
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 @@ comment already exists, jump to it."
;; 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))))