emacs-diffs
[Top][All Lists]
Advanced

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

emacs-29 859b4227e3d: Update go-ts-mode to support latest tree-sitter-go


From: Yuan Fu
Subject: emacs-29 859b4227e3d: Update go-ts-mode to support latest tree-sitter-go grammar
Date: Wed, 10 Apr 2024 01:55:30 -0400 (EDT)

branch: emacs-29
commit 859b4227e3de9f8e7bc26367540aa315cefc37dc
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>

    Update go-ts-mode to support latest tree-sitter-go grammar
    
    tree-sitter-go changed method_spec to method_elem in
    
https://github.com/tree-sitter/tree-sitter-go/commit/b82ab803d887002a0af11f6ce63d72884580bf33
    
    * lisp/progmodes/go-ts-mode.el:
    (go-ts-mode--method-elem-supported-p): New function.
    (go-ts-mode--font-lock-settings): Conditionally use method_elem or
    method_spec in the query.
---
 lisp/progmodes/go-ts-mode.el | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el
index e8a176e3d9d..a5b49bd8313 100644
--- a/lisp/progmodes/go-ts-mode.el
+++ b/lisp/progmodes/go-ts-mode.el
@@ -112,6 +112,13 @@
   (ignore-errors
     (or (treesit-query-string "" '((iota) @font-lock-constant-face) 'go) t)))
 
+;; tree-sitter-go changed method_spec to method_elem in
+;; 
https://github.com/tree-sitter/tree-sitter-go/commit/b82ab803d887002a0af11f6ce63d72884580bf33
+(defun go-ts-mode--method-elem-supported-p ()
+  "Return t if Go grammar uses `method_elem' instead of `method_spec'."
+  (ignore-errors
+    (or (treesit-query-string "" '((method_elem) @cap) 'go) t)))
+
 (defvar go-ts-mode--font-lock-settings
   (treesit-font-lock-rules
    :language 'go
@@ -136,11 +143,13 @@
 
    :language 'go
    :feature 'definition
-   '((function_declaration
+   `((function_declaration
       name: (identifier) @font-lock-function-name-face)
      (method_declaration
       name: (field_identifier) @font-lock-function-name-face)
-     (method_spec
+     (,(if (go-ts-mode--method-elem-supported-p)
+           'method_elem
+         'method_spec)
       name: (field_identifier) @font-lock-function-name-face)
      (field_declaration
       name: (field_identifier) @font-lock-property-name-face)



reply via email to

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