From f5825cb56b847512103bf441fff05d05474a512c Mon Sep 17 00:00:00 2001 From: Noah Peart Date: Mon, 29 Apr 2024 16:14:43 -0700 Subject: [PATCH] Add go-ts-mode font-locking for function var decls * lisp/progmodes/go-ts-mode.el (go-ts-mode--font-lock-settings): Add font-locking rule for go-ts-mode functions declared in var_specs. * test/lisp/progmodes/go-ts-mode-resources/font-lock.go: New file with font-locking tests for go-ts-mode. * test/lisp/progmodes/go-ts-mode-tests.el: Add go-ts-mode font-locking tests. --- lisp/progmodes/go-ts-mode.el | 3 +++ test/lisp/progmodes/go-ts-mode-resources/font-lock.go | 11 +++++++++++ test/lisp/progmodes/go-ts-mode-tests.el | 6 ++++++ 3 files changed, 20 insertions(+) create mode 100644 test/lisp/progmodes/go-ts-mode-resources/font-lock.go diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el index aef224ab3fa..9c38985ff4e 100644 --- a/lisp/progmodes/go-ts-mode.el +++ b/lisp/progmodes/go-ts-mode.el @@ -179,6 +179,9 @@ go-ts-mode--font-lock-settings left: (expression_list (identifier) @font-lock-variable-name-face ("," (identifier) @font-lock-variable-name-face)*)) + (var_spec name: (identifier) @font-lock-function-name-face + ("," name: (identifier) @font-lock-function-name-face)* + type: (function_type)) (var_spec name: (identifier) @font-lock-variable-name-face ("," name: (identifier) @font-lock-variable-name-face)*)) diff --git a/test/lisp/progmodes/go-ts-mode-resources/font-lock.go b/test/lisp/progmodes/go-ts-mode-resources/font-lock.go new file mode 100644 index 00000000000..8d8656f96e7 --- /dev/null +++ b/test/lisp/progmodes/go-ts-mode-resources/font-lock.go @@ -0,0 +1,11 @@ +package main +var x, y, z int +// ^ font-lock-variable-name-face +// ^ font-lock-variable-name-face +// ^ font-lock-type-face +var foo, bar func(x int) int +// ^ font-lock-function-name-face +// ^ font-lock-function-name-face +// ^ font-lock-variable-name-face +// ^ font-lock-type-face +// ^ font-lock-type-face diff --git a/test/lisp/progmodes/go-ts-mode-tests.el b/test/lisp/progmodes/go-ts-mode-tests.el index fd9b57e8691..761238e60a6 100644 --- a/test/lisp/progmodes/go-ts-mode-tests.el +++ b/test/lisp/progmodes/go-ts-mode-tests.el @@ -20,6 +20,7 @@ ;;; Code: (require 'ert) +(require 'ert-font-lock) (require 'ert-x) (require 'treesit) @@ -27,5 +28,10 @@ go-ts-mode-test-indentation (skip-unless (treesit-ready-p 'go)) (ert-test-erts-file (ert-resource-file "indent.erts"))) +(ert-deftest go-ts-test-font-lock () + (skip-unless (treesit-ready-p 'go)) + (let ((treesit-font-lock-level 4)) + (ert-font-lock-test-file (ert-resource-file "font-lock.go") 'go-ts-mode))) + (provide 'go-ts-mode-tests) ;;; go-ts-mode-tests.el ends here -- 2.34.1