aboutsummaryrefslogtreecommitdiffstats
path: root/queries/python
diff options
context:
space:
mode:
authorFabian <f.vioel@gmail.com>2021-12-18 22:49:30 +0100
committerGitHub <noreply@github.com>2021-12-18 16:49:30 -0500
commite01c7ce9727b9d18b71b41cc792cb4719e469598 (patch)
treec082cddee304089a402eca397db0a9a95c222d60 /queries/python
parentUpdate lockfile.json (diff)
downloadnvim-treesitter-e01c7ce9727b9d18b71b41cc792cb4719e469598.tar
nvim-treesitter-e01c7ce9727b9d18b71b41cc792cb4719e469598.tar.gz
nvim-treesitter-e01c7ce9727b9d18b71b41cc792cb4719e469598.tar.bz2
nvim-treesitter-e01c7ce9727b9d18b71b41cc792cb4719e469598.tar.lz
nvim-treesitter-e01c7ce9727b9d18b71b41cc792cb4719e469598.tar.xz
nvim-treesitter-e01c7ce9727b9d18b71b41cc792cb4719e469598.tar.zst
nvim-treesitter-e01c7ce9727b9d18b71b41cc792cb4719e469598.zip
highlights(python): Improve self and cls highlight (#2134)
1. This function simplifies an unnecessary lua-match usage. 2. Fixes an accidental change, where "cls" was changed to "class" (fe4f320b66) 3. Match functions, which have have a decorator. 4. But exclude @staticmethod 5. Only highlight "cls" as @variable.builtin when the decorator is @classmethod This might be a bit to complicated and some of this not to useful, as this existing rule: ```scm ((identifier) @variable.builtin (#eq? @variable.builtin "self")) ``` overwrites the queries anyway.
Diffstat (limited to 'queries/python')
-rw-r--r--queries/python/highlights.scm13
1 files changed, 8 insertions, 5 deletions
diff --git a/queries/python/highlights.scm b/queries/python/highlights.scm
index 423948e51..533233e48 100644
--- a/queries/python/highlights.scm
+++ b/queries/python/highlights.scm
@@ -133,7 +133,7 @@
(none) @constant.builtin
[(true) (false)] @boolean
((identifier) @variable.builtin
- (#lua-match? @variable.builtin "^self$"))
+ (#eq? @variable.builtin "self"))
(integer) @number
(float) @float
@@ -275,12 +275,15 @@
name: (identifier) @constructor)))
(#any-of? @constructor "__new__" "__init__"))
-; First parameter of a method is self or cls.
+; First parameter of a classmethod is cls.
((class_definition
body: (block
- (function_definition
- parameters: (parameters . (identifier) @variable.builtin))))
- (#any-of? @variable.builtin "self" "obj" "class"))
+ (decorated_definition
+ (decorator (identifier) @_decorator)
+ definition: (function_definition
+ parameters: (parameters . (identifier) @variable.builtin)))))
+ (#eq? @variable.builtin "cls")
+ (#eq? @_decorator "classmethod"))
;; Error
(ERROR) @error