Stream: t-compiler/wg-rls-2.0

Topic: More missing syntax highlights


Kirill Bulatov (May 13 2020 at 07:21, on Zulip):

image.png

Looks like we don't highlight macro imports at all.

woody77 (May 13 2020 at 16:29, on Zulip):

I think that this is a theme issue. You're using "Default Dark+" on VSCode, correct? If so, adding these to your settings.json will give some more highlighting:

 "editor.semanticTokenColorCustomizations": {
        "enabled": true,

        "rules": {
            // All-themes colors
            "unresolvedReference": {
               "foreground": "#c93f3f",
               "fontStyle": "bold"
            } ,
            "*.mutable": {
                "fontStyle": "underline"
            },
        },

        "[Default Dark+]": {
            "enabled": true,
            "rules":{
                "macro": "#4EADE5",
                "member": "#9876AA",
                "namespace": "#A9B7C6",
            },
        },

The full supported list is:
https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide#semantic-token-classification
and then rust-analyzer adds:
https://github.com/rust-analyzer/rust-analyzer/blob/eb892d707c379eff514df9c2a6b2203f38874b14/editors/code/package.json#L537-L587

Kirill Bulatov (May 13 2020 at 18:47, on Zulip):

Thank you for the config example.

Indeed, I use the default theme, yet the actual thing I try to understand is whether there's a way to avoid extra highlighting configuration at all.

What I want to achieve, is the highlighting that "just works"™ for any correct Rust code, which was the case for the old highlighting RA had used before and which is the case for intellij-rust.
I think this way we will avoid a lot of confusion, especially for the newbies and recent VS Code switchers that do not know about those settings. Some of them will come and ask the similar questions I do now.

Is it so that the requried semantic definitions are missing in the Default Dark+?
If it's a matter of a few lines to add, should we rather upstream it there?

Kirill Bulatov (May 13 2020 at 18:50, on Zulip):

Speaking of the hashmap macro in particular, what I find very fishy is that we fail to highlight it in the import yet we're fine with highlighting it in the code:

Screenshot-2020-05-13-at-21.46.48.png

It looks like the same token type is assigned to both the import and the usage, yet the former is not highlighted and the latter is.
Can that be an actual bug?

woody77 (May 13 2020 at 21:15, on Zulip):

The problem you're running into is the default themes (not RA). IntelliJ, for instance, has much more fine-grained theming by default).

In the examples you linked, the formatting is coming from the different TextMate rules. There isn't any matching rule for the semantic type "macro". When semantic highlighting is enabled, and the theme uses it, the inspect data reflects that:
Screen-Shot-2020-05-13-at-2.13.08-PM.png

The textmate formatting is crossed out, and the formats are taken from the semantic rules (note that it matches the color in the semantic color customizations that I gave in the example above).

Kirill Bulatov (May 14 2020 at 07:47, on Zulip):

Ah, so upstream changes then.
Thank you for explaining!

Jeremy Kolb (May 14 2020 at 12:42, on Zulip):

Keep in mind that themes need to explicitly opt in to semantic highlighting as well.

George Fraser (May 14 2020 at 21:33, on Zulip):

Kiril we've done a bunch of work recently to try to make syntax work better in it's default configuration. Coloring of macros as "function-like things" should work out of the box. Can you submit a bug with a complete example and tag me please? I'm @georgewfraser on github.

woody77 (May 14 2020 at 23:38, on Zulip):

George Fraser it looks like the fallback textmate scope for the import is just "source.rust", so it looks like the semantic fallback scope isn't being setup to match that of where it's used ("entity.name.function.macro.rust").

Kirill Bulatov (May 15 2020 at 08:52, on Zulip):

Thanks George, I've created one: https://github.com/rust-analyzer/rust-analyzer/issues/4462 and tagged you.

Last update: Sep 22 2020 at 02:00UTC