skip to Main Content

I’m trying to change the syntax highlighting for punctuation in rust within vscode, but it doesnt seem to work for semicolons, colons, angle-brackets and brackets.

I noticed that even setting "*": "#660066" doesnt highlight those punctuations.
Could there be a problem with rust-analyzer then?

My current settings.json:

{
    "rust-analyzer.linkedProjects": [
        "./Cargo.toml"
    ],
    "editor.semanticTokenColorCustomizations": {
        "[Dracula]": {
            "enabled": true,
            "rules": {
                // "macro": "#fa7f38",
                // "*": "#660066", // no effect on ';',':','<>','()','[]'
                "attribute": "#fa7f38",
                "attribute.bracket": "#fa7f38",

                // "builtinAttribute": "#fa7f38",
                "attributeBracket": "#fa7f38",
                "generic": "#fa7f38",- // no effect on ';',':','<>','()','[]'
                "bracket": "#fa7f38",
                // "unresolvedReference": "#fa7f38",

                "enumMember": "#cc9900", // works!
                "namespace": "#99ccff", // works!

                // Punctutation
                "parenthesis": "#660066", // no effect on ';',':','<>','()','[]'
                "brace": "#660066", // no effect on ';',':','<>','()','[]'
                "colon": "#66ff33" // no effect on ';',':','<>','()','[]'
            }
        }
    }
}

Same goes for brackets [] in attributes like #[cfg(test)].

What I have tried so far:

  • Reopening+Reloading vscode
  • reinstalling rust-analyzer
  • reopening opened tabs in vscode

Does anyone know how to make it work?

References:
rust-analyzer syntax highlighting,
settings.json from reddit user

2

Answers


  1. You will need to enable the following setting rust-analyzer.semanticHighlighting.punctuation.enable, otherwise rust-analyzer does not emit semantic highlighting tokens for punctuations

    Login or Signup to reply.
  2. Put the following in your settings.json file:

    "rust-analyzer.semanticHighlighting.punctuation.enable": true
    

    The setting’s description:

    Use semantic tokens for punctuations.

    When disabled, rust-analyzer will emit semantic tokens only for punctuation tokens when they are tagged with modifiers or have a special role.

    I assume this was implemented for Add semantic token modifiers for punctuation #6152.

    See also the rust-analyzer.semanticHighlighting.punctuation.separate.macro.bang setting, which makes Rust Analyzer emit a punctuation semantic token for the ! in in macro calls, and rust-analyzer.semanticHighlighting.punctuation.specialization.enable if you want to make Rust Analyzer emit specialized semantic token types for punctuation instead of generic semantic token types.

    At the time of this writing, the default value for all the above settings is false.

    You can find a list of semantic token types defined by the Rust Analyzer extensions in its package.json file.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search