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,17 +1,13 @@
[
(import_list)
(when_expression)
(control_structure_body)
(lambda_literal)
(function_body)
(primary_constructor)
(secondary_constructor)
(anonymous_initializer)
(class_body)
(enum_class_body)
(interpolated_expression)
(import_list)
(when_expression)
(control_structure_body)
(lambda_literal)
(function_body)
(primary_constructor)
(secondary_constructor)
(anonymous_initializer)
(class_body)
(enum_class_body)
(interpolated_expression)
] @fold

View file

@ -1,53 +1,53 @@
;;; Identifiers
; Identifiers
(simple_identifier) @variable
; `it` keyword inside lambdas
; FIXME: This will highlight the keyword outside of lambdas since tree-sitter
; does not allow us to check for arbitrary nestation
((simple_identifier) @variable.builtin
(#eq? @variable.builtin "it"))
(#eq? @variable.builtin "it"))
; `field` keyword inside property getter/setter
; FIXME: This will highlight the keyword outside of getters and setters
; since tree-sitter does not allow us to check for arbitrary nestation
((simple_identifier) @variable.builtin
(#eq? @variable.builtin "field"))
(#eq? @variable.builtin "field"))
[
"this"
"super"
"this@"
"super@"
"this"
"super"
"this@"
"super@"
] @variable.builtin
; NOTE: for consistency with "super@"
(super_expression "@" @variable.builtin)
(super_expression
"@" @variable.builtin)
(class_parameter
(simple_identifier) @property)
(simple_identifier) @property)
(class_body
(property_declaration
(variable_declaration
(simple_identifier) @property)))
(property_declaration
(variable_declaration
(simple_identifier) @property)))
; id_1.id_2.id_3: `id_2` and `id_3` are assumed as object properties
(_
(navigation_suffix
(simple_identifier) @property))
(navigation_suffix
(simple_identifier) @property))
; SCREAMING CASE identifiers are assumed to be constants
((simple_identifier) @constant
(#lua-match? @constant "^[A-Z][A-Z0-9_]*$"))
(#lua-match? @constant "^[A-Z][A-Z0-9_]*$"))
(_
(navigation_suffix
(simple_identifier) @constant
(#lua-match? @constant "^[A-Z][A-Z0-9_]*$")))
(navigation_suffix
(simple_identifier) @constant
(#lua-match? @constant "^[A-Z][A-Z0-9_]*$")))
(enum_entry
(simple_identifier) @constant)
(simple_identifier) @constant)
(type_identifier) @type
@ -55,170 +55,95 @@
(nullable_type) @punctuation.special
(type_alias
(type_identifier) @type.definition)
(type_identifier) @type.definition)
((type_identifier) @type.builtin
(#any-of? @type.builtin
"Byte"
"Short"
"Int"
"Long"
"UByte"
"UShort"
"UInt"
"ULong"
"Float"
"Double"
"Boolean"
"Char"
"String"
"Array"
"ByteArray"
"ShortArray"
"IntArray"
"LongArray"
"UByteArray"
"UShortArray"
"UIntArray"
"ULongArray"
"FloatArray"
"DoubleArray"
"BooleanArray"
"CharArray"
"Map"
"Set"
"List"
"EmptyMap"
"EmptySet"
"EmptyList"
"MutableMap"
"MutableSet"
"MutableList"
))
(#any-of? @type.builtin "Byte" "Short" "Int" "Long" "UByte" "UShort" "UInt" "ULong" "Float" "Double" "Boolean" "Char" "String" "Array" "ByteArray" "ShortArray" "IntArray" "LongArray" "UByteArray" "UShortArray" "UIntArray" "ULongArray" "FloatArray" "DoubleArray" "BooleanArray" "CharArray" "Map" "Set" "List" "EmptyMap" "EmptySet" "EmptyList" "MutableMap" "MutableSet" "MutableList"))
(package_header "package" @keyword
. (identifier (simple_identifier) @module))
(package_header
"package" @keyword
.
(identifier
(simple_identifier) @module))
(import_header
"import" @keyword.import)
"import" @keyword.import)
; The last `simple_identifier` in a `import_header` will always either be a function
; or a type. Classes can appear anywhere in the import path, unlike functions
(import_header
(identifier
(simple_identifier) @type @_import)
(import_alias
(type_identifier) @type.definition)?
(#lua-match? @_import "^[A-Z]"))
(identifier
(simple_identifier) @type @_import)
(import_alias
(type_identifier) @type.definition)?
(#lua-match? @_import "^[A-Z]"))
(import_header
(identifier
(simple_identifier) @function @_import .)
(import_alias
(type_identifier) @function)?
(#lua-match? @_import "^[a-z]"))
(identifier
(simple_identifier) @function @_import .)
(import_alias
(type_identifier) @function)?
(#lua-match? @_import "^[a-z]"))
(label) @label
;;; Function definitions
; Function definitions
(function_declaration
(simple_identifier) @function)
(simple_identifier) @function)
(getter
("get") @function.builtin)
("get") @function.builtin)
(setter
("set") @function.builtin)
("set") @function.builtin)
(primary_constructor) @constructor
(secondary_constructor
("constructor") @constructor)
("constructor") @constructor)
(constructor_invocation
(user_type
(type_identifier) @constructor))
(user_type
(type_identifier) @constructor))
(anonymous_initializer
("init") @constructor)
("init") @constructor)
(parameter
(simple_identifier) @variable.parameter)
(simple_identifier) @variable.parameter)
(parameter_with_optional_type
(simple_identifier) @variable.parameter)
(simple_identifier) @variable.parameter)
; lambda parameters
(lambda_literal
(lambda_parameters
(variable_declaration
(simple_identifier) @variable.parameter)))
;;; Function calls
(lambda_parameters
(variable_declaration
(simple_identifier) @variable.parameter)))
; Function calls
; function()
(call_expression
. (simple_identifier) @function.call)
.
(simple_identifier) @function.call)
; ::function
(callable_reference
. (simple_identifier) @function.call)
.
(simple_identifier) @function.call)
; object.function() or object.property.function()
(call_expression
(navigation_expression
(navigation_suffix
(simple_identifier) @function.call) . ))
(navigation_expression
(navigation_suffix
(simple_identifier) @function.call) .))
(call_expression
. (simple_identifier) @function.builtin
(#any-of? @function.builtin
"arrayOf"
"arrayOfNulls"
"byteArrayOf"
"shortArrayOf"
"intArrayOf"
"longArrayOf"
"ubyteArrayOf"
"ushortArrayOf"
"uintArrayOf"
"ulongArrayOf"
"floatArrayOf"
"doubleArrayOf"
"booleanArrayOf"
"charArrayOf"
"emptyArray"
"mapOf"
"setOf"
"listOf"
"emptyMap"
"emptySet"
"emptyList"
"mutableMapOf"
"mutableSetOf"
"mutableListOf"
"print"
"println"
"error"
"TODO"
"run"
"runCatching"
"repeat"
"lazy"
"lazyOf"
"enumValues"
"enumValueOf"
"assert"
"check"
"checkNotNull"
"require"
"requireNotNull"
"with"
"suspend"
"synchronized"
))
;;; Literals
.
(simple_identifier) @function.builtin
(#any-of? @function.builtin "arrayOf" "arrayOfNulls" "byteArrayOf" "shortArrayOf" "intArrayOf" "longArrayOf" "ubyteArrayOf" "ushortArrayOf" "uintArrayOf" "ulongArrayOf" "floatArrayOf" "doubleArrayOf" "booleanArrayOf" "charArrayOf" "emptyArray" "mapOf" "setOf" "listOf" "emptyMap" "emptySet" "emptyList" "mutableMapOf" "mutableSetOf" "mutableListOf" "print" "println" "error" "TODO" "run" "runCatching" "repeat" "lazy" "lazyOf" "enumValues" "enumValueOf" "assert" "check" "checkNotNull" "require" "requireNotNull" "with" "suspend" "synchronized"))
; Literals
[
(line_comment)
(multiline_comment)
@ -230,17 +155,19 @@
(shebang_line) @keyword.directive
(real_literal) @number.float
[
(integer_literal)
(long_literal)
(hex_literal)
(bin_literal)
(unsigned_literal)
(integer_literal)
(long_literal)
(hex_literal)
(bin_literal)
(unsigned_literal)
] @number
[
"null" ; should be highlighted the same as booleans
(boolean_literal)
"null"
; should be highlighted the same as booleans
(boolean_literal)
] @boolean
(character_literal) @character
@ -248,71 +175,73 @@
(string_literal) @string
; NOTE: Escapes not allowed in multi-line strings
(character_literal (character_escape_seq) @string.escape)
(character_literal
(character_escape_seq) @string.escape)
; There are 3 ways to define a regex
; - "[abc]?".toRegex()
(call_expression
(navigation_expression
((string_literal) @string.regexp)
(navigation_suffix
((simple_identifier) @_function
(#eq? @_function "toRegex")))))
(navigation_expression
((string_literal) @string.regexp)
(navigation_suffix
((simple_identifier) @_function
(#eq? @_function "toRegex")))))
; - Regex("[abc]?")
(call_expression
((simple_identifier) @_function
(#eq? @_function "Regex"))
(call_suffix
(value_arguments
(value_argument
(string_literal) @string.regexp))))
((simple_identifier) @_function
(#eq? @_function "Regex"))
(call_suffix
(value_arguments
(value_argument
(string_literal) @string.regexp))))
; - Regex.fromLiteral("[abc]?")
(call_expression
(navigation_expression
((simple_identifier) @_class
(#eq? @_class "Regex"))
(navigation_suffix
((simple_identifier) @_function
(#eq? @_function "fromLiteral"))))
(call_suffix
(value_arguments
(value_argument
(string_literal) @string.regexp))))
(navigation_expression
((simple_identifier) @_class
(#eq? @_class "Regex"))
(navigation_suffix
((simple_identifier) @_function
(#eq? @_function "fromLiteral"))))
(call_suffix
(value_arguments
(value_argument
(string_literal) @string.regexp))))
;;; Keywords
; Keywords
(type_alias
"typealias" @keyword)
(type_alias "typealias" @keyword)
(companion_object "companion" @keyword)
(companion_object
"companion" @keyword)
[
(class_modifier)
(member_modifier)
(function_modifier)
(property_modifier)
(platform_modifier)
(variance_modifier)
(parameter_modifier)
(visibility_modifier)
(reification_modifier)
(inheritance_modifier)
(class_modifier)
(member_modifier)
(function_modifier)
(property_modifier)
(platform_modifier)
(variance_modifier)
(parameter_modifier)
(visibility_modifier)
(reification_modifier)
(inheritance_modifier)
] @type.qualifier
[
"val"
"var"
"enum"
"class"
"object"
"interface"
; "typeof" ; NOTE: It is reserved for future use
"val"
"var"
"enum"
"class"
"object"
"interface"
; "typeof" ; NOTE: It is reserved for future use
] @keyword
[
"return"
"return@"
"return"
"return@"
] @keyword.return
"suspend" @keyword.coroutine
@ -320,112 +249,135 @@
"fun" @keyword.function
[
"if"
"else"
"when"
"if"
"else"
"when"
] @keyword.conditional
[
"for"
"do"
"while"
"continue"
"continue@"
"break"
"break@"
"for"
"do"
"while"
"continue"
"continue@"
"break"
"break@"
] @keyword.repeat
[
"try"
"catch"
"throw"
"finally"
"try"
"catch"
"throw"
"finally"
] @keyword.exception
(annotation
"@" @attribute
(use_site_target)? @attribute)
(annotation
"@" @attribute (use_site_target)? @attribute)
(user_type
(type_identifier) @attribute))
(annotation
(user_type
(type_identifier) @attribute))
(annotation
(constructor_invocation
(user_type
(type_identifier) @attribute)))
(constructor_invocation
(user_type
(type_identifier) @attribute)))
(file_annotation
"@" @attribute "file" @attribute ":" @attribute)
(file_annotation
(user_type
(type_identifier) @attribute))
(file_annotation
(constructor_invocation
(user_type
(type_identifier) @attribute)))
"@" @attribute
"file" @attribute
":" @attribute)
;;; Operators & Punctuation
(file_annotation
(user_type
(type_identifier) @attribute))
(file_annotation
(constructor_invocation
(user_type
(type_identifier) @attribute)))
; Operators & Punctuation
[
"!"
"!="
"!=="
"="
"=="
"==="
">"
">="
"<"
"<="
"||"
"&&"
"+"
"++"
"+="
"-"
"--"
"-="
"*"
"*="
"/"
"/="
"%"
"%="
"?."
"?:"
"!!"
"is"
"!is"
"in"
"!in"
"as"
"as?"
".."
"->"
"!"
"!="
"!=="
"="
"=="
"==="
">"
">="
"<"
"<="
"||"
"&&"
"+"
"++"
"+="
"-"
"--"
"-="
"*"
"*="
"/"
"/="
"%"
"%="
"?."
"?:"
"!!"
"is"
"!is"
"in"
"!in"
"as"
"as?"
".."
"->"
] @operator
[
"(" ")"
"[" "]"
"{" "}"
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
[
"."
","
";"
":"
"::"
"."
","
";"
":"
"::"
] @punctuation.delimiter
(super_expression [ "<" ">" ] @punctuation.delimiter)
(type_arguments [ "<" ">" ] @punctuation.delimiter)
(type_parameters [ "<" ">" ] @punctuation.delimiter)
(super_expression
[
"<"
">"
] @punctuation.delimiter)
(type_arguments
[
"<"
">"
] @punctuation.delimiter)
(type_parameters
[
"<"
">"
] @punctuation.delimiter)
; NOTE: `interpolated_identifier`s can be highlighted in any way
(string_literal
"$" @punctuation.special
(interpolated_identifier) @none @variable)
"$" @punctuation.special
(interpolated_identifier) @none @variable)
(string_literal
"${" @punctuation.special
(interpolated_expression) @none
"}" @punctuation.special)
"${" @punctuation.special
(interpolated_expression) @none
"}" @punctuation.special)

View file

@ -1,17 +1,17 @@
([
(line_comment)
(multiline_comment)
] @injection.content
(#set! injection.language "comment"))
] @injection.content
(#set! injection.language "comment"))
; There are 3 ways to define a regex
; - "[abc]?".toRegex()
(call_expression
(navigation_expression
((string_literal) @injection.content (#set! injection.language "regex"))
(navigation_suffix
((simple_identifier) @_function
(#eq? @_function "toRegex")))))
((string_literal) @injection.content
(#set! injection.language "regex"))
(navigation_suffix
((simple_identifier) @_function
(#eq? @_function "toRegex")))))
; - Regex("[abc]?")
(call_expression
@ -20,25 +20,28 @@
(call_suffix
(value_arguments
(value_argument
(string_literal) @injection.content (#set! injection.language "regex")))))
(string_literal) @injection.content
(#set! injection.language "regex")))))
; - Regex.fromLiteral("[abc]?")
(call_expression
(navigation_expression
((simple_identifier) @_class
(#eq? @_class "Regex"))
(#eq? @_class "Regex"))
(navigation_suffix
((simple_identifier) @_function
(#eq? @_function "fromLiteral"))))
(#eq? @_function "fromLiteral"))))
(call_suffix
(value_arguments
(value_argument
(string_literal) @injection.content (#set! injection.language "regex")))))
(string_literal) @injection.content
(#set! injection.language "regex")))))
; "pi = %.2f".format(3.14159)
((call_expression
(navigation_expression
(string_literal) @injection.content
(navigation_suffix (simple_identifier) @_method)))
(#eq? @_method "format")
(#set! injection.language "printf"))
(navigation_suffix
(simple_identifier) @_method)))
(#eq? @_method "format")
(#set! injection.language "printf"))

View file

@ -1,84 +1,78 @@
;;; Imports
; Imports
(package_header
. (identifier) @local.definition.namespace)
.
(identifier) @local.definition.namespace)
(import_header
(identifier
(simple_identifier) @local.definition.import .)
(import_alias
(type_identifier) @local.definition.import)?)
;;; Functions
(identifier
(simple_identifier) @local.definition.import .)
(import_alias
(type_identifier) @local.definition.import)?)
; Functions
(function_declaration
. (simple_identifier) @local.definition.function
(#set! "definition.function.scope" "parent"))
.
(simple_identifier) @local.definition.function
(#set! "definition.function.scope" "parent"))
(class_body
(function_declaration
. (simple_identifier) @local.definition.method)
(#set! "definition.method.scope" "parent"))
;;; Variables
(function_declaration
.
(simple_identifier) @local.definition.method)
(#set! "definition.method.scope" "parent"))
; Variables
(function_declaration
(function_value_parameters
(parameter
(simple_identifier) @local.definition.parameter)))
(function_value_parameters
(parameter
(simple_identifier) @local.definition.parameter)))
(lambda_literal
(lambda_parameters
(variable_declaration
(simple_identifier) @local.definition.parameter)))
(lambda_parameters
(variable_declaration
(simple_identifier) @local.definition.parameter)))
(class_body
(property_declaration
(variable_declaration
(simple_identifier) @local.definition.field)))
(property_declaration
(variable_declaration
(simple_identifier) @local.definition.field)))
(class_declaration
(primary_constructor
(class_parameter
(simple_identifier) @local.definition.field)))
(primary_constructor
(class_parameter
(simple_identifier) @local.definition.field)))
(enum_class_body
(enum_entry
(simple_identifier) @local.definition.field))
(enum_entry
(simple_identifier) @local.definition.field))
(variable_declaration
(simple_identifier) @local.definition.var)
;;; Types
(simple_identifier) @local.definition.var)
; Types
(class_declaration
(type_identifier) @local.definition.type
(#set! "definition.type.scope" "parent"))
(type_identifier) @local.definition.type
(#set! "definition.type.scope" "parent"))
(type_alias
(type_identifier) @local.definition.type
(#set! "definition.type.scope" "parent"))
;;; Scopes
(type_identifier) @local.definition.type
(#set! "definition.type.scope" "parent"))
; Scopes
[
(if_expression)
(when_expression)
(when_entry)
(for_statement)
(while_statement)
(do_while_statement)
(lambda_literal)
(function_declaration)
(primary_constructor)
(secondary_constructor)
(anonymous_initializer)
(class_declaration)
(enum_class_body)
(enum_entry)
(interpolated_expression)
(if_expression)
(when_expression)
(when_entry)
(for_statement)
(while_statement)
(do_while_statement)
(lambda_literal)
(function_declaration)
(primary_constructor)
(secondary_constructor)
(anonymous_initializer)
(class_declaration)
(enum_class_body)
(enum_entry)
(interpolated_expression)
] @local.scope