Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions crates/languages/src/python/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,6 +1,59 @@
(parameter (identifier) @variable)
(attribute attribute: (identifier) @property)
(type (identifier) @type)
(generic_type (identifier) @type)

; Union type X | Y (up to 8 types)
(type
Copy link
Member

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?

Copy link
Collaborator

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.

(binary_operator
left: [
(binary_operator
left: [
(binary_operator
left: [
(binary_operator
left: [
(binary_operator
left: [
(binary_operator
left: [
(binary_operator
left: (_) @type
right: (_) @type
) @type
(_) @type
]
right: (_) @type
) @type
(_) @type
]
right: (_) @type
) @type
(_) @type
]
right: (_) @type
) @type
(_) @type
]
right: (_) @type
) @type
(_) @type
]
right: (_) @type
) @type
(_) @type
]
right: (_) @type
) @type
)

; Type alias
(type_alias_statement "type" @keyword)

; TypeVar with constraints in type parameters
(type
(tuple (identifier) @type)
)

; Module imports

Expand Down
Loading