-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
highlights: rust: adjust enum variant recognition #8957
highlights: rust: adjust enum variant recognition #8957
Conversation
So, the reason why I settled on highlighting these as match x {
// Can either be a struct or an enum with named fields
Foo { a, b, c } => {}
// Can either be a tuple struct or an enum with fields
Bar(a, b, c)
} |
You're right that there's ambiguity, and I see these ways out of it:
I was originally aiming for (2), but (1) would be a lot more robust and more concise to implement, and I think I'd still be happy with a theme based on that :) so I'll give it a go. |
2f79a26
to
a756980
Compare
I don't feel like this is quite the right away to approach this because now it creates further ambiguity between enums and structs outside of pattern matching. I think the most correct way to address this is to have I have been meaning to get to it, but life has been busy. But, it should fix your issues with the inconsistent highlighting once I or someone else continues that work. This PR, if merged, would likely need to be at least partially reverted in that case for proper token tracking. |
runtime/queries/rust/highlights.scm
Outdated
@@ -40,7 +40,7 @@ | |||
; --- | |||
|
|||
(self) @variable.builtin | |||
(enum_variant (identifier) @type.enum.variant) | |||
(enum_variant (identifier) @constructor) |
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.
Except for this change, I am fine with the rest of the PR (since it is technically used in the form of constructors) as long as these changes are tracked to be possibly at least partially reverted once semantic highlighting is implemented. I don't know what the other maintainers think though.
Are you still interested in this PR? The comment before my last one may have given the idea I was rejecting the change all together, which is not the case. |
Enum variants and (tuple) structs are indistinguishable in general, so we mark any PascalCase pattern or expression as a "constructor", which covers all three.
a756980
to
e0fcd8a
Compare
Thanks for the poke, I had just forgotten :) |
Enum variants and (tuple) structs are indistinguishable in general, so we mark any PascalCase pattern or expression as a "constructor", which covers all three.
Enum variants and (tuple) structs are indistinguishable in general, so we mark any PascalCase pattern or expression as a "constructor", which covers all three.
Enum variants and (tuple) structs are indistinguishable in general, so we mark any PascalCase pattern or expression as a "constructor", which covers all three.
Enum variants and (tuple) structs are indistinguishable in general, so we mark any PascalCase pattern or expression as a "constructor", which covers all three.
Enum variants and (tuple) structs are indistinguishable in general, so we mark any PascalCase pattern or expression as a "constructor", which covers all three.
Now, enum variants with no arguments are recognised:
and have been tested to not be falsely recognised:
but still aren't recognised in the absence of a field access, method call or match arm because I think we'd need to put a
PascalCase::PascalCase
rule for that everywhere where expressions can appear (to rule out unit structs) which is likely possible but definitely annoying.