mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-20 04:10:06 -04:00
fix(python): highlight function calls correctly (#7728)
This commit is contained in:
parent
db8689da4a
commit
1a314a58d6
3 changed files with 77 additions and 42 deletions
|
|
@ -35,48 +35,6 @@
|
||||||
function: (identifier) @_func))
|
function: (identifier) @_func))
|
||||||
(#any-of? @_func "TypeVar" "NewType"))
|
(#any-of? @_func "TypeVar" "NewType"))
|
||||||
|
|
||||||
; Function calls
|
|
||||||
(call
|
|
||||||
function: (identifier) @function.call)
|
|
||||||
|
|
||||||
(call
|
|
||||||
function: (attribute
|
|
||||||
attribute: (identifier) @function.method.call))
|
|
||||||
|
|
||||||
((call
|
|
||||||
function: (identifier) @constructor)
|
|
||||||
(#lua-match? @constructor "^%u"))
|
|
||||||
|
|
||||||
((call
|
|
||||||
function: (attribute
|
|
||||||
attribute: (identifier) @constructor))
|
|
||||||
(#lua-match? @constructor "^%u"))
|
|
||||||
|
|
||||||
; Decorators
|
|
||||||
((decorator
|
|
||||||
"@" @attribute)
|
|
||||||
(#set! priority 101))
|
|
||||||
|
|
||||||
(decorator
|
|
||||||
(identifier) @attribute)
|
|
||||||
|
|
||||||
(decorator
|
|
||||||
(attribute
|
|
||||||
attribute: (identifier) @attribute))
|
|
||||||
|
|
||||||
(decorator
|
|
||||||
(call
|
|
||||||
(identifier) @attribute))
|
|
||||||
|
|
||||||
(decorator
|
|
||||||
(call
|
|
||||||
(attribute
|
|
||||||
attribute: (identifier) @attribute)))
|
|
||||||
|
|
||||||
((decorator
|
|
||||||
(identifier) @attribute.builtin)
|
|
||||||
(#any-of? @attribute.builtin "classmethod" "property" "staticmethod"))
|
|
||||||
|
|
||||||
; Builtin functions
|
; Builtin functions
|
||||||
((call
|
((call
|
||||||
function: (identifier) @function.builtin)
|
function: (identifier) @function.builtin)
|
||||||
|
|
@ -450,6 +408,23 @@
|
||||||
name: (identifier) @constructor)))
|
name: (identifier) @constructor)))
|
||||||
(#any-of? @constructor "__new__" "__init__"))
|
(#any-of? @constructor "__new__" "__init__"))
|
||||||
|
|
||||||
|
; Function calls
|
||||||
|
(call
|
||||||
|
function: (identifier) @function.call)
|
||||||
|
|
||||||
|
(call
|
||||||
|
function: (attribute
|
||||||
|
attribute: (identifier) @function.method.call))
|
||||||
|
|
||||||
|
((call
|
||||||
|
function: (identifier) @constructor)
|
||||||
|
(#lua-match? @constructor "^%u"))
|
||||||
|
|
||||||
|
((call
|
||||||
|
function: (attribute
|
||||||
|
attribute: (identifier) @constructor))
|
||||||
|
(#lua-match? @constructor "^%u"))
|
||||||
|
|
||||||
; Regex from the `re` module
|
; Regex from the `re` module
|
||||||
(call
|
(call
|
||||||
function: (attribute
|
function: (attribute
|
||||||
|
|
@ -459,3 +434,28 @@
|
||||||
(string
|
(string
|
||||||
(string_content) @string.regexp))
|
(string_content) @string.regexp))
|
||||||
(#eq? @_re "re"))
|
(#eq? @_re "re"))
|
||||||
|
|
||||||
|
; Decorators
|
||||||
|
((decorator
|
||||||
|
"@" @attribute)
|
||||||
|
(#set! priority 101))
|
||||||
|
|
||||||
|
(decorator
|
||||||
|
(identifier) @attribute)
|
||||||
|
|
||||||
|
(decorator
|
||||||
|
(attribute
|
||||||
|
attribute: (identifier) @attribute))
|
||||||
|
|
||||||
|
(decorator
|
||||||
|
(call
|
||||||
|
(identifier) @attribute))
|
||||||
|
|
||||||
|
(decorator
|
||||||
|
(call
|
||||||
|
(attribute
|
||||||
|
attribute: (identifier) @attribute)))
|
||||||
|
|
||||||
|
((decorator
|
||||||
|
(identifier) @attribute.builtin)
|
||||||
|
(#any-of? @attribute.builtin "classmethod" "property" "staticmethod"))
|
||||||
|
|
|
||||||
22
tests/query/highlights/python/decorators.py
Normal file
22
tests/query/highlights/python/decorators.py
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
#^^^^^^^^^ @attribute
|
||||||
|
class Data:
|
||||||
|
_foo: str
|
||||||
|
|
||||||
|
@property
|
||||||
|
# ^ @attribute
|
||||||
|
# ^^^^^^^^ @attribute.builtin
|
||||||
|
def foo(self) -> str:
|
||||||
|
return self._foo
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
|
||||||
|
#^^^^^^ @variable
|
||||||
|
# ^^^^ @variable.member
|
||||||
|
# ^^^^^^^^^^^^^^ @attribute
|
||||||
|
def test_func():
|
||||||
|
pass
|
||||||
|
|
||||||
13
tests/query/highlights/python/functions.py
Normal file
13
tests/query/highlights/python/functions.py
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
def func() -> None: ...
|
||||||
|
|
||||||
|
_ = func()
|
||||||
|
# ^^^^ @function.call
|
||||||
|
|
||||||
|
"{}".format(1)
|
||||||
|
# ^^^^^^ @function.method.call
|
||||||
|
|
||||||
|
class Foo:
|
||||||
|
def method(self) -> None: ...
|
||||||
|
|
||||||
|
Foo().method()
|
||||||
|
# ^^^^^^ @function.method.call
|
||||||
Loading…
Add table
Add a link
Reference in a new issue