Format Tree-sitter queries with ts_query_ls (#50138)

Release Notes:

- N/A
This commit is contained in:
Finn Evers authored and GitHub committed 2026-02-27 12:49:45 +00:00
1 parent c5f83f570c
commit 5ed538f49c
143 files changed
+4770 -3774

No files matched your search

+12 -4
View File
@@ -1,4 +1,12 @@
("(" @open ")" @close)
("[" @open "]" @close)
("{" @open "}" @close)
(((string_start) @open (string_end) @close) (#set! rainbow.exclude))
("(" @open
")" @close)
("[" @open
"]" @close)
("{" @open
"}" @close)
(((string_start) @open
(string_end) @close)
(#set! rainbow.exclude))
+78 -24
View File
@@ -1,43 +1,97 @@
(identifier) @debug-variable
(#eq? @debug-variable "self")
(assignment left: (identifier) @debug-variable)
(assignment left: (pattern_list (identifier) @debug-variable))
(assignment left: (tuple_pattern (identifier) @debug-variable))
(assignment
left: (identifier) @debug-variable)
(augmented_assignment left: (identifier) @debug-variable)
(assignment
left: (pattern_list
(identifier) @debug-variable))
(for_statement left: (identifier) @debug-variable)
(for_statement left: (pattern_list (identifier) @debug-variable))
(for_statement left: (tuple_pattern (identifier) @debug-variable))
(assignment
left: (tuple_pattern
(identifier) @debug-variable))
(for_in_clause left: (identifier) @debug-variable)
(for_in_clause left: (pattern_list (identifier) @debug-variable))
(for_in_clause left: (tuple_pattern (identifier) @debug-variable))
(augmented_assignment
left: (identifier) @debug-variable)
(as_pattern (identifier) @debug-variable)
(for_statement
left: (identifier) @debug-variable)
(binary_operator left: (identifier) @debug-variable (#not-match? @debug-variable "^[A-Z]"))
(binary_operator right: (identifier) @debug-variable (#not-match? @debug-variable "^[A-Z]"))
(comparison_operator (identifier) @debug-variable (#not-match? @debug-variable "^[A-Z]"))
(for_statement
left: (pattern_list
(identifier) @debug-variable))
(list (identifier) @debug-variable (#not-match? @debug-variable "^[A-Z]"))
(tuple (identifier) @debug-variable (#not-match? @debug-variable "^[A-Z]"))
(set (identifier) @debug-variable (#not-match? @debug-variable "^[A-Z]"))
(for_statement
left: (tuple_pattern
(identifier) @debug-variable))
(subscript value: (identifier) @debug-variable (#not-match? @debug-variable "^[A-Z]"))
(for_in_clause
left: (identifier) @debug-variable)
(attribute object: (identifier) @debug-variable (#not-match? @debug-variable "^[A-Z]"))
(for_in_clause
left: (pattern_list
(identifier) @debug-variable))
(return_statement (identifier) @debug-variable (#not-match? @debug-variable "^[A-Z]"))
(for_in_clause
left: (tuple_pattern
(identifier) @debug-variable))
(parenthesized_expression (identifier) @debug-variable (#not-match? @debug-variable "^[A-Z]"))
(as_pattern
(identifier) @debug-variable)
(argument_list (identifier) @debug-variable (#not-match? @debug-variable "^[A-Z]"))
(binary_operator
left: (identifier) @debug-variable
(#not-match? @debug-variable "^[A-Z]"))
(if_statement condition: (identifier) @debug-variable (#not-match? @debug-variable "^[A-Z]"))
(binary_operator
right: (identifier) @debug-variable
(#not-match? @debug-variable "^[A-Z]"))
(while_statement condition: (identifier) @debug-variable (#not-match? @debug-variable "^[A-Z]"))
(comparison_operator
(identifier) @debug-variable
(#not-match? @debug-variable "^[A-Z]"))
(list
(identifier) @debug-variable
(#not-match? @debug-variable "^[A-Z]"))
(tuple
(identifier) @debug-variable
(#not-match? @debug-variable "^[A-Z]"))
(set
(identifier) @debug-variable
(#not-match? @debug-variable "^[A-Z]"))
(subscript
value: (identifier) @debug-variable
(#not-match? @debug-variable "^[A-Z]"))
(attribute
object: (identifier) @debug-variable
(#not-match? @debug-variable "^[A-Z]"))
(return_statement
(identifier) @debug-variable
(#not-match? @debug-variable "^[A-Z]"))
(parenthesized_expression
(identifier) @debug-variable
(#not-match? @debug-variable "^[A-Z]"))
(argument_list
(identifier) @debug-variable
(#not-match? @debug-variable "^[A-Z]"))
(if_statement
condition: (identifier) @debug-variable
(#not-match? @debug-variable "^[A-Z]"))
(while_statement
condition: (identifier) @debug-variable
(#not-match? @debug-variable "^[A-Z]"))
(block) @debug-scope
(module) @debug-scope
+90 -47
View File
@@ -1,6 +1,8 @@
; Identifier naming conventions; these "soft conventions" should stay at the top of the file as they're often overridden
(identifier) @variable
(attribute attribute: (identifier) @property)
(attribute
attribute: (identifier) @property)
; CamelCase for classes
((identifier) @type.class
@@ -10,45 +12,56 @@
((identifier) @constant
(#match? @constant "^_*[A-Z][A-Z0-9_]*$"))
(type (identifier) @type)
(generic_type (identifier) @type)
(type
(identifier) @type)
(generic_type
(identifier) @type)
(comment) @comment
(string) @string
(escape_sequence) @string.escape
; Type alias
(type_alias_statement "type" @keyword)
(type_alias_statement
"type" @keyword)
; TypeVar with constraints in type parameters
(type
(tuple (identifier) @type)
)
(tuple
(identifier) @type))
; Forward references
(type
(string) @type
)
(string) @type)
; Function calls
(call
function: (attribute attribute: (identifier) @function.method.call))
function: (attribute
attribute: (identifier) @function.method.call))
(call
function: (identifier) @function.call)
(decorator "@" @punctuation.special)
(decorator
"@" @punctuation.special)
(decorator
"@" @punctuation.special
[
(identifier) @function.decorator
(attribute attribute: (identifier) @function.decorator)
(call function: (identifier) @function.decorator.call)
(call (attribute attribute: (identifier) @function.decorator.call))
(attribute
attribute: (identifier) @function.decorator)
(call
function: (identifier) @function.decorator.call)
(call
(attribute
attribute: (identifier) @function.decorator.call))
])
; Function and class definitions
(function_definition
name: (identifier) @function.definition)
@@ -69,15 +82,15 @@
; Function arguments
(function_definition
parameters: (parameters
[
(identifier) @variable.parameter; Simple parameters
[
(identifier) @variable.parameter ; Simple parameters
(typed_parameter
(identifier) @variable.parameter) ; Typed parameters
(default_parameter
name: (identifier) @variable.parameter) ; Default parameters
(typed_default_parameter
name: (identifier) @variable.parameter) ; Typed default parameters
]))
]))
; Keyword arguments
(call
@@ -86,28 +99,30 @@
name: (identifier) @function.kwargs)))
; Class definitions and calling: needs to come after the regex matching above
(class_definition
name: (identifier) @type.class.definition)
(class_definition
superclasses: (argument_list
(identifier) @type.class.inheritance))
(identifier) @type.class.inheritance))
(call
function: (identifier) @type.class.call
(#match? @type.class.call "^_*[A-Z][A-Za-z0-9_]*$"))
; Builtins
((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__"))
(#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__"))
; Literals
[
(true)
(false)
@@ -124,10 +139,11 @@
] @number
; Self references
[
(parameters (identifier) @variable.special)
(attribute (identifier) @variable.special)
(parameters
(identifier) @variable.special)
(attribute
(identifier) @variable.special)
(#any-of? @variable.special "self" "cls")
]
@@ -152,37 +168,57 @@
; Docstrings.
([
(expression_statement (assignment))
(expression_statement
(assignment))
(type_alias_statement)
]
. (expression_statement (string) @string.doc)+)
.
(expression_statement
(string) @string.doc)+)
(module
.(expression_statement (string) @string.doc)+)
.
(expression_statement
(string) @string.doc)+)
(class_definition
body: (block .(expression_statement (string) @string.doc)+))
body: (block
.
(expression_statement
(string) @string.doc)+))
(function_definition
"async"?
"def"
name: (_)
(parameters)?
body: (block .(expression_statement (string) @string.doc)+))
body: (block
.
(expression_statement
(string) @string.doc)+))
(class_definition
body: (block
. (comment) @comment*
. (expression_statement (string) @string.doc)+))
.
(comment) @comment*
.
(expression_statement
(string) @string.doc)+))
(module
. (comment) @comment*
. (expression_statement (string) @string.doc)+)
.
(comment) @comment*
.
(expression_statement
(string) @string.doc)+)
(class_definition
body: (block
(expression_statement (assignment))
. (expression_statement (string) @string.doc)+))
(expression_statement
(assignment))
.
(expression_statement
(string) @string.doc)+))
(class_definition
body: (block
@@ -190,9 +226,11 @@
name: (identifier) @function.method.constructor
(#eq? @function.method.constructor "__init__")
body: (block
(expression_statement (assignment))
. (expression_statement (string) @string.doc)+))))
(expression_statement
(assignment))
.
(expression_statement
(string) @string.doc)+))))
[
"-"
@@ -286,18 +324,23 @@
"lambda"
] @keyword.definition
(decorator (identifier) @attribute.builtin
(decorator
(identifier) @attribute.builtin
(#any-of? @attribute.builtin "classmethod" "staticmethod" "property"))
; Builtin types as identifiers
[
(call
function: (identifier) @type.builtin)
(type (identifier) @type.builtin)
(generic_type (identifier) @type.builtin)
(type
(identifier) @type.builtin)
(generic_type
(identifier) @type.builtin)
; also check if type binary operator left identifier for union types
(type
(binary_operator
left: (identifier) @type.builtin))
(#any-of? @type.builtin "bool" "bytearray" "bytes" "complex" "dict" "float" "frozenset" "int" "list" "memoryview" "object" "range" "set" "slice" "str" "tuple")
(#any-of? @type.builtin
"bool" "bytearray" "bytes" "complex" "dict" "float" "frozenset" "int" "list" "memoryview"
"object" "range" "set" "slice" "str" "tuple")
]
+35 -29
View File
@@ -1,32 +1,38 @@
(import_statement
name: [
(dotted_name
((identifier) @namespace ".")*
(identifier) @namespace .)
(aliased_import
name: (dotted_name
((identifier) @namespace ".")*
(identifier) @namespace .))
]) @wildcard @import
name: [
(dotted_name
((identifier) @namespace
".")*
(identifier) @namespace .)
(aliased_import
name: (dotted_name
((identifier) @namespace
".")*
(identifier) @namespace .))
]) @wildcard @import
(import_from_statement
module_name: [
(dotted_name
((identifier) @namespace ".")*
(identifier) @namespace .)
(relative_import
(dotted_name
((identifier) @namespace ".")*
(identifier) @namespace .)?)
]
(wildcard_import)? @wildcard
name: [
(dotted_name
((identifier) @namespace ".")*
(identifier) @name .)
(aliased_import
name: (dotted_name
((identifier) @namespace ".")*
(identifier) @name .)
alias: (identifier) @alias)
]?) @import
module_name: [
(dotted_name
((identifier) @namespace
".")*
(identifier) @namespace .)
(relative_import
(dotted_name
((identifier) @namespace
".")*
(identifier) @namespace .)?)
]
(wildcard_import)? @wildcard
name: [
(dotted_name
((identifier) @namespace
".")*
(identifier) @name .)
(aliased_import
name: (dotted_name
((identifier) @namespace
".")*
(identifier) @name .)
alias: (identifier) @alias)
]?) @import
+23 -3
View File
@@ -1,17 +1,37 @@
(_ "[" "]" @end) @indent
(_ "{" "}" @end) @indent
(_ "(" ")" @end) @indent
(_
"["
"]" @end) @indent
(_
"{"
"}" @end) @indent
(_
"("
")" @end) @indent
(function_definition) @start.def
(class_definition) @start.class
(if_statement) @start.if
(for_statement) @start.for
(while_statement) @start.while
(with_statement) @start.with
(match_statement) @start.match
(try_statement) @start.try
(elif_clause) @start.elif
(else_clause) @start.else
(except_clause) @start.except
(finally_clause) @start.finally
(case_clause) @start.case
+5 -6
View File
@@ -1,11 +1,10 @@
(decorator) @annotation
(class_definition
"class" @context
name: (identifier) @name
) @item
"class" @context
name: (identifier) @name) @item
(function_definition
"async"? @context
"def" @context
name: (_) @name) @item
"async"? @context
"def" @context
name: (_) @name) @item
@@ -1,2 +1,3 @@
(comment) @comment.inclusive
(string) @string
+90 -133
View File
@@ -1,151 +1,108 @@
; subclasses of unittest.TestCase or TestCase
(
(class_definition
name: (identifier) @run @_unittest_class_name
superclasses: (argument_list
[(identifier) @_superclass
(attribute (identifier) @_superclass)]
)
(#eq? @_superclass "TestCase")
) @_python-unittest-class
(#set! tag python-unittest-class)
)
((class_definition
name: (identifier) @run @_unittest_class_name
superclasses: (argument_list
[
(identifier) @_superclass
(attribute
(identifier) @_superclass)
])
(#eq? @_superclass "TestCase")) @_python-unittest-class
(#set! tag python-unittest-class))
; test methods whose names start with `test` in a TestCase
(
(class_definition
name: (identifier) @_unittest_class_name
superclasses: (argument_list
[(identifier) @_superclass
(attribute (identifier) @_superclass)]
)
(#eq? @_superclass "TestCase")
body: (block
(function_definition
name: (identifier) @run @_unittest_method_name
(#match? @_unittest_method_name "^test.*")
) @_python-unittest-method
(#set! tag python-unittest-method)
)
)
)
(class_definition
name: (identifier) @_unittest_class_name
superclasses: (argument_list
[
(identifier) @_superclass
(attribute
(identifier) @_superclass)
])
(#eq? @_superclass "TestCase")
body: (block
(function_definition
name: (identifier) @run @_unittest_method_name
(#match? @_unittest_method_name "^test.*")) @_python-unittest-method
(#set! tag python-unittest-method)))
; pytest functions
(
(module
(function_definition
name: (identifier) @run @_pytest_method_name
(#match? @_pytest_method_name "^test_")
) @_python-pytest-method
)
(#set! tag python-pytest-method)
)
((module
(function_definition
name: (identifier) @run @_pytest_method_name
(#match? @_pytest_method_name "^test_")) @_python-pytest-method)
(#set! tag python-pytest-method))
; decorated pytest functions
(
(module
(decorated_definition
(decorator)+ @_decorator
definition: (function_definition
name: (identifier) @run @_pytest_method_name
(#match? @_pytest_method_name "^test_")
)
) @_python-pytest-method
)
(#set! tag python-pytest-method)
)
((module
(decorated_definition
(decorator)+ @_decorator
definition: (function_definition
name: (identifier) @run @_pytest_method_name
(#match? @_pytest_method_name "^test_"))) @_python-pytest-method)
(#set! tag python-pytest-method))
; pytest classes
(
(module
(class_definition
name: (identifier) @run @_pytest_class_name
(#match? @_pytest_class_name "^Test")
)
(#set! tag python-pytest-class)
)
)
(module
(class_definition
name: (identifier) @run @_pytest_class_name
(#match? @_pytest_class_name "^Test"))
(#set! tag python-pytest-class))
; decorated pytest classes
(
(module
(decorated_definition
(decorator)+ @_decorator
definition: (class_definition
name: (identifier) @run @_pytest_class_name
(#match? @_pytest_class_name "^Test")
)
)
(#set! tag python-pytest-class)
)
)
(module
(decorated_definition
(decorator)+ @_decorator
definition: (class_definition
name: (identifier) @run @_pytest_class_name
(#match? @_pytest_class_name "^Test")))
(#set! tag python-pytest-class))
; pytest class methods
(
(module
(class_definition
name: (identifier) @_pytest_class_name
(#match? @_pytest_class_name "^Test")
body: (block
[(decorated_definition
(decorator)+ @_decorator
definition: (function_definition
name: (identifier) @run @_pytest_method_name
(#match? @_pytest_method_name "^test_")
)
)
(function_definition
name: (identifier) @run @_pytest_method_name
(#match? @_pytest_method_name "^test")
)
] @_python-pytest-method)
(#set! tag python-pytest-method)
)
)
)
(module
(class_definition
name: (identifier) @_pytest_class_name
(#match? @_pytest_class_name "^Test")
body: (block
[
(decorated_definition
(decorator)+ @_decorator
definition: (function_definition
name: (identifier) @run @_pytest_method_name
(#match? @_pytest_method_name "^test_")))
(function_definition
name: (identifier) @run @_pytest_method_name
(#match? @_pytest_method_name "^test"))
] @_python-pytest-method)
(#set! tag python-pytest-method)))
; decorated pytest class methods
(
(module
(decorated_definition
(module
(decorated_definition
(decorator)+ @_decorator
definition: (class_definition
name: (identifier) @_pytest_class_name
(#match? @_pytest_class_name "^Test")
body: (block
[
(decorated_definition
(decorator)+ @_decorator
definition: (class_definition
name: (identifier) @_pytest_class_name
(#match? @_pytest_class_name "^Test")
body: (block
[(decorated_definition
(decorator)+ @_decorator
definition: (function_definition
name: (identifier) @run @_pytest_method_name
(#match? @_pytest_method_name "^test_")
)
)
(function_definition
name: (identifier) @run @_pytest_method_name
(#match? @_pytest_method_name "^test")
)
] @_python-pytest-method)
(#set! tag python-pytest-method)
)
)
)
)
definition: (function_definition
name: (identifier) @run @_pytest_method_name
(#match? @_pytest_method_name "^test_")))
(function_definition
name: (identifier) @run @_pytest_method_name
(#match? @_pytest_method_name "^test"))
] @_python-pytest-method)
(#set! tag python-pytest-method))))
; module main method
(
(module
(if_statement
condition: (comparison_operator
(identifier) @run @_lhs
operators: "=="
(string) @_rhs
)
(#eq? @_lhs "__name__")
(#match? @_rhs "^[\"']__main__[\"']$")
(#set! tag python-module-main-method)
)
)
)
(module
(if_statement
condition: (comparison_operator
(identifier) @run @_lhs
operators: "=="
(string) @_rhs)
(#eq? @_lhs "__name__")
(#match? @_rhs "^[\"']__main__[\"']$")
(#set! tag python-module-main-method)))