mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-18 03:10:04 -04:00
Python: update highlights
- Get rid of @self - Highlight methods correctly - Highlight self as the first parameter of a method - Use new syntax (# for predicates, (_) instead of (*) for wildcards)
This commit is contained in:
parent
ed3469b59f
commit
cf37d143bf
1 changed files with 37 additions and 33 deletions
|
|
@ -4,24 +4,24 @@
|
||||||
; Reset highlighing in f-string interpolations
|
; Reset highlighing in f-string interpolations
|
||||||
(interpolation) @Normal
|
(interpolation) @Normal
|
||||||
|
|
||||||
; Identifier naming conventions
|
;; Identifier naming conventions
|
||||||
((identifier) @type
|
((identifier) @type
|
||||||
(match? @type "^[A-Z]"))
|
(#match? @type "^[A-Z]"))
|
||||||
((identifier) @constant
|
((identifier) @constant
|
||||||
(match? @constant "^[A-Z][A-Z_0-9]*$"))
|
(#match? @constant "^[A-Z][A-Z_0-9]*$"))
|
||||||
|
|
||||||
((identifier) @constant.builtin
|
((identifier) @constant.builtin
|
||||||
(match? @constant.builtin "^__[a-zA-Z0-9_]*__$"))
|
(#match? @constant.builtin "^__[a-zA-Z0-9_]*__$"))
|
||||||
|
|
||||||
((attribute
|
((attribute
|
||||||
attribute: (identifier) @field)
|
attribute: (identifier) @field)
|
||||||
(match? @field "^([A-Z])@!.*$"))
|
(#match? @field "^([A-Z])@!.*$"))
|
||||||
|
|
||||||
; Function calls
|
; Function calls
|
||||||
|
|
||||||
(decorator) @function
|
(decorator) @function
|
||||||
((decorator (dotted_name (identifier) @function))
|
((decorator (dotted_name (identifier) @function))
|
||||||
(match? @function "^([A-Z])@!.*$"))
|
(#match? @function "^([A-Z])@!.*$"))
|
||||||
|
|
||||||
(call
|
(call
|
||||||
function: (identifier) @function)
|
function: (identifier) @function)
|
||||||
|
|
@ -32,12 +32,12 @@
|
||||||
|
|
||||||
((call
|
((call
|
||||||
function: (identifier) @constructor)
|
function: (identifier) @constructor)
|
||||||
(match? @constructor "^[A-Z]"))
|
(#match? @constructor "^[A-Z]"))
|
||||||
|
|
||||||
((call
|
((call
|
||||||
function: (attribute
|
function: (attribute
|
||||||
attribute: (identifier) @constructor))
|
attribute: (identifier) @constructor))
|
||||||
(match? @constructor "^[A-Z]"))
|
(#match? @constructor "^[A-Z]"))
|
||||||
|
|
||||||
;; Builtin functions
|
;; Builtin functions
|
||||||
|
|
||||||
|
|
@ -52,19 +52,6 @@
|
||||||
(function_definition
|
(function_definition
|
||||||
name: (identifier) @function)
|
name: (identifier) @function)
|
||||||
|
|
||||||
((function_definition
|
|
||||||
name: (identifier) @method
|
|
||||||
parameters: (parameters
|
|
||||||
(identifier) @self) )
|
|
||||||
(eq? @self "self"))
|
|
||||||
|
|
||||||
((function_definition
|
|
||||||
name: (identifier) @constructor
|
|
||||||
parameters: (parameters
|
|
||||||
(identifier) @self) )
|
|
||||||
(eq? @self "self")
|
|
||||||
(vim-match? @constructor "(__new__|__init__)"))
|
|
||||||
|
|
||||||
(type (identifier) @type)
|
(type (identifier) @type)
|
||||||
(type
|
(type
|
||||||
(subscript
|
(subscript
|
||||||
|
|
@ -73,9 +60,9 @@
|
||||||
((call
|
((call
|
||||||
function: (identifier) @isinstance
|
function: (identifier) @isinstance
|
||||||
arguments: (argument_list
|
arguments: (argument_list
|
||||||
(*)
|
(_)
|
||||||
(identifier) @type))
|
(identifier) @type))
|
||||||
(eq? @isinstance "isinstance"))
|
(#eq? @isinstance "isinstance"))
|
||||||
|
|
||||||
; Normal parameters
|
; Normal parameters
|
||||||
(parameters
|
(parameters
|
||||||
|
|
@ -112,7 +99,7 @@
|
||||||
(none) @constant.builtin
|
(none) @constant.builtin
|
||||||
[(true) (false)] @boolean
|
[(true) (false)] @boolean
|
||||||
((identifier) @constant.builtin
|
((identifier) @constant.builtin
|
||||||
(match? @constant.builtin "self"))
|
(#match? @constant.builtin "self"))
|
||||||
|
|
||||||
(integer) @number
|
(integer) @number
|
||||||
(float) @float
|
(float) @float
|
||||||
|
|
@ -185,27 +172,31 @@
|
||||||
"yield"
|
"yield"
|
||||||
] @keyword
|
] @keyword
|
||||||
|
|
||||||
[ "as" "from" "import"] @include
|
["as" "from" "import"] @include
|
||||||
|
|
||||||
[ "if" "elif" "else" ] @conditional
|
["if" "elif" "else"] @conditional
|
||||||
|
|
||||||
[ "for" "while" "break" "continue" ] @repeat
|
["for" "while" "break" "continue"] @repeat
|
||||||
|
|
||||||
[ "(" ")" "[" "]" "{" "}"] @punctuation.bracket
|
["(" ")" "[" "]" "{" "}"] @punctuation.bracket
|
||||||
|
|
||||||
(interpolation
|
(interpolation
|
||||||
"{" @punctuation.special
|
"{" @punctuation.special
|
||||||
"}" @punctuation.special) @embedded
|
"}" @punctuation.special) @embedded
|
||||||
|
|
||||||
[ "," "." ":" (ellipsis) ] @punctuation.delimiter
|
["," "." ":" (ellipsis)] @punctuation.delimiter
|
||||||
|
|
||||||
; Class definitions
|
;; Class definitions
|
||||||
|
|
||||||
(class_definition
|
(class_definition
|
||||||
name: (identifier) @type)
|
name: (identifier) @type
|
||||||
|
body: (block
|
||||||
|
(function_definition
|
||||||
|
name: (identifier) @method)))
|
||||||
|
|
||||||
(class_definition
|
(class_definition
|
||||||
superclasses: (argument_list
|
superclasses: (argument_list
|
||||||
(identifier) @type))
|
(identifier) @type))
|
||||||
|
|
||||||
((class_definition
|
((class_definition
|
||||||
body: (block
|
body: (block
|
||||||
|
|
@ -213,7 +204,20 @@
|
||||||
(assignment
|
(assignment
|
||||||
left: (expression_list
|
left: (expression_list
|
||||||
(identifier) @field)))))
|
(identifier) @field)))))
|
||||||
(match? @field "^([A-Z])@!.*$"))
|
(#match? @field "^([A-Z])@!.*$"))
|
||||||
|
|
||||||
|
((class_definition
|
||||||
|
(block
|
||||||
|
(function_definition
|
||||||
|
name: (identifier) @constructor)))
|
||||||
|
(#vim-match? @constructor "^(__new__|__init__)$"))
|
||||||
|
|
||||||
|
; First parameter of a method is self or cls.
|
||||||
|
((class_definition
|
||||||
|
body: (block
|
||||||
|
(function_definition
|
||||||
|
parameters: (parameters . (identifier) @constant.builtin))))
|
||||||
|
(#vim-match? @constant.builtin "^(self|obj|cls)$"))
|
||||||
|
|
||||||
;; Error
|
;; Error
|
||||||
(ERROR) @error
|
(ERROR) @error
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue