chore: query formatting

This commit is contained in:
Pham Huy Hoang 2024-01-06 15:05:50 +09:00 committed by Christian Clason
parent 79975d6557
commit 57a8acf0c4
674 changed files with 18466 additions and 12648 deletions

View file

@ -1,21 +1,21 @@
[
(for_statement)
(if_statement)
(while_statement)
(do_statement)
(switch_statement)
(case_statement)
(function_definition)
(struct_specifier)
(enum_specifier)
(comment)
(preproc_if)
(preproc_elif)
(preproc_else)
(preproc_ifdef)
(preproc_function_def)
(initializer_list)
(gnu_asm_expression)
(for_statement)
(if_statement)
(while_statement)
(do_statement)
(switch_statement)
(case_statement)
(function_definition)
(struct_specifier)
(enum_specifier)
(comment)
(preproc_if)
(preproc_elif)
(preproc_else)
(preproc_ifdef)
(preproc_function_def)
(initializer_list)
(gnu_asm_expression)
] @fold
(compound_statement

View file

@ -1,6 +1,9 @@
; Lower priority to prefer @variable.parameter when identifier appears in parameter_declaration.
((identifier) @variable (#set! "priority" 95))
(preproc_def (preproc_arg) @variable)
((identifier) @variable
(#set! "priority" 95))
(preproc_def
(preproc_arg) @variable)
[
"default"
@ -17,7 +20,10 @@
"sizeof"
"offsetof"
] @keyword.operator
(alignof_expression . _ @keyword.operator)
(alignof_expression
.
_ @keyword.operator)
"return" @keyword.return
@ -30,10 +36,10 @@
] @keyword.repeat
[
"if"
"else"
"case"
"switch"
"if"
"else"
"case"
"switch"
] @keyword.conditional
[
@ -52,42 +58,48 @@
"#include" @keyword.import
[ ";" ":" "," "::" ] @punctuation.delimiter
[
";"
":"
","
"::"
] @punctuation.delimiter
"..." @punctuation.special
[ "(" ")" "[" "]" "{" "}"] @punctuation.bracket
[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
[
"="
"-"
"*"
"/"
"+"
"%"
"~"
"|"
"&"
"^"
"<<"
">>"
"->"
"."
"<"
"<="
">="
">"
"=="
"!="
"!"
"&&"
"||"
"-="
"+="
"*="
@ -102,42 +114,54 @@
"++"
] @operator
;; Make sure the comma operator is given a highlight group after the comma
;; punctuator so the operator is highlighted properly.
(comma_expression [ "," ] @operator)
; Make sure the comma operator is given a highlight group after the comma
; punctuator so the operator is highlighted properly.
(comma_expression
"," @operator)
[
(true)
(false)
] @boolean
(conditional_expression [ "?" ":" ] @keyword.conditional.ternary)
(conditional_expression
[
"?"
":"
] @keyword.conditional.ternary)
(string_literal) @string
(system_lib_string) @string
(escape_sequence) @string.escape
(null) @constant.builtin
(number_literal) @number
(char_literal) @character
((preproc_arg) @function.macro (#set! "priority" 90))
((preproc_arg) @function.macro
(#set! "priority" 90))
(preproc_defined) @function.macro
((field_expression
(field_identifier) @property) @_parent
(#not-has-parent? @_parent template_method function_declarator call_expression))
(field_identifier) @property) @_parent
(#not-has-parent? @_parent template_method function_declarator call_expression))
(field_designator) @property
((field_identifier) @property
(#has-ancestor? @property field_declaration)
(#not-has-ancestor? @property function_declarator))
(#has-ancestor? @property field_declaration)
(#not-has-ancestor? @property function_declarator))
(statement_identifier) @label
[
(type_identifier)
(type_descriptor)
(type_identifier)
(type_descriptor)
] @type
(storage_class_specifier) @keyword.storage
@ -156,14 +180,20 @@
(primitive_type) @type.builtin
(sized_type_specifier _ @type.builtin type: _?)
(sized_type_specifier
_ @type.builtin
type: _?)
((identifier) @constant
(#lua-match? @constant "^[A-Z][A-Z0-9_]+$"))
(preproc_def (preproc_arg) @constant
(#lua-match? @constant "^[A-Z][A-Z0-9_]+$"))
(preproc_def
(preproc_arg) @constant
(#lua-match? @constant "^[A-Z][A-Z0-9_]+$"))
(enumerator
name: (identifier) @constant)
(case_statement
value: (identifier) @constant)
@ -181,7 +211,9 @@
"__clang_wide_literal_encoding__"
"__FUNCTION__" "__func__" "__PRETTY_FUNCTION__"
"__VA_ARGS__" "__VA_OPT__"))
(preproc_def (preproc_arg) @constant.builtin
(preproc_def
(preproc_arg) @constant.builtin
; format-ignore
(#any-of? @constant.builtin
"stderr" "stdin" "stdout"
@ -197,21 +229,26 @@
"__VA_ARGS__" "__VA_OPT__"))
(attribute_specifier
(argument_list (identifier) @variable.builtin))
(argument_list
(identifier) @variable.builtin))
((attribute_specifier
(argument_list (call_expression
function: (identifier) @variable.builtin))))
(argument_list
(call_expression
function: (identifier) @variable.builtin))))
((call_expression
function: (identifier) @function.builtin)
(#lua-match? @function.builtin "^__builtin_"))
((call_expression
function: (identifier) @function.builtin)
function: (identifier) @function.builtin)
(#has-ancestor? @function.builtin attribute_specifier))
;; Preproc def / undef
; Preproc def / undef
(preproc_def
name: (_) @constant)
(preproc_call
directive: (preproc_directive) @_u
argument: (_) @constant
@ -219,15 +256,21 @@
(call_expression
function: (identifier) @function.call)
(call_expression
function: (field_expression
field: (field_identifier) @function.call))
function:
(field_expression
field: (field_identifier) @function.call))
(function_declarator
declarator: (identifier) @function)
(function_declarator
declarator: (parenthesized_declarator
(pointer_declarator
declarator: (field_identifier) @function)))
declarator:
(parenthesized_declarator
(pointer_declarator
declarator: (field_identifier) @function)))
(preproc_function_def
name: (identifier) @function.macro)
@ -236,7 +279,7 @@
((comment) @comment.documentation
(#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$"))
;; Parameters
; Parameters
(parameter_declaration
declarator: (identifier) @variable.parameter)
@ -268,8 +311,8 @@
; declarator: _
; (declaration
; declarator: (pointer_declarator) @variable.parameter))
(preproc_params (identifier) @variable.parameter)
(preproc_params
(identifier) @variable.parameter)
[
"__attribute__"

View file

@ -1,5 +1,5 @@
[
(compound_statement)
(compound_statement)
(field_declaration_list)
(case_statement)
(enumerator_list)
@ -7,56 +7,62 @@
(initializer_list)
(init_declarator)
] @indent.begin
; With current indent logic, if we capture expression_statement with @indent.begin
; It will be affected by _parent_ node with error subnodes deep down the tree
; So narrow indent capture to check for error inside expression statement only,
; So narrow indent capture to check for error inside expression statement only,
(expression_statement
(_) @indent.begin
";" @indent.end)
(ERROR
"for" "(" @indent.begin ";" ";" ")" @indent.end)
"for"
"(" @indent.begin
";"
";"
")" @indent.end)
((for_statement
body: (_) @_body) @indent.begin
body: (_) @_body) @indent.begin
(#not-has-type? @_body compound_statement))
(while_statement
condition: (_) @indent.begin)
((while_statement
body: (_) @_body) @indent.begin
body: (_) @_body) @indent.begin
(#not-has-type? @_body compound_statement))
(
(if_statement)
((if_statement)
.
(ERROR "else" @indent.begin))
(ERROR
"else" @indent.begin))
(if_statement
condition: (_) @indent.begin)
;; Supports if without braces (but not both if-else without braces)
; Supports if without braces (but not both if-else without braces)
((if_statement
consequence:
(_ ";" @indent.end) @_consequence
(#not-has-type? @_consequence compound_statement)
consequence:
(_
";" @indent.end) @_consequence
(#not-has-type? @_consequence compound_statement)
alternative:
(else_clause
(else_clause
"else" @indent.branch
[
(if_statement (compound_statement) @indent.dedent)? @indent.dedent
[
(if_statement
(compound_statement) @indent.dedent)? @indent.dedent
(compound_statement)? @indent.dedent
(_)? @indent.dedent
]
)?
) @indent.begin)
])?) @indent.begin)
(else_clause (_ . "{" @indent.branch))
(else_clause
(_
.
"{" @indent.branch))
(compound_statement "}" @indent.end)
(compound_statement
"}" @indent.end)
[
")"
@ -79,12 +85,16 @@
(string_literal)
] @indent.ignore
((ERROR (parameter_declaration)) @indent.align
(#set! indent.open_delimiter "(")
(#set! indent.close_delimiter ")"))
([(argument_list) (parameter_list)] @indent.align
((ERROR
(parameter_declaration)) @indent.align
(#set! indent.open_delimiter "(")
(#set! indent.close_delimiter ")"))
([
(argument_list)
(parameter_list)
] @indent.align
(#set! indent.open_delimiter "(")
(#set! indent.close_delimiter ")"))
(comment) @indent.auto

View file

@ -1,8 +1,8 @@
((preproc_arg) @injection.content
(#set! injection.language "c"))
(#set! injection.language "c"))
((comment) @injection.content
(#set! injection.language "comment"))
(#set! injection.language "comment"))
((comment) @injection.content
(#match? @injection.content "/\\*!([a-zA-Z]+:)?re2c")
@ -14,8 +14,11 @@
((call_expression
function: (identifier) @_function
arguments: (argument_list
. (string_literal (string_content) @injection.content)))
arguments:
(argument_list
.
(string_literal
(string_content) @injection.content)))
; format-ignore
(#any-of? @_function
"printf" "printf_s"
@ -29,12 +32,16 @@
"cscanf" "_cscanf"
"printw"
"scanw")
(#set! injection.language "printf"))
(#set! injection.language "printf"))
((call_expression
function: (identifier) @_function
arguments: (argument_list
(_) . (string_literal (string_content) @injection.content)))
arguments:
(argument_list
(_)
.
(string_literal
(string_content) @injection.content)))
; format-ignore
(#any-of? @_function
"fprintf" "fprintf_s"
@ -57,12 +64,18 @@
"vw_printw" "vwprintw"
"wscanw"
"vw_scanw" "vwscanw")
(#set! injection.language "printf"))
(#set! injection.language "printf"))
((call_expression
function: (identifier) @_function
arguments: (argument_list
(_) . (_) . (string_literal (string_content) @injection.content)))
arguments:
(argument_list
(_)
.
(_)
.
(string_literal
(string_content) @injection.content)))
; format-ignore
(#any-of? @_function
"sprintf_s"
@ -75,15 +88,22 @@
"vsnwprintf_s"
"mvprintw"
"mvscanw")
(#set! injection.language "printf"))
(#set! injection.language "printf"))
((call_expression
function: (identifier) @_function
arguments: (argument_list
(_) . (_) . (_) . (string_literal (string_content) @injection.content)))
(#any-of? @_function "mvwprintw"
"mvwscanw")
(#set! injection.language "printf"))
arguments:
(argument_list
(_)
.
(_)
.
(_)
.
(string_literal
(string_content) @injection.content)))
(#any-of? @_function "mvwprintw" "mvwscanw")
(#set! injection.language "printf"))
; TODO: add when asm is added
; (gnu_asm_expression assembly_code: (string_literal) @injection.content

View file

@ -1,53 +1,67 @@
;; Functions definitions
; Functions definitions
(function_declarator
declarator: (identifier) @local.definition.function)
(preproc_function_def
name: (identifier) @local.definition.macro) @local.scope
(preproc_def
name: (identifier) @local.definition.macro)
(pointer_declarator
declarator: (identifier) @local.definition.var)
(parameter_declaration
declarator: (identifier) @local.definition.parameter)
(init_declarator
declarator: (identifier) @local.definition.var)
(array_declarator
declarator: (identifier) @local.definition.var)
(declaration
declarator: (identifier) @local.definition.var)
(enum_specifier
name: (_) @local.definition.type
(enumerator_list
(enumerator name: (identifier) @local.definition.var)))
(enumerator
name: (identifier) @local.definition.var)))
;; Type / Struct / Enum
; Type / Struct / Enum
(field_declaration
declarator: (field_identifier) @local.definition.field)
(type_definition
declarator: (type_identifier) @local.definition.type)
(struct_specifier
name: (type_identifier) @local.definition.type)
;; goto
(labeled_statement (statement_identifier) @local.definition)
; goto
(labeled_statement
(statement_identifier) @local.definition)
;; References
; References
(identifier) @local.reference
((field_identifier) @local.reference
(#set! reference.kind "field"))
(#set! reference.kind "field"))
((type_identifier) @local.reference
(#set! reference.kind "type"))
(#set! reference.kind "type"))
(goto_statement (statement_identifier) @local.reference)
(goto_statement
(statement_identifier) @local.reference)
;; Scope
; Scope
[
(for_statement)
(if_statement)
(while_statement)
(translation_unit)
(function_definition)
(compound_statement) ; a block in curly braces
(struct_specifier)
(for_statement)
(if_statement)
(while_statement)
(translation_unit)
(function_definition)
(compound_statement) ; a block in curly braces
(struct_specifier)
] @local.scope