emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 1671e2db8a8: Fix 'go-ts-mode's incorrect docstring inserted for m


From: Eli Zaretskii
Subject: master 1671e2db8a8: Fix 'go-ts-mode's incorrect docstring inserted for methods
Date: Sun, 26 Mar 2023 08:05:10 -0400 (EDT)

branch: master
commit 1671e2db8a8d43da58c2f250c314a70aba199e09
Author: Evgeni Kolev <evgenysw@gmail.com>
Commit: Eli Zaretskii <eliz@gnu.org>

    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)
---
 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 @@
 (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))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]