Closed Arcitec closed 4 years ago
By the way, Rust support may be as easy as this change, which is what I personally added to my settings.json for now:
"[Monokai Pro]": {
"textMateRules": [
{
"scope":"storage.type.rust",
"settings": {
"foreground": "#ff6188"
}
}
]
},
This change colors the Rust struct
and impl
keywords the same as fn
and other keywords.
But will still need to go through the whole language and make sure Monokai Pro really looks nice with all of it... And to consider the macro vs function syntax color as well...
Actually... I just compared Rust to JS and Python and there's actually need for a bigger overhaul than I thought. Monokai is supposed to color function, fn, def, let, etc in light blue. And classes in light blue, and functions in green, etc etc. The Rust theme violates all of that by using red for most but not all keywords, etc... It needs a big overhaul to make it consistent with all other languages Monokai actually supports.
Here's a revised temporary workaround which colors tokens a bit more consistently. It will be a good start but more work needs to be done, and I can't do any more. I've spent an hour on this so far. I am new to Rust, just starting to learn the language, I don't know all keywords yet (and the syntax highlighting example file above is mostly complete but still lacks some features for sure), and I don't have the energy to go through and try to guess what colors Monokai Pro intends to use in the spirit of the theme. Here's my temporary work:
"[Monokai Pro]": {
// TODO: Remove when https://github.com/Monokai/monokai-pro-vscode/issues/160 is fixed.
"textMateRules": [
{
"scope":"keyword.other.fn.rust,keyword.other.rust,keyword.other.unsafe.rust,keyword.other.where.rust,storage.modifier.const.rust,storage.modifier.dyn.rust,storage.modifier.mut.rust,storage.modifier.static.rust,storage.type.rust,storage.type.core.rust,storage.class.std.rust,support.constant.core.rust,entity.name.type.rust",
"settings": {
"foreground": "#78dce8"
}
},
{
"scope":"keyword.control.rust,storage.modifier.visibility.rust,keyword.operator.misc.rust",
"settings": {
"foreground": "#ff6188"
}
},
{
"scope":"meta.type_params.rust", // Important for visual distinction of <> type brackets. Also affects certain type names.
"settings": {
"foreground": "#fcfcfa"
}
},
{
"scope":"storage.modifier.lifetime.rust,entity.name.lifetime.rust", // Makes "&'static" lifetime modifier red.
"settings": {
"foreground": "#ff6188"
}
},
{
"scope":"meta.attribute.rust,variable.language.rust", // The "variable.language.rust" is "self" keyword. Note that "super" keyword is "keyword.other.rust" which is used by tons of other keywords.
"settings": {
"foreground": "#c1c0c0" // Same light gray color as "self" keyword.
}
},
]
},
I went through with JS, Python and CPP files as reference for what colors various keywords should have. One limiting factor is that Rust's syntax highlighter isn't granular enough for true control, so there will be some inconsistencies. And it remains to be seen how these colors feel in actual use.
Also, I've reached the conclusion that I think Rust macros should indeed be the same color as functions.
PS: I used a keyword reference site: https://doc.rust-lang.org/reference/keywords.html ... and painstakingly added real examples for all of those keywords to my syntax highlighting example file in my 1st post. I am not sure this gives 100% language coverage, but it sure as hell will be close to 100%... :-)
By the way, even though the syntax rules I ended up with (the previous post above) follow the Monokai style of light blue for functions and types, red for if-else, etc, I still think that Dracula Official has better colors for Rust, because the Monokai result tends to have overly monotone blue lines, whereas Dracula has split things up a bit to get alternating colors, even though that does break consistency in other places. I suggest analyzing what Dracula did, and thinking really hard about what to do with Monokai.
Edit: I did it... have spent a total of two hours tweaking everything now, and have probably gained 100% language coverage now... With these changes, the readability is perfect. So, these are my final colors. They break the Monokai "blue keywords" consistency to gain much better Rust code readability, with the same color patterns as Dracula. The code below is my colors from above PLUS an extra section which overrides some colors back to red instead. You can see for yourself that it's much more readable. I also marked (and commented out) fn
and unsafe
as potential colors to turn to red, but I really like them as blue for visibility. The comments in the code below explain things...
"[Monokai Pro]": {
// TODO: Remove when https://github.com/Monokai/monokai-pro-vscode/issues/160 is fixed.
"textMateRules": [
{
"scope":"keyword.other.fn.rust,keyword.other.rust,keyword.other.unsafe.rust,keyword.other.where.rust,storage.modifier.const.rust,storage.modifier.dyn.rust,storage.modifier.mut.rust,storage.modifier.static.rust,storage.type.rust,storage.type.core.rust,storage.class.std.rust,support.constant.core.rust,entity.name.type.rust",
"settings": {
"foreground": "#78dce8"
}
},
{
"scope":"keyword.control.rust,storage.modifier.visibility.rust,keyword.operator.misc.rust",
"settings": {
"foreground": "#ff6188"
}
},
{
"scope":"meta.type_params.rust", // Important for visual distinction of <> type brackets. Also affects certain type names.
"settings": {
"foreground": "#fcfcfa"
}
},
{
"scope":"storage.modifier.lifetime.rust,entity.name.lifetime.rust", // Makes "&'static" lifetime modifier red.
"settings": {
"foreground": "#ff6188"
}
},
{
"scope":"meta.attribute.rust,variable.language.rust", // The "variable.language.rust" is "self" keyword. Note that "super" keyword is "keyword.other.rust" which is used by tons of other keywords.
"settings": {
"foreground": "#c1c0c0" // Same light gray color as "self" keyword.
}
},
// Re-adjust some colors to get less Monokai consistency but more contrast a la Dracula theme's Rust highlighting.
{ // Changes all blue colors to red EXCEPT the type-related colors (storage.type.core.rust,storage.class.std.rust,support.constant.core.rust,entity.name.type.rust).
"scope":"storage.type.rust,storage.modifier.const.rust,storage.modifier.dyn.rust,storage.modifier.mut.rust,storage.modifier.static.rust,keyword.other.rust,keyword.other.where.rust",
"settings": {
"foreground": "#ff6188"
}
},
// These two are commented out because I am leaning towards preferring the readability of having blue "fn" and "unsafe" blocks (same color as types) in a sea of red keywords.
// {
// "scope":"keyword.other.fn.rust", // Not decided yet: Should we force functions to red too, or keep them blue (same color as types)? Keeping them blue is less consistent but makes it easier to see functions.
// "settings": {
// "foreground": "#ff6188"
// }
// },
// {
// "scope":"keyword.other.unsafe.rust", // Not decided yet: The "unsafe" keyword has the same dilemma. Blue makes unsafe code stand out. Red is more consistent.
// "settings": {
// "foreground": "#ff6188"
// }
// },
]
},
Thanks for your work, I've added more rust support to 1.1.15 based on some of your suggestions.
Rust is a quickly emerging new language, which is like a very productive, memory-safe version of C. It's fantastic. Sadly monokai's support for it is incomplete, since the Rust language defines many custom text tokens.
Related ticket: #154
Here's a partial example file (not valid code, just meant as a test of syntax and it doesn't include all syntax offered by rust) where you can see that the syntax highlighting has many problems in Monokai Pro.
Examples of problems:
struct
andimpl
keywords are some weird light blue color, instead of being reddish/pinkish likefn
,const
,let
,mut
and other language keywords in Rust (and in other languages that Monokai fully supports).!
) such as theprintln!()
are the same color as regular functions... this may or may not be a problem, but look at the Dracula Official theme, which colors them differently. I am not decided on which approach I prefer. Worth thinking about...