-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Try new Rust grammar #108254
Try new Rust grammar #108254
Conversation
@@ -210,7 +342,29 @@ | |||
}, | |||
{ | |||
"c": "let", |
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.
In other languages, let
is usually scoped as storage.type
. Should that be the case for Rust?
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 think so. Even if not, keyword.control
seems wrong as it doesn't affect control flow.
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.
The new grammer has an issue I am seeing right now:
fn
and use
should not be highlighted as keyword.control
. In my opinion fn
does not not necessarily signify control-flow. The same applies to use
, there is no control-flow.
@@ -154,19 +242,30 @@ | |||
} | |||
}, | |||
{ | |||
"c": "println!", | |||
"t": "source.rust support.function.std.rust", | |||
"c": "println", |
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.
In other languages (and in the old grammar for Rust), print
statements are support.function
should that be the case for Rust too?
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.
In Rust println!
is a macro and not a function. I also think that println!
maybe should be considered a single token and not two tokens (println
and !
)
} | ||
}, | ||
{ | ||
"c": "mut", |
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.
In the old grammar mut
was storage.modifier
, is keyword
more correct?
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.
https://macromates.com/manual/en/language_grammars
- storage — things relating to “storage”.
- modifier — a storage modifier like static, final, abstract, etc.
Should be storage.modifier
I think.
@@ -1,13 +1,13 @@ | |||
[ | |||
{ | |||
"c": "impl", | |||
"t": "source.rust storage.type.rust", | |||
"t": "source.rust keyword.control.rust", |
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.
Not sure what scope this should have, but the new grammar does change the scope it gets.
}, | ||
{ | ||
"c": "struct", | ||
"t": "source.rust keyword.control.rust", |
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.
In other languages, struct
is scoped as storage.type
, and in the old grammar it was also storate.type
. Should it change?
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.
https://macromates.com/manual/en/language_grammars
- storage — things relating to “storage”.
- type — the type of something, class, function, int, var, etc.
Yeah, it should be storage.type
I think.
} | ||
}, | ||
{ | ||
"c": "trait", |
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.
Should this stay storage.type
?
@dustypomerleau I have tried adopting your rust grammar in this PR. We have colorization tests that compare the color and scope of tokens in sample language files. The language files for rust are here: Your grammar definitely colors more tokens and colors some tokens more specifically, which is great. However, there are some tokens that I'm not confident have the correct scope. I left some comments in the output of the colorization tests where the scope doesn't match what I'd expect. As you probably know already, the reason we have some standard scopes that we expect various tokens to be is so that one theme can look good on any language. I am not a rust user, so I'm not 100% certain that the comments I have are relevant, but please take a look and convince me that the scopes are correct (or update your grammar and I'll pull the change into this PR). Once we've addressed the scope differences, I'll bring this grammar into insiders for a month or two. Given the low user count for this grammar currently, I want to make sure that it has plenty of time in insiders so users and find any issues. |
@alexr00 The reason I chose
I'm happy to move some of the keywords into As for |
@dustypomerleau since many of the tokens that get scoped as What you said about macros makes sense to me. Please ping here when you've made the changes you want to make and I'll update again! |
@alexr00 Changes have been pushed. Appreciate your help. |
@alexr00 Pushed an additional commit to fix a highlighting error for raw strings rust-lang/rust-analyzer#6042. |
@dustypomerleau I'll try to get to this this week. Thanks for the updates! |
I was not able to review this again for October. Will address in November. |
@dustypomerleau I am happy with the changes, thanks! I will merge the grammar from https://github.com/dustypomerleau/rust-syntax/ into VS Code and we will see what users think for a month. |
Thanks for your help, @alexr00! For patch updates, should I ping someone or submit my own PR with updated commit hash? We are still finding occasional edge cases since I merged into Rust Analyzer. |
@dustypomerleau if there's an urgent fix in the grammar, please just open an issue and ping me on it. Otherwise, I pick up grammar changes with a script about once per month at the beginning of our milestones. |
and @bjorn3 thanks for the additional feedback! |
The grammar in its current state has some issues, I'd like to get it fixed:
Is it preferred to open a PR here or upstream (https://github.com/dustypomerleau/rust-syntax/)? Also the current situation is quite weird, because we've got this same grammar in multiple places vscode, upstream extension and in rust-analyzer. |
I think vscode doesn't accept any changes to grammars. I think they only periodically pull in updates from the upstream version, which is https://github.com/dustypomerleau/rust-syntax/ in this case. |
@bjorn3 is correct. |
There has been no feedback about this grammar having problems. I will leave it in for the release of 1.52. |
Related to #64488