From 7c1ef966f3fe6b5ac22774d10dd55b91126d355a Mon Sep 17 00:00:00 2001 From: Nikita Orlov Date: Fri, 1 Mar 2024 02:24:35 +0100 Subject: [PATCH] Zig outline view (#8122) Release Notes: - Added Zig outline view, related #7357 - image --- crates/languages/src/zig/highlights.scm | 60 ++++++++++++++----------- crates/languages/src/zig/indents.scm | 14 +++--- crates/languages/src/zig/outline.scm | 24 ++++++++++ 3 files changed, 67 insertions(+), 31 deletions(-) create mode 100644 crates/languages/src/zig/outline.scm diff --git a/crates/languages/src/zig/highlights.scm b/crates/languages/src/zig/highlights.scm index 53b08aef85..152a66b670 100644 --- a/crates/languages/src/zig/highlights.scm +++ b/crates/languages/src/zig/highlights.scm @@ -1,7 +1,11 @@ [ (container_doc_comment) (doc_comment) - (line_comment) + +] @comment.doc + +[ + (line_comment) ] @comment [ @@ -9,12 +13,13 @@ variable_type_function: (IDENTIFIER) ] @variable -parameter: (IDENTIFIER) @parameter +;; func parameter +parameter: (IDENTIFIER) @property [ field_member: (IDENTIFIER) field_access: (IDENTIFIER) -] @field +] @property ;; assume TitleCase is a type ( @@ -23,13 +28,17 @@ parameter: (IDENTIFIER) @parameter field_access: (IDENTIFIER) parameter: (IDENTIFIER) ] @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 - (FnCallArguments)) + [ + variable_type_function: (IDENTIFIER) + field_access: (IDENTIFIER) + parameter: (IDENTIFIER) + ] @function + (#match? @function "^[a-z]+([A-Z][a-z0-9]*)+$") ) ;; assume all CAPS_1 is a constant @@ -46,14 +55,14 @@ parameter: (IDENTIFIER) @parameter function: (IDENTIFIER) ] @function -exception: "!" @keyword.exception +exception: "!" @keyword ( - (IDENTIFIER) @variable.builtin - (#eq? @variable.builtin "_") + (IDENTIFIER) @variable.special + (#eq? @variable.special "_") ) -(PtrTypeStart "c" @variable.builtin) +(PtrTypeStart "c" @variable.special) ( (ContainerDeclType @@ -69,12 +78,12 @@ field_constant: (IDENTIFIER) @constant (BUILTINIDENTIFIER) @keyword -((BUILTINIDENTIFIER) @keyword.import - (#any-of? @keyword.import "@import" "@cImport")) +((BUILTINIDENTIFIER) @function + (#any-of? @function "@import" "@cImport")) (INTEGER) @number -(FLOAT) @number.float +(FLOAT) @number [ "true" @@ -86,12 +95,12 @@ field_constant: (IDENTIFIER) @constant (STRINGLITERALSINGLE) ] @string -(CHAR_LITERAL) @character +(CHAR_LITERAL) @string.special.symbol (EscapeSequence) @string.escape (FormatSequence) @string.special -(BreakLabel (IDENTIFIER) @label) -(BlockLabel (IDENTIFIER) @label) +(BreakLabel (IDENTIFIER) @tag) +(BlockLabel (IDENTIFIER) @tag) [ "asm" @@ -115,13 +124,13 @@ field_constant: (IDENTIFIER) @constant [ "fn" -] @keyword.function +] @keyword [ "and" "or" "orelse" -] @keyword.operator +] @operator [ "return" @@ -131,7 +140,7 @@ field_constant: (IDENTIFIER) @constant "if" "else" "switch" -] @keyword +] @keyword.control [ "for" @@ -142,7 +151,7 @@ field_constant: (IDENTIFIER) @constant [ "usingnamespace" -] @keyword.import +] @constant [ "try" @@ -151,8 +160,9 @@ field_constant: (IDENTIFIER) @constant [ "anytype" + "anyframe" (BuildinTypeExpr) -] @type.builtin +] @type [ "const" @@ -160,7 +170,7 @@ field_constant: (IDENTIFIER) @constant "volatile" "allowzero" "noalias" -] @type.qualifier +] @keyword [ "addrspace" @@ -178,13 +188,13 @@ field_constant: (IDENTIFIER) @constant "packed" "pub" "threadlocal" -] @attribute +] @keyword [ "null" "unreachable" "undefined" -] @constant.builtin +] @constant [ (CompareOp) diff --git a/crates/languages/src/zig/indents.scm b/crates/languages/src/zig/indents.scm index 9c27ddcba3..76876d5645 100644 --- a/crates/languages/src/zig/indents.scm +++ b/crates/languages/src/zig/indents.scm @@ -1,17 +1,19 @@ [ + (AsmExpr) + (AssignExpr) (Block) + (BlockExpr) (ContainerDecl) - (SwitchExpr) + (ErrorUnionExpr) (InitList) + (SwitchExpr) + (TestDecl) ] @indent.begin [ - "(" - ")" - "[" - "]" - "{" "}" + "]" + ")" ] @indent.branch [ diff --git a/crates/languages/src/zig/outline.scm b/crates/languages/src/zig/outline.scm new file mode 100644 index 0000000000..d87cff2058 --- /dev/null +++ b/crates/languages/src/zig/outline.scm @@ -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