mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-14 17:30:08 -04:00
fix(python): don't highlight attribute name as builtin (#7712)
* fix(python): don't highlight attribute name as builtin * fix(python): highlight `@variable.member` correctly for member access context * test: add test * test: expand test * docs: update comment * refactor: change order, remove priority override * style: remove extra newline
This commit is contained in:
parent
833405d5a9
commit
cf0eabc16c
2 changed files with 30 additions and 24 deletions
|
|
@ -23,10 +23,6 @@
|
||||||
|
|
||||||
"_" @character.special ; match wildcard
|
"_" @character.special ; match wildcard
|
||||||
|
|
||||||
((attribute
|
|
||||||
attribute: (identifier) @variable.member)
|
|
||||||
(#lua-match? @variable.member "^[%l_].*$"))
|
|
||||||
|
|
||||||
((assignment
|
((assignment
|
||||||
left: (identifier) @type.definition
|
left: (identifier) @type.definition
|
||||||
(type
|
(type
|
||||||
|
|
@ -395,6 +391,31 @@
|
||||||
(ellipsis)
|
(ellipsis)
|
||||||
] @punctuation.delimiter
|
] @punctuation.delimiter
|
||||||
|
|
||||||
|
((identifier) @type.builtin
|
||||||
|
(#any-of? @type.builtin
|
||||||
|
; https://docs.python.org/3/library/exceptions.html
|
||||||
|
"BaseException" "Exception" "ArithmeticError" "BufferError" "LookupError" "AssertionError"
|
||||||
|
"AttributeError" "EOFError" "FloatingPointError" "GeneratorExit" "ImportError"
|
||||||
|
"ModuleNotFoundError" "IndexError" "KeyError" "KeyboardInterrupt" "MemoryError" "NameError"
|
||||||
|
"NotImplementedError" "OSError" "OverflowError" "RecursionError" "ReferenceError" "RuntimeError"
|
||||||
|
"StopIteration" "StopAsyncIteration" "SyntaxError" "IndentationError" "TabError" "SystemError"
|
||||||
|
"SystemExit" "TypeError" "UnboundLocalError" "UnicodeError" "UnicodeEncodeError"
|
||||||
|
"UnicodeDecodeError" "UnicodeTranslateError" "ValueError" "ZeroDivisionError" "EnvironmentError"
|
||||||
|
"IOError" "WindowsError" "BlockingIOError" "ChildProcessError" "ConnectionError"
|
||||||
|
"BrokenPipeError" "ConnectionAbortedError" "ConnectionRefusedError" "ConnectionResetError"
|
||||||
|
"FileExistsError" "FileNotFoundError" "InterruptedError" "IsADirectoryError"
|
||||||
|
"NotADirectoryError" "PermissionError" "ProcessLookupError" "TimeoutError" "Warning"
|
||||||
|
"UserWarning" "DeprecationWarning" "PendingDeprecationWarning" "SyntaxWarning" "RuntimeWarning"
|
||||||
|
"FutureWarning" "ImportWarning" "UnicodeWarning" "BytesWarning" "ResourceWarning"
|
||||||
|
; https://docs.python.org/3/library/stdtypes.html
|
||||||
|
"bool" "int" "float" "complex" "list" "tuple" "range" "str" "bytes" "bytearray" "memoryview"
|
||||||
|
"set" "frozenset" "dict" "type" "object"))
|
||||||
|
|
||||||
|
; After @type.builtin bacause builtins (such as `type`) are valid as attribute name
|
||||||
|
((attribute
|
||||||
|
attribute: (identifier) @variable.member)
|
||||||
|
(#lua-match? @variable.member "^[%l_].*$"))
|
||||||
|
|
||||||
; Class definitions
|
; Class definitions
|
||||||
(class_definition
|
(class_definition
|
||||||
name: (identifier) @type)
|
name: (identifier) @type)
|
||||||
|
|
@ -429,26 +450,6 @@
|
||||||
name: (identifier) @constructor)))
|
name: (identifier) @constructor)))
|
||||||
(#any-of? @constructor "__new__" "__init__"))
|
(#any-of? @constructor "__new__" "__init__"))
|
||||||
|
|
||||||
((identifier) @type.builtin
|
|
||||||
(#any-of? @type.builtin
|
|
||||||
; https://docs.python.org/3/library/exceptions.html
|
|
||||||
"BaseException" "Exception" "ArithmeticError" "BufferError" "LookupError" "AssertionError"
|
|
||||||
"AttributeError" "EOFError" "FloatingPointError" "GeneratorExit" "ImportError"
|
|
||||||
"ModuleNotFoundError" "IndexError" "KeyError" "KeyboardInterrupt" "MemoryError" "NameError"
|
|
||||||
"NotImplementedError" "OSError" "OverflowError" "RecursionError" "ReferenceError" "RuntimeError"
|
|
||||||
"StopIteration" "StopAsyncIteration" "SyntaxError" "IndentationError" "TabError" "SystemError"
|
|
||||||
"SystemExit" "TypeError" "UnboundLocalError" "UnicodeError" "UnicodeEncodeError"
|
|
||||||
"UnicodeDecodeError" "UnicodeTranslateError" "ValueError" "ZeroDivisionError" "EnvironmentError"
|
|
||||||
"IOError" "WindowsError" "BlockingIOError" "ChildProcessError" "ConnectionError"
|
|
||||||
"BrokenPipeError" "ConnectionAbortedError" "ConnectionRefusedError" "ConnectionResetError"
|
|
||||||
"FileExistsError" "FileNotFoundError" "InterruptedError" "IsADirectoryError"
|
|
||||||
"NotADirectoryError" "PermissionError" "ProcessLookupError" "TimeoutError" "Warning"
|
|
||||||
"UserWarning" "DeprecationWarning" "PendingDeprecationWarning" "SyntaxWarning" "RuntimeWarning"
|
|
||||||
"FutureWarning" "ImportWarning" "UnicodeWarning" "BytesWarning" "ResourceWarning"
|
|
||||||
; https://docs.python.org/3/library/stdtypes.html
|
|
||||||
"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
|
(call
|
||||||
function: (attribute
|
function: (attribute
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,14 @@
|
||||||
class Fields:
|
class Fields:
|
||||||
|
type: str
|
||||||
|
# ^^^^ @variable.member
|
||||||
|
|
||||||
def __init__(self, fields: list[int]) -> None:
|
def __init__(self, fields: list[int]) -> None:
|
||||||
# ^^^ @type.builtin
|
# ^^^ @type.builtin
|
||||||
# ^^^^ @constant.builtin
|
# ^^^^ @constant.builtin
|
||||||
self.fields = fields
|
self.fields = fields
|
||||||
# ^^^^^^ @variable.member
|
# ^^^^^^ @variable.member
|
||||||
|
self.type = "foo"
|
||||||
|
# ^^^^ @variable.member
|
||||||
self.__dunderfield__ = None
|
self.__dunderfield__ = None
|
||||||
# ^^^^^^^^^^^^^^^ @variable.member
|
# ^^^^^^^^^^^^^^^ @variable.member
|
||||||
self._FunKyFielD = 0
|
self._FunKyFielD = 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue