feat(zig): basic treesitter support for zig. (#359)

* Add basic support for navigating zig files.

* Fix struct start position.

* Add test and tagged unions.

* Add test.
This commit is contained in:
Gordon Cassie 2024-04-16 13:27:37 -07:00 committed by GitHub
parent 24ebacab58
commit 5961a1afc0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 107 additions and 0 deletions

32
queries/zig/aerial.scm Normal file
View file

@ -0,0 +1,32 @@
(Decl
(VarDecl
variable_type_function: (IDENTIFIER) @name
(#set! "kind" "Struct")
(_
(_
(ContainerDecl
(ContainerDeclType "struct") @symbol
))))
)
(Decl
(VarDecl
variable_type_function: (IDENTIFIER) @name
(#set! "kind" "Struct")
(_
(_
(ContainerDecl
(ContainerDeclType "union") @symbol
))))
)
(FnProto
function: (IDENTIFIER) @name
(#set! "kind" "Function")
) @symbol
(TestDecl
(STRINGLITERALSINGLE) @name
(#set! "kind" "Function")
) @symbol

View file

@ -0,0 +1,62 @@
[
{
"col": 0,
"end_col": 16,
"end_lnum": 1,
"kind": "Function",
"level": 0,
"lnum": 1,
"name": "myFunc",
"selection_range": {
"col": 3,
"end_col": 9,
"end_lnum": 1,
"lnum": 1
}
},
{
"col": 17,
"end_col": 23,
"end_lnum": 5,
"kind": "Struct",
"level": 0,
"lnum": 5,
"name": "MyStruct",
"selection_range": {
"col": 6,
"end_col": 14,
"end_lnum": 5,
"lnum": 5
}
},
{
"col": 22,
"end_col": 33,
"end_lnum": 9,
"kind": "Struct",
"level": 0,
"lnum": 9,
"name": "MyTaggedUnion",
"selection_range": {
"col": 6,
"end_col": 19,
"end_lnum": 9,
"lnum": 9
}
},
{
"col": 0,
"end_col": 1,
"end_lnum": 13,
"kind": "Function",
"level": 0,
"lnum": 11,
"name": "\"my test\"",
"selection_range": {
"col": 5,
"end_col": 14,
"end_lnum": 11,
"lnum": 11
}
}
]

View file

@ -0,0 +1,13 @@
fn myFunc() bool {
return true;
}
const MyStruct = struct {
is_true: bool,
};
const MyTaggedUnion = union(enum) { choice1, choice2 };
test "my test" {
myFunc();
}