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,28 +1,23 @@
[
(function_definition)
(class_definition)
(while_statement)
(for_statement)
(if_statement)
(with_statement)
(try_statement)
(match_statement)
(import_from_statement)
(parameters)
(argument_list)
(parenthesized_expression)
(generator_expression)
(list_comprehension)
(set_comprehension)
(dictionary_comprehension)
(tuple)
(list)
(set)
(dictionary)
(string)
] @fold

View file

@ -1,20 +1,20 @@
;; From tree-sitter-python licensed under MIT License
; From tree-sitter-python licensed under MIT License
; Copyright (c) 2016 Max Brunsfeld
; Variables
(identifier) @variable
; Reset highlighting in f-string interpolations
(interpolation) @none
;; Identifier naming conventions
; Identifier naming conventions
((identifier) @type
(#lua-match? @type "^[A-Z].*[a-z]"))
(#lua-match? @type "^[A-Z].*[a-z]"))
((identifier) @constant
(#lua-match? @constant "^[A-Z][A-Z_0-9]*$"))
(#lua-match? @constant "^[A-Z][A-Z_0-9]*$"))
((identifier) @constant.builtin
(#lua-match? @constant.builtin "^__[a-zA-Z0-9_]*__$"))
(#lua-match? @constant.builtin "^__[a-zA-Z0-9_]*__$"))
((identifier) @constant.builtin
; format-ignore
@ -26,160 +26,188 @@
"_" @constant.builtin ; match wildcard
((attribute
attribute: (identifier) @variable.member)
(#lua-match? @variable.member "^[%l_].*$"))
attribute: (identifier) @variable.member)
(#lua-match? @variable.member "^[%l_].*$"))
((assignment
left: (identifier) @type.definition
(type (identifier) @_annotation))
(#eq? @_annotation "TypeAlias"))
(type
(identifier) @_annotation))
(#eq? @_annotation "TypeAlias"))
((assignment
left: (identifier) @type.definition
right: (call
function: (identifier) @_func))
(#any-of? @_func "TypeVar" "NewType"))
right:
(call
function: (identifier) @_func))
(#any-of? @_func "TypeVar" "NewType"))
; Function calls
(call
function: (identifier) @function.call)
(call
function: (attribute
attribute: (identifier) @function.method.call))
function:
(attribute
attribute: (identifier) @function.method.call))
((call
function: (identifier) @constructor)
(#lua-match? @constructor "^%u"))
function: (identifier) @constructor)
(#lua-match? @constructor "^%u"))
((call
function: (attribute
attribute: (identifier) @constructor))
(#lua-match? @constructor "^%u"))
function:
(attribute
attribute: (identifier) @constructor))
(#lua-match? @constructor "^%u"))
;; Decorators
((decorator "@" @attribute)
(#set! "priority" 101))
; Decorators
((decorator
"@" @attribute)
(#set! "priority" 101))
(decorator
(identifier) @attribute)
(decorator
(attribute
attribute: (identifier) @attribute))
(decorator
(call (identifier) @attribute))
(call
(identifier) @attribute))
(decorator
(call (attribute
attribute: (identifier) @attribute)))
(call
(attribute
attribute: (identifier) @attribute)))
((decorator
(identifier) @attribute.builtin)
(#any-of? @attribute.builtin "classmethod" "property"))
;; Builtin functions
(#any-of? @attribute.builtin "classmethod" "property"))
; Builtin functions
((call
function: (identifier) @function.builtin)
(#any-of? @function.builtin
"abs" "all" "any" "ascii" "bin" "bool" "breakpoint" "bytearray" "bytes" "callable" "chr" "classmethod"
"compile" "complex" "delattr" "dict" "dir" "divmod" "enumerate" "eval" "exec" "filter" "float" "format"
"frozenset" "getattr" "globals" "hasattr" "hash" "help" "hex" "id" "input" "int" "isinstance" "issubclass"
"iter" "len" "list" "locals" "map" "max" "memoryview" "min" "next" "object" "oct" "open" "ord" "pow"
"print" "property" "range" "repr" "reversed" "round" "set" "setattr" "slice" "sorted" "staticmethod" "str"
"sum" "super" "tuple" "type" "vars" "zip" "__import__"))
;; Function definitions
(#any-of? @function.builtin "abs" "all" "any" "ascii" "bin" "bool" "breakpoint" "bytearray" "bytes" "callable" "chr" "classmethod" "compile" "complex" "delattr" "dict" "dir" "divmod" "enumerate" "eval" "exec" "filter" "float" "format" "frozenset" "getattr" "globals" "hasattr" "hash" "help" "hex" "id" "input" "int" "isinstance" "issubclass" "iter" "len" "list" "locals" "map" "max" "memoryview" "min" "next" "object" "oct" "open" "ord" "pow" "print" "property" "range" "repr" "reversed" "round" "set" "setattr" "slice" "sorted" "staticmethod" "str" "sum" "super" "tuple" "type" "vars" "zip" "__import__"))
; Function definitions
(function_definition
name: (identifier) @function)
(type (identifier) @type)
(type
(identifier) @type)
(type
(subscript
(identifier) @type)) ; type subscript: Tuple[int]
((call
function: (identifier) @_isinstance
arguments: (argument_list
(_)
(identifier) @type))
(#eq? @_isinstance "isinstance"))
arguments:
(argument_list
(_)
(identifier) @type))
(#eq? @_isinstance "isinstance"))
;; Normal parameters
; Normal parameters
(parameters
(identifier) @variable.parameter)
;; Lambda parameters
; Lambda parameters
(lambda_parameters
(identifier) @variable.parameter)
(lambda_parameters
(tuple_pattern
(identifier) @variable.parameter))
; Default parameters
(keyword_argument
name: (identifier) @variable.parameter)
; Naming parameters on call-site
(default_parameter
name: (identifier) @variable.parameter)
(typed_parameter
(identifier) @variable.parameter)
(typed_default_parameter
name: (identifier) @variable.parameter)
; Variadic parameters *args, **kwargs
(parameters
(list_splat_pattern ; *args
(list_splat_pattern
; *args
(identifier) @variable.parameter))
(parameters
(dictionary_splat_pattern ; **kwargs
(dictionary_splat_pattern
; **kwargs
(identifier) @variable.parameter))
(lambda_parameters
(list_splat_pattern
(identifier) @variable.parameter))
(lambda_parameters
(dictionary_splat_pattern
(identifier) @variable.parameter))
;; Literals
; Literals
(none) @constant.builtin
[(true) (false)] @boolean
[
(true)
(false)
] @boolean
((identifier) @variable.builtin
(#eq? @variable.builtin "self"))
(#eq? @variable.builtin "self"))
((identifier) @variable.builtin
(#eq? @variable.builtin "cls"))
(#eq? @variable.builtin "cls"))
(integer) @number
(float) @number.float
(comment) @comment @spell
((module . (comment) @keyword.directive)
((module
.
(comment) @keyword.directive)
(#lua-match? @keyword.directive "^#!/"))
(string) @string
[
(escape_sequence)
(escape_interpolation)
] @string.escape
; doc-strings
(module . (expression_statement (string) @string.documentation @spell))
(module
.
(expression_statement
(string) @string.documentation @spell))
(class_definition
body:
(block
. (expression_statement (string) @string.documentation @spell)))
.
(expression_statement
(string) @string.documentation @spell)))
(function_definition
body:
(block
. (expression_statement (string) @string.documentation @spell)))
.
(expression_statement
(string) @string.documentation @spell)))
; Tokens
[
"-"
"-="
@ -229,7 +257,6 @@
"or"
"is not"
"not in"
"del"
] @keyword.operator
@ -260,19 +287,36 @@
"return"
"yield"
] @keyword.return
(yield "from" @keyword.return)
(yield
"from" @keyword.return)
(future_import_statement
"from" @keyword.import
"__future__" @constant.builtin)
(import_from_statement "from" @keyword.import)
(import_from_statement
"from" @keyword.import)
"import" @keyword.import
(aliased_import "as" @keyword.import)
(aliased_import
"as" @keyword.import)
["if" "elif" "else" "match" "case"] @keyword.conditional
[
"if"
"elif"
"else"
"match"
"case"
] @keyword.conditional
["for" "while" "break" "continue"] @keyword.repeat
[
"for"
"while"
"break"
"continue"
] @keyword.repeat
[
"try"
@ -282,13 +326,21 @@
"finally"
] @keyword.exception
(raise_statement "from" @keyword.exception)
(raise_statement
"from" @keyword.exception)
(try_statement
(else_clause
"else" @keyword.exception))
["(" ")" "[" "]" "{" "}"] @punctuation.bracket
[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
(interpolation
"{" @punctuation.special
@ -296,40 +348,52 @@
(type_conversion) @function.macro
["," "." ":" ";" (ellipsis)] @punctuation.delimiter
[
","
"."
":"
";"
(ellipsis)
] @punctuation.delimiter
;; Class definitions
(class_definition name: (identifier) @type)
; Class definitions
(class_definition
name: (identifier) @type)
(class_definition
body: (block
(function_definition
name: (identifier) @function.method)))
body:
(block
(function_definition
name: (identifier) @function.method)))
(class_definition
superclasses: (argument_list
(identifier) @type))
superclasses:
(argument_list
(identifier) @type))
((class_definition
body: (block
(expression_statement
(assignment
left: (identifier) @variable.member))))
(#lua-match? @variable.member "^%l.*$"))
body:
(block
(expression_statement
(assignment
left: (identifier) @variable.member))))
(#lua-match? @variable.member "^%l.*$"))
((class_definition
body: (block
(expression_statement
(assignment
left: (_
(identifier) @variable.member)))))
(#lua-match? @variable.member "^%l.*$"))
body:
(block
(expression_statement
(assignment
left:
(_
(identifier) @variable.member)))))
(#lua-match? @variable.member "^%l.*$"))
((class_definition
(block
(function_definition
name: (identifier) @constructor)))
(#any-of? @constructor "__new__" "__init__"))
(#any-of? @constructor "__new__" "__init__"))
((identifier) @type.builtin
; format-ignore
@ -350,10 +414,14 @@
"bool" "int" "float" "complex" "list" "tuple" "range" "str"
"bytes" "bytearray" "memoryview" "set" "frozenset" "dict" "type" "object"))
;; Regex from the `re` module
; Regex from the `re` module
(call
function: (attribute
object: (identifier) @_re)
arguments: (argument_list . (string (string_content) @string.regexp))
function:
(attribute
object: (identifier) @_re)
arguments:
(argument_list
.
(string
(string_content) @string.regexp))
(#eq? @_re "re"))

View file

@ -1,82 +1,106 @@
[
(import_from_statement)
(parenthesized_expression)
(generator_expression)
(list_comprehension)
(set_comprehension)
(dictionary_comprehension)
(tuple_pattern)
(list_pattern)
(binary_operator)
(lambda)
(concatenated_string)
] @indent.begin
((list) @indent.align
(#set! indent.open_delimiter "[")
(#set! indent.close_delimiter "]")
)
(#set! indent.open_delimiter "[")
(#set! indent.close_delimiter "]"))
((dictionary) @indent.align
(#set! indent.open_delimiter "{")
(#set! indent.close_delimiter "}")
)
(#set! indent.open_delimiter "{")
(#set! indent.close_delimiter "}"))
((set) @indent.align
(#set! indent.open_delimiter "{")
(#set! indent.close_delimiter "}")
)
(#set! indent.open_delimiter "{")
(#set! indent.close_delimiter "}"))
((for_statement) @indent.begin
(#set! indent.immediate 1))
(#set! indent.immediate 1))
((if_statement) @indent.begin
(#set! indent.immediate 1))
(#set! indent.immediate 1))
((while_statement) @indent.begin
(#set! indent.immediate 1))
(#set! indent.immediate 1))
((try_statement) @indent.begin
(#set! indent.immediate 1))
(ERROR "try" ":" @indent.begin (#set! indent.immediate 1))
(#set! indent.immediate 1))
(ERROR
"try"
":" @indent.begin
(#set! indent.immediate 1))
((function_definition) @indent.begin
(#set! indent.immediate 1))
(#set! indent.immediate 1))
((class_definition) @indent.begin
(#set! indent.immediate 1))
(#set! indent.immediate 1))
((with_statement) @indent.begin
(#set! indent.immediate 1))
(#set! indent.immediate 1))
((match_statement) @indent.begin
(#set! indent.immediate 1))
(#set! indent.immediate 1))
((case_clause) @indent.begin
(#set! indent.immediate 1))
(#set! indent.immediate 1))
(if_statement
condition: (parenthesized_expression) @indent.align
(#set! indent.open_delimiter "(")
(#set! indent.close_delimiter ")")
(#set! indent.avoid_last_matching_next 1)
)
(#set! indent.avoid_last_matching_next 1))
(while_statement
condition: (parenthesized_expression) @indent.align
(#set! indent.open_delimiter "(")
(#set! indent.close_delimiter ")")
(#set! indent.avoid_last_matching_next 1)
)
(#set! indent.avoid_last_matching_next 1))
(ERROR
"(" @indent.align
(#set! indent.open_delimiter "(")
(#set! indent.close_delimiter ")")
.
(_))
(ERROR "(" @indent.align (#set! indent.open_delimiter "(") (#set! indent.close_delimiter ")") . (_))
((argument_list) @indent.align
(#set! indent.open_delimiter "(")
(#set! indent.close_delimiter ")"))
(#set! indent.open_delimiter "(")
(#set! indent.close_delimiter ")"))
((parameters) @indent.align
(#set! indent.open_delimiter "(")
(#set! indent.close_delimiter ")")
(#set! indent.avoid_last_matching_next 1))
(#set! indent.open_delimiter "(")
(#set! indent.close_delimiter ")")
(#set! indent.avoid_last_matching_next 1))
((tuple) @indent.align
(#set! indent.open_delimiter "(")
(#set! indent.close_delimiter ")"))
(#set! indent.open_delimiter "(")
(#set! indent.close_delimiter ")"))
(ERROR "[" @indent.align (#set! indent.open_delimiter "[") (#set! indent.close_delimiter "]") . (_))
(ERROR
"[" @indent.align
(#set! indent.open_delimiter "[")
(#set! indent.close_delimiter "]")
.
(_))
(ERROR "{" @indent.align (#set! indent.open_delimiter "{") (#set! indent.close_delimiter "}") . (_))
(ERROR
"{" @indent.align
(#set! indent.open_delimiter "{")
(#set! indent.close_delimiter "}")
.
(_))
[
(break_statement)
@ -84,22 +108,37 @@
] @indent.dedent
(ERROR
(_) @indent.branch ":" .
(_) @indent.branch
":"
.
(#lua-match? @indent.branch "^else"))
(ERROR
(_) @indent.branch @indent.dedent ":" .
(_) @indent.branch @indent.dedent
":"
.
(#lua-match? @indent.branch "^elif"))
(parenthesized_expression ")" @indent.end)
(generator_expression ")" @indent.end)
(list_comprehension "]" @indent.end)
(set_comprehension "}" @indent.end)
(dictionary_comprehension "}" @indent.end)
(parenthesized_expression
")" @indent.end)
(tuple_pattern ")" @indent.end)
(list_pattern "]" @indent.end)
(generator_expression
")" @indent.end)
(list_comprehension
"]" @indent.end)
(set_comprehension
"}" @indent.end)
(dictionary_comprehension
"}" @indent.end)
(tuple_pattern
")" @indent.end)
(list_pattern
"]" @indent.end)
(return_statement
[
@ -111,10 +150,12 @@
"}"
"]"
] @indent.end .)
(attribute
(attribute
attribute: (_) @indent.end)
(call
arguments: (_ ")" @indent.end))
arguments:
(_
")" @indent.end))
"return" @indent.end
] .)
@ -129,4 +170,3 @@
] @indent.branch
(string) @indent.auto

View file

@ -1,15 +1,21 @@
(call
function: (attribute
object: (identifier) @_re)
arguments: (argument_list . (string
(string_content) @injection.content))
function:
(attribute
object: (identifier) @_re)
arguments:
(argument_list
.
(string
(string_content) @injection.content))
(#eq? @_re "re")
(#set! injection.language "regex"))
((binary_operator
left: (string (string_content) @injection.content)
left:
(string
(string_content) @injection.content)
operator: "%")
(#set! injection.language "printf"))
(#set! injection.language "printf"))
((comment) @injection.content
(#set! injection.language "comment"))
(#set! injection.language "comment"))

View file

@ -1,25 +1,35 @@
;;; Program structure
; Program structure
(module) @local.scope
(class_definition
body: (block
(expression_statement
(assignment
left: (identifier) @local.definition.field)))) @local.scope
body:
(block
(expression_statement
(assignment
left: (identifier) @local.definition.field)))) @local.scope
(class_definition
body: (block
(expression_statement
(assignment
left: (_
(identifier) @local.definition.field))))) @local.scope
body:
(block
(expression_statement
(assignment
left:
(_
(identifier) @local.definition.field))))) @local.scope
; Imports
(aliased_import
alias: (identifier) @local.definition.import)
(import_statement
name: (dotted_name ((identifier) @local.definition.import)))
name:
(dotted_name
((identifier) @local.definition.import)))
(import_from_statement
name: (dotted_name ((identifier) @local.definition.import)))
name:
(dotted_name
((identifier) @local.definition.import)))
; Function with parameters, defines parameters
(parameters
@ -47,69 +57,81 @@
; Function defines function and scope
((function_definition
name: (identifier) @local.definition.function) @local.scope
(#set! definition.function.scope "parent"))
(#set! definition.function.scope "parent"))
((class_definition
name: (identifier) @local.definition.type) @local.scope
(#set! definition.type.scope "parent"))
(#set! definition.type.scope "parent"))
(class_definition
body: (block
(function_definition
name: (identifier) @local.definition.method)))
body:
(block
(function_definition
name: (identifier) @local.definition.method)))
;;; Loops
; Loops
; not a scope!
(for_statement
left: (pattern_list
(identifier) @local.definition.var))
left:
(pattern_list
(identifier) @local.definition.var))
(for_statement
left: (tuple_pattern
(identifier) @local.definition.var))
left:
(tuple_pattern
(identifier) @local.definition.var))
(for_statement
left: (identifier) @local.definition.var)
; not a scope!
;(while_statement) @local.scope
; for in list comprehension
(for_in_clause
left: (identifier) @local.definition.var)
(for_in_clause
left: (tuple_pattern
(identifier) @local.definition.var))
left:
(tuple_pattern
(identifier) @local.definition.var))
(for_in_clause
left: (pattern_list
(identifier) @local.definition.var))
left:
(pattern_list
(identifier) @local.definition.var))
(dictionary_comprehension) @local.scope
(list_comprehension) @local.scope
(set_comprehension) @local.scope
;;; Assignments
; Assignments
(assignment
left: (identifier) @local.definition.var)
(assignment
left: (identifier) @local.definition.var)
left:
(pattern_list
(identifier) @local.definition.var))
(assignment
left: (pattern_list
(identifier) @local.definition.var))
(assignment
left: (tuple_pattern
(identifier) @local.definition.var))
left:
(tuple_pattern
(identifier) @local.definition.var))
(assignment
left: (attribute
(identifier)
(identifier) @local.definition.field))
left:
(attribute
(identifier)
(identifier) @local.definition.field))
; Walrus operator x := 1
(named_expression
(identifier) @local.definition.var)
(as_pattern
(as_pattern
alias: (as_pattern_target) @local.definition.var)
;;; REFERENCES
; REFERENCES
(identifier) @local.reference