diff options
| author | maxxnino <idonthaveemail@dontknow.com> | 2021-08-23 14:46:27 +0900 |
|---|---|---|
| committer | Stephan Seitz <stephan.seitz@fau.de> | 2021-09-17 21:06:36 +0200 |
| commit | b52cccf8999bbe6424919b0e46095ad9805ffbdb (patch) | |
| tree | f72f5676da3e6347facb45c5e44c61b58eff2fb2 | |
| parent | Query: allow to pass a list to get_capture_matches (#1693) (diff) | |
| download | nvim-treesitter-b52cccf8999bbe6424919b0e46095ad9805ffbdb.tar nvim-treesitter-b52cccf8999bbe6424919b0e46095ad9805ffbdb.tar.gz nvim-treesitter-b52cccf8999bbe6424919b0e46095ad9805ffbdb.tar.bz2 nvim-treesitter-b52cccf8999bbe6424919b0e46095ad9805ffbdb.tar.lz nvim-treesitter-b52cccf8999bbe6424919b0e46095ad9805ffbdb.tar.xz nvim-treesitter-b52cccf8999bbe6424919b0e46095ad9805ffbdb.tar.zst nvim-treesitter-b52cccf8999bbe6424919b0e46095ad9805ffbdb.zip | |
highlight(zig): rework query
* improve query performance 120ms -> 6ms
* correct highlight for field, type and function
* add highlight for escape/format sequence in string
| -rw-r--r-- | queries/zig/folds.scm | 3 | ||||
| -rw-r--r-- | queries/zig/highlights.scm | 141 | ||||
| -rw-r--r-- | queries/zig/indents.scm | 4 |
3 files changed, 47 insertions, 101 deletions
diff --git a/queries/zig/folds.scm b/queries/zig/folds.scm index 70c1f7439..5fa6eb974 100644 --- a/queries/zig/folds.scm +++ b/queries/zig/folds.scm @@ -2,5 +2,8 @@ (Block) (ContainerDecl) (SwitchExpr) + (InitList) (AsmExpr) + (ErrorSetDecl) + (LINESTRING) ] @fold diff --git a/queries/zig/highlights.scm b/queries/zig/highlights.scm index 048d6e07b..a7f1071a2 100644 --- a/queries/zig/highlights.scm +++ b/queries/zig/highlights.scm @@ -4,119 +4,57 @@ (line_comment) ] @comment -(IDENTIFIER) @variable +[ + variable: (IDENTIFIER) + variable_type_function: (IDENTIFIER) +] @variable -;field in top level decl, and in struct, union... -(ContainerField - (IDENTIFIER) @field - (SuffixExpr (IDENTIFIER) @type)? -) +parameter: (IDENTIFIER) @parameter -; INFO: field become a function if type is a function? -; const u = union { this_is_function: fn () void }; -(ContainerField - (IDENTIFIER) @function - (SuffixExpr (FnProto)) -) +[ + field_member: (IDENTIFIER) + field_access: (IDENTIFIER) +] @field -;enum and tag union field is constant +;; assume TitleCase is a type ( [ - ; union(Tag){} - (ContainerDeclType (SuffixExpr (IDENTIFIER) @type)) - - ; enum{} - (ContainerDeclType "enum") - ] - (ContainerField (IDENTIFIER) @constant)? + variable_type_function: (IDENTIFIER) + field_access: (IDENTIFIER) + parameter: (IDENTIFIER) + ] @type + (#match? @type "^[A-Z]") ) - -; INFO: .IDENTIFIER is a field? -(SuffixExpr - "." - (IDENTIFIER) @field -) - -; error.OutOfMemory; -(SuffixExpr - "error" - "." - (IDENTIFIER) @constant -) - -(VarDecl - (IDENTIFIER) @type +;; assume camelCase is a function +( [ - ; const IDENTIFIER = struct/enum/union... - (SuffixExpr (ContainerDecl)) - - ; const A = u8; - (SuffixExpr (BuildinTypeExpr)) - ] -) - -; const fn_no_comma = fn (i32, i32) void; -(VarDecl - (IDENTIFIER) @function - (SuffixExpr (FnProto)) + variable_type_function: (IDENTIFIER) + field_access: (IDENTIFIER) + parameter: (IDENTIFIER) + ] @function + (#match? @function "^[a-z]+([A-Z][a-z0-9]*)+$") ) -; var x: IDENTIFIER -type: (SuffixExpr (IDENTIFIER) @type) - -; IDENTIFIER{} -constructor: (SuffixExpr (IDENTIFIER) @constructor) - -;{.IDENTIFIER = 1} -(FieldInit (IDENTIFIER) @field) +[ + function_call: (IDENTIFIER) + function: (IDENTIFIER) +] @function -; var.field -(SuffixOp (IDENTIFIER) @field) +exception: "!" @exception -; var.func().func().field -( - (SuffixOp - (IDENTIFIER) @function +( + (ContainerDeclType + [ + (ErrorUnionExpr) + "enum" + ] ) - . - (FnCallArguments) -) -; func() -( - ( - (IDENTIFIER) @function + (ContainerMembers + (ContainerField (IDENTIFIER) @constant) ) - . - (FnCallArguments) -) - -; functionn decl -(FnProto - (IDENTIFIER) @function - (SuffixExpr (IDENTIFIER) @type)? - ("!")? @exception -) - -(ParamDecl - (ParamType (SuffixExpr (IDENTIFIER) @parameter)) -) - -(ParamDecl - (IDENTIFIER) @parameter - ":" - [ - (ParamType (SuffixExpr (IDENTIFIER) @type)) - (ParamType) - ] ) -(SwitchItem - (SuffixExpr - "." - . - (IDENTIFIER) @constant - ) -) +field_constant: (IDENTIFIER) @constant (BUILTINIDENTIFIER) @function.builtin @@ -128,11 +66,13 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor) (FLOAT) @float [ - (STRINGLITERAL) + (LINESTRING) (STRINGLITERALSINGLE) ] @string (CHAR_LITERAL) @character +(EscapeSequence) @string.escape +(FormatSequence) @string.special [ "allowzero" @@ -275,3 +215,6 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor) (PtrPayload "|") (PtrIndexPayload "|") ] @punctuation.bracket + +; Error +(ERROR) @error diff --git a/queries/zig/indents.scm b/queries/zig/indents.scm index 97710195d..54fe29312 100644 --- a/queries/zig/indents.scm +++ b/queries/zig/indents.scm @@ -1,9 +1,9 @@ [ - ; BUG: why function block not indent (Block) (ContainerDecl) (SwitchExpr) (InitList) + (ContainerDecl) ] @indent [ @@ -19,5 +19,5 @@ (line_comment) (container_doc_comment) (doc_comment) - (STRINGLITERAL) + (LINESTRING) ] @ignore |
