highlight(zig): rework query

* improve query performance 120ms -> 6ms
 * correct highlight for field, type and function
 * add highlight for escape/format sequence in string
This commit is contained in:
maxxnino 2021-08-23 14:46:27 +09:00 committed by Stephan Seitz
parent b5153b666e
commit b52cccf899
3 changed files with 48 additions and 102 deletions

View file

@ -2,5 +2,8 @@
(Block) (Block)
(ContainerDecl) (ContainerDecl)
(SwitchExpr) (SwitchExpr)
(InitList)
(AsmExpr) (AsmExpr)
(ErrorSetDecl)
(LINESTRING)
] @fold ] @fold

View file

@ -4,120 +4,58 @@
(line_comment) (line_comment)
] @comment ] @comment
(IDENTIFIER) @variable [
variable: (IDENTIFIER)
variable_type_function: (IDENTIFIER)
] @variable
;field in top level decl, and in struct, union... parameter: (IDENTIFIER) @parameter
(ContainerField
(IDENTIFIER) @field
(SuffixExpr (IDENTIFIER) @type)?
)
; INFO: field become a function if type is a function? [
; const u = union { this_is_function: fn () void }; field_member: (IDENTIFIER)
(ContainerField field_access: (IDENTIFIER)
(IDENTIFIER) @function ] @field
(SuffixExpr (FnProto))
)
;enum and tag union field is constant ;; assume TitleCase is a type
( (
[ [
; union(Tag){} variable_type_function: (IDENTIFIER)
(ContainerDeclType (SuffixExpr (IDENTIFIER) @type)) field_access: (IDENTIFIER)
parameter: (IDENTIFIER)
; enum{} ] @type
(ContainerDeclType "enum") (#match? @type "^[A-Z]")
]
(ContainerField (IDENTIFIER) @constant)?
) )
;; assume camelCase is a function
; INFO: .IDENTIFIER is a field? (
(SuffixExpr
"."
(IDENTIFIER) @field
)
; error.OutOfMemory;
(SuffixExpr
"error"
"."
(IDENTIFIER) @constant
)
(VarDecl
(IDENTIFIER) @type
[ [
; const IDENTIFIER = struct/enum/union... variable_type_function: (IDENTIFIER)
(SuffixExpr (ContainerDecl)) field_access: (IDENTIFIER)
parameter: (IDENTIFIER)
; const A = u8; ] @function
(SuffixExpr (BuildinTypeExpr)) (#match? @function "^[a-z]+([A-Z][a-z0-9]*)+$")
]
) )
; const fn_no_comma = fn (i32, i32) void; [
(VarDecl function_call: (IDENTIFIER)
(IDENTIFIER) @function function: (IDENTIFIER)
(SuffixExpr (FnProto)) ] @function
)
; var x: IDENTIFIER exception: "!" @exception
type: (SuffixExpr (IDENTIFIER) @type)
; IDENTIFIER{} (
constructor: (SuffixExpr (IDENTIFIER) @constructor) (ContainerDeclType
[
;{.IDENTIFIER = 1} (ErrorUnionExpr)
(FieldInit (IDENTIFIER) @field) "enum"
]
; var.field
(SuffixOp (IDENTIFIER) @field)
; var.func().func().field
(
(SuffixOp
(IDENTIFIER) @function
) )
. (ContainerMembers
(FnCallArguments) (ContainerField (IDENTIFIER) @constant)
)
; func()
(
(
(IDENTIFIER) @function
)
.
(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 (BUILTINIDENTIFIER) @function.builtin
((BUILTINIDENTIFIER) @include ((BUILTINIDENTIFIER) @include
@ -128,11 +66,13 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
(FLOAT) @float (FLOAT) @float
[ [
(STRINGLITERAL) (LINESTRING)
(STRINGLITERALSINGLE) (STRINGLITERALSINGLE)
] @string ] @string
(CHAR_LITERAL) @character (CHAR_LITERAL) @character
(EscapeSequence) @string.escape
(FormatSequence) @string.special
[ [
"allowzero" "allowzero"
@ -275,3 +215,6 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
(PtrPayload "|") (PtrPayload "|")
(PtrIndexPayload "|") (PtrIndexPayload "|")
] @punctuation.bracket ] @punctuation.bracket
; Error
(ERROR) @error

View file

@ -1,9 +1,9 @@
[ [
; BUG: why function block not indent
(Block) (Block)
(ContainerDecl) (ContainerDecl)
(SwitchExpr) (SwitchExpr)
(InitList) (InitList)
(ContainerDecl)
] @indent ] @indent
[ [
@ -19,5 +19,5 @@
(line_comment) (line_comment)
(container_doc_comment) (container_doc_comment)
(doc_comment) (doc_comment)
(STRINGLITERAL) (LINESTRING)
] @ignore ] @ignore