Skip to content

Commit

Permalink
fix(language/go): add tree-sitter query for highlighting struct prope…
Browse files Browse the repository at this point in the history
…rties

The field_identifier type was recently removed from tree-sitter-go here:
tree-sitter/tree-sitter-go#71

This means that struct keys are no longer syntax highlighted as
properties, which I dislike. Hence this new query targets the first
element of a key/value pair, and marks the first element as a @Property
if it contains an identifier.

I'm not sure if this undoes the goal of removing the field_identifier,
but for now, it resolves my personal annoyance of struct keys not be
highlighted as properties when creating a new instance of the struct.
  • Loading branch information
jimeh committed Oct 4, 2022
1 parent 3b280e2 commit 6d4665f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions modules/languages/siren-golang.el
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@
(call_expression
function: (identifier) @function.builtin
(.match? @function.builtin "^(append|cap|close|complex|copy|delete|imag|len|make|new|panic|print|println|real|recover)$"))
;; Highlight struct/block keys as properties after field_identifier was
;; removed from the Go parser:
;; https://github.com/tree-sitter/tree-sitter-go/pull/71
(keyed_element
\.
(literal_element (identifier)) @property)
]))

:config
Expand Down

0 comments on commit 6d4665f

Please sign in to comment.