@@ -453,6 +453,12 @@ statements."
453
453
(1 font-lock-type-face nil t )
454
454
(2 font-lock-type-face nil t ))
455
455
456
+ ; ; Match multi type param instantiation such as "foo[int, string]".
457
+ ; ; Does not match on "foo[int]" since that is ambiguous.
458
+ (go--match-type-instantiation
459
+ (1 font-lock-type-face nil t )
460
+ (2 font-lock-type-face nil t ))
461
+
456
462
; ; An anchored matcher for type switch case clauses.
457
463
(go--match-type-switch-case
458
464
(go--fontify-type-switch-case
@@ -1633,6 +1639,35 @@ succeeds."
1633
1639
(go--in-type-params-p))))))
1634
1640
found-match))
1635
1641
1642
+ (defconst go--type-instantiation-re (concat go-type-name-regexp " \\ s-*,\\ |,\\ s-*" go-type-name-regexp))
1643
+
1644
+ (defun go--match-type-instantiation (end )
1645
+ " Search for type params in type instantiations.
1646
+
1647
+ We look for comma separated names within square brackets. That
1648
+ means this only matches for instantiations with more than one
1649
+ param."
1650
+ (let (found-match)
1651
+ (while (and
1652
+ (not found-match)
1653
+ ; ; Look for "foo ," or ", foo" (i.e. a type name before or
1654
+ ; ; after a comma).
1655
+ (re-search-forward go--type-instantiation-re end t ))
1656
+
1657
+ (let ((match (match-string 1 )))
1658
+ ; ; If we matched "foo ,", move back one char so we can see the
1659
+ ; ; comma again on the next iteration.
1660
+ (if match
1661
+ (backward-char )
1662
+ (setq match (match-string 2 )))
1663
+
1664
+ (setq found-match (and
1665
+ (not (member match go-mode-keywords))
1666
+ (save-excursion
1667
+ (go-goto-opening-parenthesis)
1668
+ (eq (char-after ) ?\[ ))))))
1669
+ found-match))
1670
+
1636
1671
(defconst go--single-func-result-re (concat " )[[:space:]]+" go-type-name-regexp " \\ (?:$\\ |[[:space:]),]\\ )" ))
1637
1672
1638
1673
(defun go--match-single-func-result (end )
0 commit comments