Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
python: Add capture groups for builtin types, builtin attribute decorators, class inheritance, function arguments and definition keywords (#21454)
Elisiário Couto73001a72e3c5
diff --git a/crates/languages/src/python/highlights.scm b/crates/languages/src/python/highlights.scmindex 9d08237e3cb..6b296574786 100644--- a/crates/languages/src/python/highlights.scm+++ b/crates/languages/src/python/highlights.scm@@ -36,6 +36,7 @@(callfunction: (identifier) @function.call)+(decorator "@" @punctuation.special)(decorator"@" @punctuation.special[@@ -50,11 +51,32 @@(function_definitionname: (identifier) @function.definition)+; Function arguments+(function_definition+ parameters: (parameters+ [+ (identifier) @function.arguments ; Simple parameters+ (typed_parameter+ (identifier) @function.arguments) ; Typed parameters+ (default_parameter+ name: (identifier) @function.arguments) ; Default parameters+ ]))++; Keyword arguments+(call+ arguments: (argument_list+ (keyword_argument+ name: (identifier) @function.kwargs)))+; Class definitions and calling: needs to come after the regex matching above(class_definitionname: (identifier) @type.class.definition)+(class_definition+ superclasses: (argument_list+ (identifier) @type.class.inheritance))+(callfunction: (identifier) @type.class.call(#match? @type.class.call "^_*[A-Z][A-Za-z0-9_]*$"))@@ -69,7 +91,7 @@((identifier) @type.builtin(#any-of? @type.builtin "int" "float" "complex" "bool" "list" "tuple" "range" "str" "bytes" "bytearray" "memoryview" "set" "frozenset" "dict"))-+; Literals[@@ -221,3 +243,33 @@"match""case"] @keyword++; Definition keywords def, class, async def, lambda+[+ "async"+ "def"+ "class"+ "lambda"+] @keyword.definition++((identifier) @attribute.builtin+ (#any-of? @attribute.builtin "classmethod" "staticmethod" "property"))++; Builtin types as identifiers+[+ (call+ function: (identifier) @type.builtin)+ (call+ arguments: (argument_list+ (identifier) @type.builtin))+ (call+ arguments: (argument_list+ (keyword_argument+ value: (identifier) @type.builtin)))+ (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")+] @type.builtin