Skip to content

Commit 85a20da

Browse files
muirdmpsanford
authored andcommitted
Only fontify ident keys in composite literals
Previously we were fontifying things like selectors and binary expressions in composite literals. For example, we fontified "baz" in: foo{ bar.baz: 123, bar + baz: 123, } Now we are more careful to only fontify composite literal key identifiers preceded by "," or "{". Closes: #337 [via git-merge-pr]
1 parent 7ce031c commit 85a20da

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

go-mode.el

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,18 +1629,22 @@ We are looking for the right-hand-side of the type alias"
16291629
(not found-match)
16301630
(re-search-forward go--label-re end t))
16311631

1632-
(setq found-match (or
1633-
;; Composite literal field names, e.g. "Foo{Bar:". Note
1634-
;; that this gives false positives for literal maps,
1635-
;; arrays, and slices.
1636-
(go--in-composite-literal-p)
1637-
1638-
;; We are a label definition if we are at the beginning
1639-
;; of the line.
1640-
(save-excursion
1641-
(goto-char (match-beginning 1))
1642-
(skip-syntax-backward " ")
1643-
(bolp)))))
1632+
(save-excursion
1633+
(goto-char (match-beginning 1))
1634+
(skip-syntax-backward " ")
1635+
1636+
(setq found-match (or
1637+
;; We are a label/field name if we are at the
1638+
;; beginning of the line.
1639+
(bolp)
1640+
1641+
;; Composite literal field names, e.g. "Foo{Bar:". Note
1642+
;; that this gives false positives for literal maps,
1643+
;; arrays, and slices.
1644+
(and
1645+
(or (eq (char-before) ?,) (eq (char-before) ?{))
1646+
(go--in-composite-literal-p))))))
1647+
16441648
found-match))
16451649

16461650
(defun go--parameter-list-type (end)

test/go-font-lock-test.el

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,13 @@ CbarC: baz,
106106
CbarC: baz,
107107
}, {
108108
CbarC: baz,
109-
}}"))
109+
}}")
110+
111+
(go--should-fontify "TsomeMapT{
112+
foo.Zar: baz,
113+
a + b: 3,
114+
a-b: 4,
115+
}"))
110116

111117
(ert-deftest go--fontify-slices-arrays-maps ()
112118
(go--should-fontify "[]TfooT")

0 commit comments

Comments
 (0)