Subject: Re: bug#76330: 31.0.50; Faulty fontification in go-ts-mode

From: Randy Taylor <[email-masked]>
Date: Sun, 16 Feb 2025 21:03:29 +0000

On Sunday, February 16th, 2025 at 04:52, Eli Zaretskii <[email-masked]> wrote:
> 
> 
> > Cc: Randy Taylor [email-masked]
> 
> > From: Utkarsh Singh [email-masked]
> > Date: Sun, 16 Feb 2025 14:44:31 +0530
> > 
> > I have recently started learning Go using The Go Programming Language
> > (GOPL) book, and I'm using go-ts-mode for editing Go files.
> > 
> > Everything is working perfectly, but I have noticed a minor
> > fontification error in the following code:
> > 
> > const (
> > width, height = 600, 320 // canvas size in pixels
> > cells = 100 // number of grid cells
> > xyrange = 30.0 // axis ranges (-xyrange..+xyrange)
> > xyscale = width / 2 / xyrange // pixels per x or y unit
> > zscale = height * 0.4 // pixels per z unit
> > angle = math.Pi / 6 // angle of x, y axes (=30°)
> > )
> > 
> > Every constant except `height` is using `font-lock-constant-face`.
> > 
> > Could you please check if you can reproduce this issue?
> 
> 
> Randy and Yuan, could you please look into this?
> 
> Thanks.

Thanks for the report Utkarsh.

I've attached a patch (against emacs-30) that fixes it for me.

From 4fbe81967c97e34b8fb5a561fc4ad9145e1bd10c Mon Sep 17 00:00:00 2001
From: Randy Taylor <[email-masked]>
Date: Sun, 16 Feb 2025 15:51:43 -0500
Subject: [PATCH] Fix go-ts-mode const_spec highlighting (Bug#76330)

* lisp/progmodes/go-ts-mode.el (go-ts-mode--font-lock-settings):
Handle multiple const_spec identifiers.
* test/lisp/progmodes/go-ts-mode-resources/font-lock.go:
Add test case.
---
 lisp/progmodes/go-ts-mode.el                          | 3 ++-
 test/lisp/progmodes/go-ts-mode-resources/font-lock.go | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el
index 5110ab890f3..eb5b93008eb 100644
--- a/lisp/progmodes/go-ts-mode.el
+++ b/lisp/progmodes/go-ts-mode.el
@@ -154,7 +154,8 @@ go-ts-mode--font-lock-settings
      ,@(when (go-ts-mode--iota-query-supported-p)
          '((iota) @font-lock-constant-face))
      (const_declaration
-      (const_spec name: (identifier) @font-lock-constant-face)))
+      (const_spec name: (identifier) @font-lock-constant-face
+                  ("," name: (identifier) @font-lock-constant-face)*)))
 
    :language 'go
    :feature 'delimiter
diff --git a/test/lisp/progmodes/go-ts-mode-resources/font-lock.go b/test/lisp/progmodes/go-ts-mode-resources/font-lock.go
index 4e7a8e1710b..170bf9353c6 100644
--- a/test/lisp/progmodes/go-ts-mode-resources/font-lock.go
+++ b/test/lisp/progmodes/go-ts-mode-resources/font-lock.go
@@ -3,3 +3,9 @@ for idx, val := range arr {}
 //        ^ font-lock-variable-name-face
 for idx := 0; idx < n; idx++ {}
 //   ^ font-lock-variable-name-face
+
+const (
+	zero, one = 0, 1
+//	 ^ font-lock-constant-face
+//	       ^ font-lock-constant-face
+)
-- 
2.48.1