python: Enhance syntax highlighting for type hints (#18185)
Release Notes: - Python: Improved syntax highlighting for type hints. # Before  # After  --- Why manual recursion? - Due to tree-sitter grammar not supporting recursion in query (https://github.com/tree-sitter-grammars/tree-sitter-lua/issues/24), currently only manual recursion is possible (refer to https://github.com/projekt0n/github-nvim-theme/pull/250/files). <br/> Unable to highlight when simple structures appear before complex structures, example: ```python def t() -> str | dict[int, dict[int, dict[int, str]]]: pass ``` Because complex structures are parsed as `subscript` rather than `generic_type` by tree-sitter in this case ☹ <br/> Related: - https://github.com/zed-industries/zed/issues/14715 - [Union Type (Python Doc)](https://docs.python.org/3/library/stdtypes.html#union-type) - [Type parameter lists (Python Doc)](https://docs.python.org/3/reference/compound_stmts.html#type-parameter-lists) --------- Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
This commit is contained in:
parent
052b746fbd
commit
188a893fd0
1 changed files with 9 additions and 0 deletions
|
@ -1,5 +1,14 @@
|
|||
(attribute attribute: (identifier) @property)
|
||||
(type (identifier) @type)
|
||||
(generic_type (identifier) @type)
|
||||
|
||||
; Type alias
|
||||
(type_alias_statement "type" @keyword)
|
||||
|
||||
; TypeVar with constraints in type parameters
|
||||
(type
|
||||
(tuple (identifier) @type)
|
||||
)
|
||||
|
||||
; Function calls
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue