on master help sign in
Add zig tree-sitter support (#631)

* Add initial zig tree-sitter support * zig/highlights.scm: remove unnecessary queries * Add zig/indents.toml

commitf22e0aa2ae4169851b43d2225e6a43ef36442659 authorvoroskoi <60064214+voroskoi@users.noreply.github.com> dateSat 28 Aug 2021, 06:32 (5 years ago) parent5cee3b6
5 files changed+227
.gitmodules+4 helix-syntax/languages/tree-sitter-zig+1 languages.toml+12 runtime/queries/zig/highlights.scm+198 runtime/queries/zig/indents.toml+12
.gitmodules+4
@@ -102,3 +102,7 @@
102102 path = helix-syntax/languages/tree-sitter-protobuf
103103 url = https://github.com/yusdacra/tree-sitter-protobuf.git
104104 shallow = true
105+[submodule "helix-syntax/languages/tree-sitter-zig"]
106+ path = helix-syntax/languages/tree-sitter-zig
107+ url = https://github.com/maxxnino/tree-sitter-zig
108+ shallow = true
helix-syntax/languages/tree-sitter-zignew file+1

Submodule changed.

languages.toml+12
@@ -233,3 +233,15 @@ indent = { tab-width = 4, unit = " " }
233233# comment-token = "--"
234234#
235235# indent = { tab-width = 2, unit = " " }
236+
237+[[language]]
238+name = "zig"
239+scope = "source.zig"
240+injection-regex = "zig"
241+file-types = ["zig"]
242+roots = ["build.zig"]
243+auto-format = true
244+comment-token = "//"
245+
246+language-server = { command = "zls" }
247+indent = { tab-width = 4, unit = " " }
runtime/queries/zig/highlights.scmnew file+198
@@ -0,0 +1,198 @@
1+[
2+ (container_doc_comment)
3+ (doc_comment)
4+ (line_comment)
5+] @comment
6+
7+; field in top level decl, and in struct, union...
8+(ContainerField
9+ (IDENTIFIER) @property
10+ (SuffixExpr (IDENTIFIER) @type)?
11+)
12+
13+; error.OutOfMemory;
14+(SuffixExpr
15+ "error"
16+ "."
17+ (IDENTIFIER) @constant
18+)
19+
20+; var x: IDENTIFIER
21+type: (SuffixExpr (IDENTIFIER) @type)
22+
23+; IDENTIFIER{}
24+constructor: (SuffixExpr (IDENTIFIER) @constructor)
25+
26+; fields
27+(FieldInit (IDENTIFIER) @property)
28+
29+; foo.bar.baz.function() calls
30+(
31+ (SuffixOp
32+ (IDENTIFIER) @function
33+ )
34+ .
35+ (FnCallArguments)
36+)
37+
38+; function() calls
39+(
40+ (
41+ (IDENTIFIER) @function
42+ )
43+ .
44+ (FnCallArguments)
45+)
46+
47+; functionn decl
48+(FnProto
49+ (IDENTIFIER) @function
50+ (SuffixExpr (IDENTIFIER) @type)?
51+ ("!")? @function.macro
52+)
53+
54+; function parameters and types
55+(ParamDecl
56+ (IDENTIFIER) @variable.parameter
57+ ":"
58+ [
59+ (ParamType (SuffixExpr (IDENTIFIER) @type))
60+ (ParamType)
61+ ]
62+)
63+
64+; switch
65+(SwitchItem
66+ (SuffixExpr
67+ "."
68+ .
69+ (IDENTIFIER) @constant
70+ )
71+)
72+
73+(INTEGER) @number
74+
75+(FLOAT) @number
76+
77+[
78+ (STRINGLITERAL)
79+ (STRINGLITERALSINGLE)
80+] @string
81+
82+(CHAR_LITERAL) @string
83+
84+[
85+ "allowzero"
86+ "volatile"
87+ "anytype"
88+ "anyframe"
89+ (BuildinTypeExpr)
90+] @type.builtin
91+
92+(BreakLabel (IDENTIFIER) @label)
93+(BlockLabel (IDENTIFIER) @label)
94+
95+[
96+ "true"
97+ "false"
98+ "undefined"
99+ "unreachable"
100+ "null"
101+] @constant.builtin
102+
103+[
104+ "else"
105+ "if"
106+ "switch"
107+ "for"
108+ "while"
109+ "return"
110+ "break"
111+ "continue"
112+ "defer"
113+ "errdefer"
114+ "async"
115+ "nosuspend"
116+ "await"
117+ "suspend"
118+ "resume"
119+ "try"
120+ "catch"
121+] @keyword.control
122+
123+[
124+ "struct"
125+ "enum"
126+ "union"
127+ "error"
128+ "packed"
129+ "opaque"
130+ "test"
131+ "usingnamespace"
132+ "export"
133+ "extern"
134+ "const"
135+ "var"
136+ "comptime"
137+ "threadlocal"
138+] @keyword
139+
140+[
141+ "pub"
142+ "fn"
143+] @keyword.function
144+
145+; PrecProc
146+[
147+ "inline"
148+ "noinline"
149+ "asm"
150+ "callconv"
151+ "noalias"
152+] @attribute
153+
154+[
155+ (BUILTINIDENTIFIER)
156+ "linksection"
157+ "align"
158+] @function.builtin
159+
160+[
161+ (CompareOp)
162+ (BitwiseOp)
163+ (BitShiftOp)
164+ (AdditionOp)
165+ (MultiplyOp)
166+ (PrefixOp)
167+ "or"
168+ "and"
169+ "orelse"
170+ "*"
171+ "**"
172+ "->"
173+ "=>"
174+ ".?"
175+ ".*"
176+ "="
177+] @operator
178+
179+[
180+ ";"
181+ "."
182+ ","
183+ ":"
184+] @punctuation.delimiter
185+
186+[
187+ ".."
188+ "..."
189+ "["
190+ "]"
191+ "("
192+ ")"
193+ "{"
194+ "}"
195+ (Payload "|")
196+ (PtrPayload "|")
197+ (PtrIndexPayload "|")
198+] @punctuation
runtime/queries/zig/indents.tomlnew file+12
@@ -0,0 +1,12 @@
1+indent = [
2+ "block",
3+ "match_block",
4+ "arguments",
5+ "parameters"
6+]
7+
8+outdent = [
9+ "}",
10+ "]",
11+ ")"
12+]