branch: elpa/go-mode
commit 34974346d1f74fa835d745514c9fe9afccce8dae
Author: Muir Manders <[email protected]>
Commit: Peter Sanford <[email protected]>
Fix fontification of chained map types.
For types like "map[foo]map[bar]baz", we previously relied on array
fontification for fontifying "baz". In a previous commit I fixed array
fontification to not match this case (because it isn't an array). In
this commit I fix map value fontification to handle this case. In
particular, switch to a matcher func for map values so we can leave
point before the map value. For example, previously we would leave
point "|" here after matching the first map: "map[foo]map|[bar]baz"
which precludes the second "map" getting considered. Now we leave
things like "map[foo]|map[bar]baz" so the second "map" will be
considered on the next fontification iteration.
Updates #382.
Closes: #383 [via git-merge-pr]
---
go-mode.el | 13 ++++++++++++-
test/go-font-lock-test.el | 4 +++-
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/go-mode.el b/go-mode.el
index aa988e5..72cb8ae 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -500,7 +500,7 @@ statements."
(,(concat go-type-name-regexp "{") 1 font-lock-type-face)
;; Map value type
- (,(concat "\\_<map\\_>\\[[^]]+\\]" go-type-name-regexp) 1
font-lock-type-face)
+ (go--match-map-value 1 font-lock-type-face)
;; Map key type
(,(concat "\\_<map\\_>\\[" go-type-name-regexp) 1 font-lock-type-face)
@@ -1724,6 +1724,17 @@ We are looking for the right-hand-side of the type alias"
found-match))
+(defconst go--map-value-re
+ (concat "\\_<map\\_>\\[\\(?:\\[[^]]*\\]\\)*[^]]*\\]" go-type-name-regexp))
+
+(defun go--match-map-value (end)
+ "Search for map value types."
+ (when (re-search-forward go--map-value-re end t)
+ ;; Move point to beginning of map value in case value itself is
+ ;; also a map (we will match it next iteration).
+ (goto-char (match-beginning 1))
+ t))
+
(defconst go--label-re (concat "\\(" go-label-regexp "\\):"))
(defun go--match-ident-colon (end)
diff --git a/test/go-font-lock-test.el b/test/go-font-lock-test.el
index 9ca0f4d..c943fe4 100644
--- a/test/go-font-lock-test.el
+++ b/test/go-font-lock-test.el
@@ -130,7 +130,9 @@ a-b: 4,
(go--should-fontify "KmapK[*Tfoo.ZarT]*Tbar.ZarT")
(go--should-fontify "[]KmapK[TfooT]TbarT")
- (go--should-fontify "KmapK[[1][2][three]*Tfoo.ZarT][four][]*Tbar.ZarT"))
+ (go--should-fontify "KmapK[[1][2][three]*Tfoo.ZarT][four][]*Tbar.ZarT")
+ (go--should-fontify "KmapK[TstringT]KmapK[TstringT]Tfloat64T")
+ (go--should-fontify "KmapK[[2][c]*TintT]TboolT"))
(ert-deftest go--fontify-negation ()
;; Fontify unary "!".