Skip to content

Semantic colors don't match other languages #4335

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
georgewfraser opened this issue May 6, 2020 · 9 comments
Closed

Semantic colors don't match other languages #4335

georgewfraser opened this issue May 6, 2020 · 9 comments

Comments

@georgewfraser
Copy link
Contributor

Semantic coloring is a huge improvement over the built-in textmate colors, especially for a tricky-to-color language like rust. But, the colors that are applied by rust-analyzer seem to contradict the color theme. Here is VSCode syntax coloring with semantic coloring off:

Screen Shot 2020-05-05 at 10 19 52 PM

Here it is with semantic coloring on:

Screen Shot 2020-05-05 at 10 18 14 PM

We can see a couple of issues. First, all keywords are purple. This contradicts other VSCode languages, like typescript, where only some keywords (for example if) are purple, and most keywords are blue. Type names, which are all green in other languages, are inconsistent: struct names are blue (the color of keywords in other languages) but enum names are green (as expected).

I'd be happy to work on changing the implementation to better match the coloring of other languages, but first I'd like to understand if this is intended behavior.

@matklad
Copy link
Member

matklad commented May 6, 2020

For keywords, see microsoft/vscode#94367. For enums and structs, we emit specific tags for types: enum for enum, struct for struct, etc. It's up to the color theme to color or not color them.

Other language "work" because they rely on regex-based based textmate scopes much more than rust.

Closing, as I belive this should be fixed in the color theme and not on our side.

@matklad matklad closed this as completed May 6, 2020
@matklad
Copy link
Member

matklad commented May 6, 2020

Though, re-reading 94367, it seems like we can do better for keywords: #4353

@georgewfraser
Copy link
Contributor Author

Help me understand---is it your view that, in the default Dark+ color theme, coloring struct type names like keywords is correct behavior? Or that it's a bug on the VSCode side? Or something else?

@georgewfraser
Copy link
Contributor Author

This contradicts the behavior of, for example, the C++ extension, which colors struct type names like other type names:

Screen Shot 2020-05-06 at 10 12 11 AM

@matklad
Copy link
Member

matklad commented May 6, 2020

This contradicts the behavior of, for example, the C++ extension

What semantic token type does C++ give for structs?

I believe we correctly flag it as struct and declaration:

image

@georgewfraser
Copy link
Contributor Author

The VSCode C++ extension implemented "enhanced colorization" before VSCode defined a colorization API. It bypasses the colorization API and directly colors the tokens. So, it doesn't specify a semantic token type. However, it colors struct names the same as other type names:

Screen Shot 2020-05-06 at 10 12 11 AM

Having dug into this more, it's clear to me that this is a mistake in VSCode's default mappings for semantic tokens: microsoft/vscode#97162

If they don't fix it, the solution is to simply define a rust-specific mapping from the semantic token type struct to the textmate scope entity.name.type.struct. The default mapping they currently have in place, storage.type.struct, is clearly intended for the struct keyword, not struct type names: https://macromates.com/manual/en/language_grammars

@matklad
Copy link
Member

matklad commented May 7, 2020

Oh, thanks for digging this up, fascinating find! I guess, we can paper over this by overriding the name on our side, let me cook up a PR... done, #4365.

@georgewfraser
Copy link
Contributor Author

Syntax coloring is a small obsession of mine 😄 There are a couple other optimizations that could be done to improve client-side performance and user-experience of semantic coloring. I'm working on a PR.

@georgewfraser
Copy link
Contributor Author

Here it is: #4383

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

No branches or pull requests

2 participants