-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
python: Enhance syntax highlighting for type hints #18185
python: Enhance syntax highlighting for type hints #18185
Conversation
937c0e2
to
1a2db3f
Compare
(generic_type (identifier) @type) | ||
|
||
; Union type X | Y (up to 8 types) | ||
(type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maxbrunsfeld Do you have thoughts on this approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should land this code. I get that it's working around a limitation in the query system right now, but I think we just need to fix that limitation.
I worry this is going to have a negative performance impact, and it's also just hard to understand and maintain.
@ClanEver Can you back out the one complex pattern from the query (sorry that it's not possible to highlight union types cleanly with our current scheme) so that we can land the other changes in the query? |
@maxbrunsfeld Would it be acceptable to reduce the depth to 3? ; Union type X | Y (up to 3 types)
(type
(binary_operator
left: [
(binary_operator
left: (_) @type
right: (_) @type
) @type
(_) @type
]
right: (_) @type
) @type
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
I removed the union type highlighting until we can come up with a better solution.
Release Notes:
Before
After
Why manual recursion?
Unable to highlight when simple structures appear before complex structures, example:
Because complex structures are parsed as
subscript
rather thangeneric_type
by tree-sitter in this case ☹Related:
t | None
is incorrect #14715