Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zig tree-sitter support #631

Merged
merged 3 commits into from
Aug 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,7 @@
path = helix-syntax/languages/tree-sitter-protobuf
url = https://github.com/yusdacra/tree-sitter-protobuf.git
shallow = true
[submodule "helix-syntax/languages/tree-sitter-zig"]
path = helix-syntax/languages/tree-sitter-zig
url = https://github.com/maxxnino/tree-sitter-zig
shallow = true
1 change: 1 addition & 0 deletions helix-syntax/languages/tree-sitter-zig
Submodule tree-sitter-zig added at 049162
12 changes: 12 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,15 @@ indent = { tab-width = 4, unit = " " }
# comment-token = "--"
#
# indent = { tab-width = 2, unit = " " }

[[language]]
name = "zig"
scope = "source.zig"
injection-regex = "zig"
file-types = ["zig"]
roots = ["build.zig"]
auto-format = true
comment-token = "//"

language-server = { command = "zls" }
indent = { tab-width = 4, unit = " " }
198 changes: 198 additions & 0 deletions runtime/queries/zig/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
[
(container_doc_comment)
(doc_comment)
(line_comment)
] @comment

; field in top level decl, and in struct, union...
(ContainerField
(IDENTIFIER) @property
(SuffixExpr (IDENTIFIER) @type)?
)

; error.OutOfMemory;
(SuffixExpr
"error"
"."
(IDENTIFIER) @constant
)

; var x: IDENTIFIER
type: (SuffixExpr (IDENTIFIER) @type)

; IDENTIFIER{}
constructor: (SuffixExpr (IDENTIFIER) @constructor)

; fields
(FieldInit (IDENTIFIER) @property)

; foo.bar.baz.function() calls
(
(SuffixOp
(IDENTIFIER) @function
)
.
(FnCallArguments)
)

; function() calls
(
(
(IDENTIFIER) @function
)
.
(FnCallArguments)
)

; functionn decl
(FnProto
(IDENTIFIER) @function
(SuffixExpr (IDENTIFIER) @type)?
("!")? @function.macro
)

; function parameters and types
(ParamDecl
(IDENTIFIER) @variable.parameter
":"
[
(ParamType (SuffixExpr (IDENTIFIER) @type))
(ParamType)
]
)

; switch
(SwitchItem
(SuffixExpr
"."
.
(IDENTIFIER) @constant
)
)

(INTEGER) @number

(FLOAT) @number

[
(STRINGLITERAL)
(STRINGLITERALSINGLE)
] @string

(CHAR_LITERAL) @string

[
"allowzero"
"volatile"
"anytype"
"anyframe"
(BuildinTypeExpr)
] @type.builtin

(BreakLabel (IDENTIFIER) @label)
(BlockLabel (IDENTIFIER) @label)

[
"true"
"false"
"undefined"
"unreachable"
"null"
] @constant.builtin

[
"else"
"if"
"switch"
"for"
"while"
"return"
"break"
"continue"
"defer"
"errdefer"
"async"
"nosuspend"
"await"
"suspend"
"resume"
"try"
"catch"
] @keyword.control

[
"struct"
"enum"
"union"
"error"
"packed"
"opaque"
"test"
"usingnamespace"
"export"
"extern"
"const"
"var"
"comptime"
"threadlocal"
] @keyword
voroskoi marked this conversation as resolved.
Show resolved Hide resolved

[
"pub"
"fn"
] @keyword.function

; PrecProc
[
"inline"
"noinline"
"asm"
"callconv"
"noalias"
] @attribute

[
(BUILTINIDENTIFIER)
"linksection"
"align"
] @function.builtin

[
(CompareOp)
(BitwiseOp)
(BitShiftOp)
(AdditionOp)
(MultiplyOp)
(PrefixOp)
"or"
"and"
"orelse"
"*"
"**"
"->"
"=>"
".?"
".*"
"="
] @operator
voroskoi marked this conversation as resolved.
Show resolved Hide resolved

[
";"
"."
","
":"
] @punctuation.delimiter

[
".."
"..."
"["
"]"
"("
")"
"{"
"}"
(Payload "|")
(PtrPayload "|")
(PtrIndexPayload "|")
] @punctuation
12 changes: 12 additions & 0 deletions runtime/queries/zig/indents.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
indent = [
"block",
"match_block",
"arguments",
"parameters"
]

outdent = [
"}",
"]",
")"
]