Skip to content

Commit 1d2b59a

Browse files
authored
Add variable declaration highlighting for go (#69)
* Add variable declaration highlighting * Remove package declaration; update parameter declaration * Simplify parameter declaration !bump-version 0.11.0
1 parent e920092 commit 1d2b59a

File tree

1 file changed

+89
-74
lines changed

1 file changed

+89
-74
lines changed

queries/go/highlights.scm

Lines changed: 89 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
; Function calls
22

33
(call_expression
4-
function: (identifier) @function)
4+
function: (identifier) @function.call)
55

66
(call_expression
77
function: (selector_expression
8-
field: (field_identifier) @function.method))
8+
field: (field_identifier) @function.method.call))
99

1010
; Function definitions
1111

@@ -19,88 +19,103 @@
1919

2020
(type_identifier) @type
2121
(field_identifier) @property
22-
(identifier) @variable
22+
(short_var_declaration left: (expression_list (identifier) @variable))
23+
(var_declaration (var_spec name: (identifier) @variable))
24+
(parameter_declaration (identifier) @variable.parameter)
25+
(const_declaration (const_spec name: (identifier) @variable))
26+
(range_clause left: (expression_list (identifier) @variable))
2327

2428
; Operators
2529

26-
"--" @operator
27-
"-" @operator
28-
"-=" @operator
29-
":=" @operator
30-
"!" @operator
31-
"!=" @operator
32-
"..." @operator
33-
"*" @operator
34-
"*" @operator
35-
"*=" @operator
36-
"/" @operator
37-
"/=" @operator
38-
"&" @operator
39-
"&&" @operator
40-
"&=" @operator
41-
"%" @operator
42-
"%=" @operator
43-
"^" @operator
44-
"^=" @operator
45-
"+" @operator
46-
"++" @operator
47-
"+=" @operator
48-
"<-" @operator
49-
"<" @operator
50-
"<<" @operator
51-
"<<=" @operator
52-
"<=" @operator
53-
"=" @operator
54-
"==" @operator
55-
">" @operator
56-
">=" @operator
57-
">>" @operator
58-
">>=" @operator
59-
"|" @operator
60-
"|=" @operator
61-
"||" @operator
30+
[
31+
"--"
32+
"-"
33+
"-="
34+
":="
35+
"!"
36+
"!="
37+
"..."
38+
"*"
39+
"*"
40+
"*="
41+
"/"
42+
"/="
43+
"&"
44+
"&&"
45+
"&="
46+
"%"
47+
"%="
48+
"^"
49+
"^="
50+
"+"
51+
"++"
52+
"+="
53+
"<-"
54+
"<"
55+
"<<"
56+
"<<="
57+
"<="
58+
"="
59+
"=="
60+
">"
61+
">="
62+
">>"
63+
">>="
64+
"|"
65+
"|="
66+
"||"
67+
] @operator
6268

6369
; Keywords
6470

65-
"break" @keyword
66-
"case" @keyword
67-
"chan" @keyword
68-
"const" @keyword
69-
"continue" @keyword
70-
"default" @keyword
71-
"defer" @keyword
72-
"else" @keyword
73-
"fallthrough" @keyword
74-
"for" @keyword
75-
"func" @keyword
76-
"go" @keyword
77-
"goto" @keyword
78-
"if" @keyword
79-
"import" @keyword
80-
"interface" @keyword
81-
"map" @keyword
82-
"package" @keyword
83-
"range" @keyword
84-
"return" @keyword
85-
"select" @keyword
86-
"struct" @keyword
87-
"switch" @keyword
88-
"type" @keyword
89-
"var" @keyword
71+
[
72+
"break"
73+
"case"
74+
"chan"
75+
"const"
76+
"continue"
77+
"default"
78+
"defer"
79+
"else"
80+
"fallthrough"
81+
"for"
82+
"func"
83+
"go"
84+
"goto"
85+
"if"
86+
"import"
87+
"interface"
88+
"map"
89+
"package"
90+
"range"
91+
"return"
92+
"select"
93+
"struct"
94+
"switch"
95+
"type"
96+
"var"
97+
] @keyword
9098

9199
; Literals
92100

93-
(interpreted_string_literal) @string
94-
(raw_string_literal) @string
95-
(rune_literal) @string
96-
(escape_sequence) @escape
101+
[
102+
(interpreted_string_literal)
103+
(raw_string_literal)
104+
(rune_literal)
105+
] @string
97106

98-
(int_literal) @number
99-
(float_literal) @number
100-
(imaginary_literal) @number
107+
(escape_sequence) @escape
101108

102-
(true) @constant.builtin
103-
(false) @constant.builtin
104-
(nil) @constant.builtin
109+
[
110+
(int_literal)
111+
(float_literal)
112+
(imaginary_literal)
113+
] @number
114+
115+
[
116+
(true)
117+
(false)
118+
(nil)
119+
] @constant.builtin
105120

106121
(comment) @comment

0 commit comments

Comments
 (0)