branch: elpa/go-mode
commit 4fabba6e20d2da78644087a19a23361cb3b7d20d
Author: Muir Manders <[email protected]>
Commit: Peter Sanford <[email protected]>
Small fix for fontification of array types
We weren't fontifying the type for array types like "[someConst]int". We now
allow identifiers in the brackets.
I also dropped the must-be-preceded-by-non-word case since I don't think it
is
necessary and it prevents fontification at the beginning of the line.
Closes: #311 [via git-merge-pr]
---
go-mode.el | 5 ++++-
test/go-font-lock-test.el | 13 +++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/go-mode.el b/go-mode.el
index 6b55003..ae9cdb9 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -446,7 +446,10 @@ For mode=set, all covered lines will have this weight."
("\\(`[^`]*`\\)" 1 font-lock-multiline) ;; raw string literal, needed for
font-lock-syntactic-keywords
(,(concat "\\_<type\\_>[[:space:]]+\\([^[:space:](]+\\)") 1
font-lock-type-face) ;; types
(,(concat "\\_<type\\_>[[:space:]]+" go-identifier-regexp "[[:space:]]*"
go-type-name-regexp) 1 font-lock-type-face) ;; types
- (,(concat "[^[:word:][:multibyte:]]\\[\\([[:digit:]]+\\|\\.\\.\\.\\)?\\]"
go-type-name-regexp) 2 font-lock-type-face) ;; Arrays/slices
+
+ ;; Arrays/slices: []<type> | [123]<type> | [some.Const]<type> |
[someConst]<type> | [...]<type>
+ (,(concat "\\[\\(?:[[:digit:]]+\\|" go-qualified-identifier-regexp "\\|"
go-identifier-regexp "\\|\\.\\.\\.\\)?\\]" go-type-name-regexp) 1
font-lock-type-face)
+
(,(concat go-type-name-regexp "{") 1 font-lock-type-face)
(,(concat "\\_<map\\_>\\[[^]]+\\]" go-type-name-regexp) 1
font-lock-type-face) ;; map value type
(,(concat "\\_<map\\_>\\[" go-type-name-regexp) 1 font-lock-type-face) ;;
map key type
diff --git a/test/go-font-lock-test.el b/test/go-font-lock-test.el
index d5f94fe..6a20e77 100644
--- a/test/go-font-lock-test.el
+++ b/test/go-font-lock-test.el
@@ -84,6 +84,19 @@ KcaseK string:
(should-fontify "Tfoo.ZarT{")
(should-fontify "[]Tfoo.ZarT{"))
+(ert-deftest go--fontify-slices-arrays-maps ()
+ (should-fontify "[]TfooT")
+ (should-fontify "[]Tfoo.ZarT")
+ (should-fontify "[]*Tfoo.ZarT")
+
+ (should-fontify "[123]TfooT")
+ (should-fontify "[...]TfooT")
+ (should-fontify "[foo.Zar]TfooT")
+
+ (should-fontify "KmapK[*Tfoo.ZarT]*Tbar.ZarT")
+ (should-fontify "[]KmapK[TfooT]TbarT")
+ (should-fontify "KmapK[[1][2][three]*Tfoo.ZarT][four][]*Tbar.ZarT"))
+
(defun should-fontify (contents)
"Verify fontification.