aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmaan Qureshi <amaanq12@gmail.com>2023-04-24 00:38:31 -0400
committerAmaan Qureshi <amaanq12@gmail.com>2023-04-25 03:04:05 -0400
commit87faf372eb517077cc600c4e653e4fb3252d02ac (patch)
tree7753d3ac7bc5e731d077bf9a1c4ae079f386a994
parentfeat(python,starlark): highlight type conversions as `@function.macro` (diff)
downloadnvim-treesitter-87faf372eb517077cc600c4e653e4fb3252d02ac.tar
nvim-treesitter-87faf372eb517077cc600c4e653e4fb3252d02ac.tar.gz
nvim-treesitter-87faf372eb517077cc600c4e653e4fb3252d02ac.tar.bz2
nvim-treesitter-87faf372eb517077cc600c4e653e4fb3252d02ac.tar.lz
nvim-treesitter-87faf372eb517077cc600c4e653e4fb3252d02ac.tar.xz
nvim-treesitter-87faf372eb517077cc600c4e653e4fb3252d02ac.tar.zst
nvim-treesitter-87faf372eb517077cc600c4e653e4fb3252d02ac.zip
fix(python,starlark): builtin types should come after types
-rw-r--r--queries/python/highlights.scm36
-rw-r--r--queries/starlark/highlights.scm36
-rw-r--r--tests/query/highlights/python/fields.py4
3 files changed, 39 insertions, 37 deletions
diff --git a/queries/python/highlights.scm b/queries/python/highlights.scm
index 6e9436ff1..956b1d19c 100644
--- a/queries/python/highlights.scm
+++ b/queries/python/highlights.scm
@@ -31,24 +31,6 @@
attribute: (identifier) @field)
(#lua-match? @field "^.*%l.*$"))
-((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"))
-
((assignment
left: (identifier) @type.definition
(type (identifier) @_annotation))
@@ -341,5 +323,23 @@
name: (identifier) @constructor)))
(#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"))
+
;; Error
(ERROR) @error
diff --git a/queries/starlark/highlights.scm b/queries/starlark/highlights.scm
index b203bc9d6..42776c89f 100644
--- a/queries/starlark/highlights.scm
+++ b/queries/starlark/highlights.scm
@@ -31,24 +31,6 @@
attribute: (identifier) @field)
(#lua-match? @field "^.*%l.*$"))
-((identifier) @type.builtin
- (#any-of? @type.builtin
- ;; https://docs.python.org/3/library/exceptions.html
- "ArithmeticError" "BufferError" "LookupError" "AssertionError" "AttributeError"
- "EOFError" "FloatingPointError" "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" "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"))
-
((assignment
left: (identifier) @type.definition
(type (identifier) @_annotation))
@@ -106,6 +88,24 @@
(identifier) @type))
(#eq? @_isinstance "isinstance"))
+((identifier) @type.builtin
+ (#any-of? @type.builtin
+ ;; https://docs.python.org/3/library/exceptions.html
+ "ArithmeticError" "BufferError" "LookupError" "AssertionError" "AttributeError"
+ "EOFError" "FloatingPointError" "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" "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"))
+
;; Normal parameters
(parameters
(identifier) @parameter)
diff --git a/tests/query/highlights/python/fields.py b/tests/query/highlights/python/fields.py
index 21b6251dc..fb36a6311 100644
--- a/tests/query/highlights/python/fields.py
+++ b/tests/query/highlights/python/fields.py
@@ -1,5 +1,7 @@
class Fields:
- def __init__(self, fields):
+ def __init__(self, fields: list[int]) -> None:
+# ^^^ @type.builtin
+# ^^^^ @constant.builtin
self.fields = fields
# ^^^^^^ @field
self.__dunderfield__ = None