Zig outline view (#8122)

Release Notes:

- Added Zig outline view, related #7357 
- 
<img width="762" alt="image"
src="https://github.com/zed-industries/zed/assets/13052752/a879cd98-d5e0-446e-aaed-504528b99552">
This commit is contained in:
Nikita Orlov 2024-03-01 02:24:35 +01:00 committed by GitHub
parent 4cc4f08a53
commit 7c1ef966f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 67 additions and 31 deletions

View file

@ -1,7 +1,11 @@
[ [
(container_doc_comment) (container_doc_comment)
(doc_comment) (doc_comment)
(line_comment)
] @comment.doc
[
(line_comment)
] @comment ] @comment
[ [
@ -9,12 +13,13 @@
variable_type_function: (IDENTIFIER) variable_type_function: (IDENTIFIER)
] @variable ] @variable
parameter: (IDENTIFIER) @parameter ;; func parameter
parameter: (IDENTIFIER) @property
[ [
field_member: (IDENTIFIER) field_member: (IDENTIFIER)
field_access: (IDENTIFIER) field_access: (IDENTIFIER)
] @field ] @property
;; assume TitleCase is a type ;; assume TitleCase is a type
( (
@ -23,13 +28,17 @@ parameter: (IDENTIFIER) @parameter
field_access: (IDENTIFIER) field_access: (IDENTIFIER)
parameter: (IDENTIFIER) parameter: (IDENTIFIER)
] @type ] @type
(#match? @type "^[A-Z]([a-z]+[A-Za-z0-9]*)*$") (#match? @type "^[A-Z]([a-z]+[A-Za-z0-9]*)+$")
) )
;; assume camelCase is a function
( (
(_ [
variable_type_function: (IDENTIFIER) @function variable_type_function: (IDENTIFIER)
(FnCallArguments)) field_access: (IDENTIFIER)
parameter: (IDENTIFIER)
] @function
(#match? @function "^[a-z]+([A-Z][a-z0-9]*)+$")
) )
;; assume all CAPS_1 is a constant ;; assume all CAPS_1 is a constant
@ -46,14 +55,14 @@ parameter: (IDENTIFIER) @parameter
function: (IDENTIFIER) function: (IDENTIFIER)
] @function ] @function
exception: "!" @keyword.exception exception: "!" @keyword
( (
(IDENTIFIER) @variable.builtin (IDENTIFIER) @variable.special
(#eq? @variable.builtin "_") (#eq? @variable.special "_")
) )
(PtrTypeStart "c" @variable.builtin) (PtrTypeStart "c" @variable.special)
( (
(ContainerDeclType (ContainerDeclType
@ -69,12 +78,12 @@ field_constant: (IDENTIFIER) @constant
(BUILTINIDENTIFIER) @keyword (BUILTINIDENTIFIER) @keyword
((BUILTINIDENTIFIER) @keyword.import ((BUILTINIDENTIFIER) @function
(#any-of? @keyword.import "@import" "@cImport")) (#any-of? @function "@import" "@cImport"))
(INTEGER) @number (INTEGER) @number
(FLOAT) @number.float (FLOAT) @number
[ [
"true" "true"
@ -86,12 +95,12 @@ field_constant: (IDENTIFIER) @constant
(STRINGLITERALSINGLE) (STRINGLITERALSINGLE)
] @string ] @string
(CHAR_LITERAL) @character (CHAR_LITERAL) @string.special.symbol
(EscapeSequence) @string.escape (EscapeSequence) @string.escape
(FormatSequence) @string.special (FormatSequence) @string.special
(BreakLabel (IDENTIFIER) @label) (BreakLabel (IDENTIFIER) @tag)
(BlockLabel (IDENTIFIER) @label) (BlockLabel (IDENTIFIER) @tag)
[ [
"asm" "asm"
@ -115,13 +124,13 @@ field_constant: (IDENTIFIER) @constant
[ [
"fn" "fn"
] @keyword.function ] @keyword
[ [
"and" "and"
"or" "or"
"orelse" "orelse"
] @keyword.operator ] @operator
[ [
"return" "return"
@ -131,7 +140,7 @@ field_constant: (IDENTIFIER) @constant
"if" "if"
"else" "else"
"switch" "switch"
] @keyword ] @keyword.control
[ [
"for" "for"
@ -142,7 +151,7 @@ field_constant: (IDENTIFIER) @constant
[ [
"usingnamespace" "usingnamespace"
] @keyword.import ] @constant
[ [
"try" "try"
@ -151,8 +160,9 @@ field_constant: (IDENTIFIER) @constant
[ [
"anytype" "anytype"
"anyframe"
(BuildinTypeExpr) (BuildinTypeExpr)
] @type.builtin ] @type
[ [
"const" "const"
@ -160,7 +170,7 @@ field_constant: (IDENTIFIER) @constant
"volatile" "volatile"
"allowzero" "allowzero"
"noalias" "noalias"
] @type.qualifier ] @keyword
[ [
"addrspace" "addrspace"
@ -178,13 +188,13 @@ field_constant: (IDENTIFIER) @constant
"packed" "packed"
"pub" "pub"
"threadlocal" "threadlocal"
] @attribute ] @keyword
[ [
"null" "null"
"unreachable" "unreachable"
"undefined" "undefined"
] @constant.builtin ] @constant
[ [
(CompareOp) (CompareOp)

View file

@ -1,17 +1,19 @@
[ [
(AsmExpr)
(AssignExpr)
(Block) (Block)
(BlockExpr)
(ContainerDecl) (ContainerDecl)
(SwitchExpr) (ErrorUnionExpr)
(InitList) (InitList)
(SwitchExpr)
(TestDecl)
] @indent.begin ] @indent.begin
[ [
"("
")"
"["
"]"
"{"
"}" "}"
"]"
")"
] @indent.branch ] @indent.branch
[ [

View file

@ -0,0 +1,24 @@
(Decl (
FnProto(
"fn" @context
function: (_) @name
)
)
) @item
(
Decl (
VarDecl (
"const"
variable_type_function: (_) @name
(ErrorUnionExpr) @context
)
)
) @item
(
TestDecl (
"test" @context
(STRINGLITERALSINGLE)? @name
)
) @item