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
Theme loading and "editor.tokenColorCustomizations" support. #2061
Conversation
Hm, can with remove our own settings completely in favor of TextMate definitions? I'd rather have one way to config the coloring, and I agree that theme files are better for this. If the existing rust tm grammar does not contain tags that we need (like mutable variabels), should we ship our own (Note: I haven't looked at the grammar files for VS Code at all, so I might be suggesting something stupid here) |
@matklad Sure!
My suggestion is to work within the existing scopes for those that are very Rust specific. decoration('keyword.unsafe'),
decoration('builtin'),
decoration('macro'),
decoration('variable.mut', 'underline'), Surely there's has to be a decent compromise for highlighting them with existing scopes. I'm not 100% what |
…proach to error handling.
@matklad I actually thought of a plan forward here so you can abandon the old settings. So the issue is, some of the scopes aren't part of the general grammars. Not to mention many themes won't bother supplying styling for them. Something like So I was thinking of a mapper. "rust-analyzer.themingScopes" : {
"keyword.unsafe" : "invalid.illegal",
"macro" : "meta",
"variable.mut" : "variable",
"builtin" : "support.type"
} I am sure there are better scopes to map them to, but this is a start at least to get RA to work with most of the supplied themes on the VSCode extension marketplace. |
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.
LGTM!
Let's also add a short note here about how to configure colors now.
Sure, but I wasn't... done. :) Edit: Do'h, forgot about the readme. I thought I'd updated it once a decision has been made on how to move forward. |
Hm, I think this can backfire. Like, something like |
@matklad That was just an example. It doesn't have to backfire unless the user wants to.
I agree that keeping the existing scopes is better, that's why I didn't suggest to change their names at all. Edit: This together with |
The important thing here is that we support constructs that exist only in Rust, and not in other languages. In particular we should man |
@matklad Yeah, and with the mapper, it can fallback to But that's a bit more work with supplying a grammar bundle. |
So the plan I had in mind:
The last portion would let RA work with This reasoning comes from the fact that custom scopes are usually not implemented by themes. So what use is there to have a Let the user define how a Another PR later for custom grammars would let Letting the user decide which theme they want and allow them to tweak for Rust is a better approach. |
SGTM, although I still have a feeling that it probably makes sense to just skip step 2. |
@matklad Maybe I'm the one missing something here. But if you skip 2 you will be leaving
This already happens now as the names are the same, so not really changing anything. I wasn't talking about mapping everything - just the ones that were custom. This also makes the config portion easier to reason about from user PoV. |
Hm, yeah, convinced that the mapping is a nice intermediate step! Sorry for the back and forth here :) |
Bit off-topic, but this tree-sitter demo is pretty cool: https://twitter.com/oni_vim/status/1167475446222479361. |
@seivan @matklad This looks really nice! Thanks for putting an effort into this. I was just playing with RA's syntax highlighting engine this weekend when I saw this PR! Currently I have something like this (in a small fork I'm playing with), this is from the html based tests. Just some thoughts - some of those are relevant to the highlighting engine in
If any help is necessary on the rust end of things (matching different categories for AST entities) I'd be happy to assist :) |
…JSONC. However, there is still an issue where themes could have been defined in JSONC - but so far with testing very few of them actually do. The issue was in loading packages and now we're letting VSCode tackle that. Fix: #2061 (comment)
The issue is working with existing themes that do not supply any theming for the Rust specific scopes.
I'd love some help on what good sane defaults could be mapped to the Rust specific scopes. 'keyword.unsafe'
'builtin'
'macro'
'variable.mut' These are the scopes currently not targeted by either user supplied themes or So what's missing today is
Eventually in a different PR also supply a grammar bundle for future Rust specific themes. |
From reading that document, I think you swapped the meaning of meta and entity:
|
@bjorn3 I believe my reasoning is correct. so if we have:
From the explanation - We would have The same reasoning goes for stuff that's inside macros and so forth. |
IMO some sane defaults (unrelated to rust) would be: |
@lnicola Looks like latest master fixed the CI stuff. |
In Rust it is indeed idiomatic to chain iterator methods (I'm not saying that it's not idiomatic in JS/TS, but it's the first time I see it), but it's used with collections. The moral equivalent would be |
… into feature/themes
… into feature/themes
… into feature/themes
… into feature/themes
I finally gave this a try with some of the default themes. There are some differences from the current highlighting, but nothing too bad -- most are on keywords. It didn't bite my cat or make my laptop catch fire. See the attached archive for some screenshots. To summarize my previous feedback:
The last two points above can be done in a future PR, since this one has been idling here for a long time. I think we can merge this now (or soon-ish) and try to fine-tune it more in the future. |
Thanks for the review, @lnicola ! Yeah, let's merge this then! bors r=lnicola |
2061: Theme loading and "editor.tokenColorCustomizations" support. r=lnicola a=seivan Fixes: [Issue#1294](#1294 (comment)) TODO: - [x] Load themes - [x] Load existing `ralsp`-prefixed overrides from `"workbench.colorCustomizations"`. - [x] Load overrides from `"editor.tokenColorCustomizations.textMateRules"`. - [x] Use RA tags to load `vscode.DecorationRenderOptions` (colors) from theme & overrides. - [x] Map RA tags to common TextMate scopes before loading colors. - [x] Add default scope mappings in extension. - [x] Cache mappings between settings updates. - [x] Add scope mapping configuration manifest in `package.json` - [x] Load configurable scope mappings from settings. - [x] Load JSON Scheme for text mate scope rules in settings. - [x] Update [Readme](https://github.com/seivan/rust-analyzer/blob/feature/themes/docs/user/README.md#settings). Borrowed the theme loading (`scopes.ts`) from `Tree Sitter` with some modifications to reading `"editor.tokenColorCustomizations"` for merging with loaded themes and had to remove the async portions to be able to load it from settings updates. ~Just a PoC and an idea I toyed around with a lot of room for improvement.~ For starters, certain keywords aren't part of the standard TextMate grammar, so it still reads colors from the `ralsp` prefixed values in `"workbench.colorCustomizations"`. But I think there's more value making the extension work with existing themes by maping some of the decoration tags to existing key or keys. <img width="453" alt="Screenshot 2019-11-09 at 17 43 18" src="https://user-images.githubusercontent.com/55424/68531968-71b4e380-0318-11ea-924e-cdbb8d5eae06.png"> <img width="780" alt="Screenshot 2019-11-09 at 17 41 45" src="https://user-images.githubusercontent.com/55424/68531950-4b8f4380-0318-11ea-8f85-24a84efaf23b.png"> <img width="468" alt="Screenshot 2019-11-09 at 17 40 29" src="https://user-images.githubusercontent.com/55424/68531952-51852480-0318-11ea-800a-6ae9215f5368.png"> These will merge with the default ones coming with the extension, so you don't have to implement all of them and works well with overrides defined in settings. ```jsonc "editor.tokenColorCustomizations": { "textMateRules": [ { "scope": "keyword", "settings": { "fontStyle": "bold", } }, ] }, ``` Edit: The idea is to work with 90% of the themes out there by working within existing scopes available that are generally styled. It's not to say I want to erase the custom Rust scopes - those should still remain and eventually worked into a custom grammar bundle for Rust specific themes that target those, I just want to make it work with generic themes offered on the market place for now. A custom grammar bundle and themes for Rust specific scopes is out of... scope for this PR. We'll make another round to tackle those issues. Current fallbacks implemented ```typescript [ 'comment', [ 'comment', 'comment.block', 'comment.line', 'comment.block.documentation' ] ], ['string', ['string']], ['keyword', ['keyword']], ['keyword.control', ['keyword.control', 'keyword', 'keyword.other']], [ 'keyword.unsafe', ['storage.modifier', 'keyword.other', 'keyword.control', 'keyword'] ], ['function', ['entity.name.function']], ['parameter', ['variable.parameter']], ['constant', ['constant', 'variable']], ['type', ['entity.name.type']], ['builtin', ['variable.language', 'support.type', 'support.type']], ['text', ['string', 'string.quoted', 'string.regexp']], ['attribute', ['keyword']], ['literal', ['string', 'string.quoted', 'string.regexp']], ['macro', ['support.other']], ['variable', ['variable']], ['variable.mut', ['variable', 'storage.modifier']], [ 'field', [ 'variable.object.property', 'meta.field.declaration', 'meta.definition.property', 'variable.other' ] ], ['module', ['entity.name.section', 'entity.other']] ``` Co-authored-by: Seivan Heidari <seivan.heidari@icloud.com>
bors r_
…On Wed, 4 Dec 2019 at 13:03, Seivan Heidari ***@***.***> wrote:
@matklad <https://github.com/matklad> @lnicola
<https://github.com/lnicola> Just a moment, I need to address some of the
issues brought up. But I am kinda short on time right now. Please don't
merge just yet. :)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2061>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANB3M2HIY2OJEYRAV2VBATQW6MANANCNFSM4JEVXL6Q>
.
|
bors r- |
Canceled |
2559: Add some granularity to syntax highlighting. r=matklad a=omerbenamram Hi, I wanted to start using `rust-analyzer` a bit more frequently - one of the main blockers for me so far was the highlighting. I just discovered it's possible to override the default colors with `ralsp.<something>` setting without waiting for #2061! However, the current implementation was lumping a bunch of different tokens into `type` and `literal`. The golden standard IMO is what Clion is currently doing (and is my current daily driver for rust). Clion allows users to control the coloring for specific literal kinds, and the default is to distinguish between them (numerics get a different color from strings, and special colors for bytestrings). I've also splitted the builtin types, which are also allowed to be highlighted speratly. My goal is to match the default experience I'm getting with clion. The only blockers now I think is that `rust-analyzer` doesn't corrently infer types in some situations, so the highlighting information is incorrect in those cases. This is what it looks like so far (with colors overriden to match clion's theme): ![image](https://user-images.githubusercontent.com/2467993/70848219-ccd97900-1e76-11ea-89e1-2e467cfcc9fb.png) If there are any other changes you feel is necessary let me know. I did leave the default colors to match the current behavior, since I'm not familiar with the colors for this theme, I added some random (different) colors in the test to check that it indeed was working. Co-authored-by: Omer Ben-Amram <omerbenamram@gmail.com>
@matklad Sorry for the long delay, I've been out of commission but I'm back and merging in master and dealing with the last comments! Just wanted to update you. |
Also see #604 (comment). Looks like there's some native support in the LSP for this already? |
@matklad I looked at that - unless I have misunderstood completely (pretty big chance) this means that
However it would still need Either way, I am done with the PR - fixed the review comments with this exception Merry Christmas btw. |
Let's merge this and fix any fallout separatelly! bors r+ |
2061: Theme loading and "editor.tokenColorCustomizations" support. r=matklad a=seivan Fixes: [Issue#1294](#1294 (comment)) TODO: - [x] Load themes - [x] Load existing `ralsp`-prefixed overrides from `"workbench.colorCustomizations"`. - [x] Load overrides from `"editor.tokenColorCustomizations.textMateRules"`. - [x] Use RA tags to load `vscode.DecorationRenderOptions` (colors) from theme & overrides. - [x] Map RA tags to common TextMate scopes before loading colors. - [x] Add default scope mappings in extension. - [x] Cache mappings between settings updates. - [x] Add scope mapping configuration manifest in `package.json` - [x] Load configurable scope mappings from settings. - [x] Load JSON Scheme for text mate scope rules in settings. - [x] Update [Readme](https://github.com/seivan/rust-analyzer/blob/feature/themes/docs/user/README.md#settings). Borrowed the theme loading (`scopes.ts`) from `Tree Sitter` with some modifications to reading `"editor.tokenColorCustomizations"` for merging with loaded themes and had to remove the async portions to be able to load it from settings updates. ~Just a PoC and an idea I toyed around with a lot of room for improvement.~ For starters, certain keywords aren't part of the standard TextMate grammar, so it still reads colors from the `ralsp` prefixed values in `"workbench.colorCustomizations"`. But I think there's more value making the extension work with existing themes by maping some of the decoration tags to existing key or keys. <img width="453" alt="Screenshot 2019-11-09 at 17 43 18" src="https://user-images.githubusercontent.com/55424/68531968-71b4e380-0318-11ea-924e-cdbb8d5eae06.png"> <img width="780" alt="Screenshot 2019-11-09 at 17 41 45" src="https://user-images.githubusercontent.com/55424/68531950-4b8f4380-0318-11ea-8f85-24a84efaf23b.png"> <img width="468" alt="Screenshot 2019-11-09 at 17 40 29" src="https://user-images.githubusercontent.com/55424/68531952-51852480-0318-11ea-800a-6ae9215f5368.png"> These will merge with the default ones coming with the extension, so you don't have to implement all of them and works well with overrides defined in settings. ```jsonc "editor.tokenColorCustomizations": { "textMateRules": [ { "scope": "keyword", "settings": { "fontStyle": "bold", } }, ] }, ``` Edit: The idea is to work with 90% of the themes out there by working within existing scopes available that are generally styled. It's not to say I want to erase the custom Rust scopes - those should still remain and eventually worked into a custom grammar bundle for Rust specific themes that target those, I just want to make it work with generic themes offered on the market place for now. A custom grammar bundle and themes for Rust specific scopes is out of... scope for this PR. We'll make another round to tackle those issues. Current fallbacks implemented ```typescript [ 'comment', [ 'comment', 'comment.block', 'comment.line', 'comment.block.documentation' ] ], ['string', ['string']], ['keyword', ['keyword']], ['keyword.control', ['keyword.control', 'keyword', 'keyword.other']], [ 'keyword.unsafe', ['storage.modifier', 'keyword.other', 'keyword.control', 'keyword'] ], ['function', ['entity.name.function']], ['parameter', ['variable.parameter']], ['constant', ['constant', 'variable']], ['type', ['entity.name.type']], ['builtin', ['variable.language', 'support.type', 'support.type']], ['text', ['string', 'string.quoted', 'string.regexp']], ['attribute', ['keyword']], ['literal', ['string', 'string.quoted', 'string.regexp']], ['macro', ['support.other']], ['variable', ['variable']], ['variable.mut', ['variable', 'storage.modifier']], [ 'field', [ 'variable.object.property', 'meta.field.declaration', 'meta.definition.property', 'variable.other' ] ], ['module', ['entity.name.section', 'entity.other']] ``` Co-authored-by: Seivan Heidari <seivan.heidari@icloud.com>
Build succeeded
|
…JSONC. However, there is still an issue where themes could have been defined in JSONC - but so far with testing very few of them actually do. The issue was in loading packages and now we're letting VSCode tackle that. Fix: rust-lang/rust-analyzer#2061 (comment)
Fixes: Issue#1294
TODO:
ralsp
-prefixed overrides from"workbench.colorCustomizations"
."editor.tokenColorCustomizations.textMateRules"
.vscode.DecorationRenderOptions
(colors) from theme & overrides.package.json
Borrowed the theme loading (
scopes.ts
) fromTree Sitter
with some modifications to reading"editor.tokenColorCustomizations"
for merging with loaded themes and had to remove the async portions to be able to load it from settings updates.Just a PoC and an idea I toyed around with a lot of room for improvement.For starters, certain keywords aren't part of the standard TextMate grammar, so it still reads colors from the
ralsp
prefixed values in"workbench.colorCustomizations"
.But I think there's more value making the extension work with existing themes by maping some of the decoration tags to existing key or keys.
These will merge with the default ones coming with the extension, so you don't have to implement all of them and works well with overrides defined in settings.
Edit: The idea is to work with 90% of the themes out there by working within existing scopes available that are generally styled. It's not to say I want to erase the custom Rust scopes - those should still remain and eventually worked into a custom grammar bundle for Rust specific themes that target those, I just want to make it work with generic themes offered on the market place for now.
A custom grammar bundle and themes for Rust specific scopes is out of... scope for this PR.
We'll make another round to tackle those issues.
Current fallbacks implemented