Skip to content

Highlight variable definitions and constant names #373

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

Closed
wants to merge 1 commit into from
Closed

Highlight variable definitions and constant names #373

wants to merge 1 commit into from

Conversation

lunacookies
Copy link

The regexes I’ve used are definitely not perfect, I just quickly slapped them together. Also, constants that begin with a number are not currently highlighted.

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @da-x (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

Copy link
Member

@chris-morgan chris-morgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constants that begin with a number are not currently highlighted.

I’m not sure what you’re meaning—if you mean “the form of identifier that is conventionally used for constants and statics”, then there’s no such thing as one beginning with a number.

@@ -64,6 +64,8 @@ syn match rustExternCrateString /".*"\_s*as/ contained nextgroup=rustIdentifie
syn keyword rustObsoleteExternMod mod contained nextgroup=rustIdentifier skipwhite skipempty

syn match rustIdentifier contains=rustIdentifierPrime "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
syn match rustIdentifier "\v((let|static|const) (ref )?(mut )?)@<=[a-z_]+"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is insufficient: e.g. let Foo(bar) = baz;, these things are patterns, not identifiers. Also there are three other constructs that can introduce new bindings (match branches, function arguments, closure arguments). In general, I don’t like things that make it work sometimes but not always. I don’t think a good solution exists, when using a regular expression parser. You could make it highlight identifiers inside a pattern in each of these cases, but it’d slow things down a lot, and I don’t think that people actually care so very much about the precise highlighting, but they do about the performance of the highlighter. (Do take what I say with a grain of salt, however: I’m biased towards simple highlighting, and have Identifier cleared.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a good start for tuple destructuring:

syn match rustIdentifier "\v((let|static|const) (ref )?(mut )?)@<=([a-z_]+|\((\w+(, )?)+\))"

It currently matches the parentheses and commas as well though.

The following works for simple cases (i.e. no destructuring) with for loops:

syn match rustIdentifier "\v(for (&)?)@<=\w+"

@lunacookies
Copy link
Author

you mean “the form of identifier that is conventionally used for constants and statics”

Yep, correct.

then there’s no such thing as one beginning with a number

Cool, I wasn’t sure exactly where to look for the answer to something like this.

@Iron-E Iron-E mentioned this pull request Mar 10, 2021
1 task
@lunacookies lunacookies closed this by deleting the head repository Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants