Mutability & ownership indicated by colors?

Hey, I wonder, is there a way or a ready to use setting to indicate mutability and ownership of vars in code?

Example: current theme in VS Code:

How it could look like with mutability & ownership indication: refs are purple, mutable refs are redder than that. Mutable vars should look like darker blue.

Is this possible with VS Code?

In my VSCode, rust-analyzer underlines the mutable operations. It looks like the following:

But I don't know which setting controls this feature... Maybe someone else can enlighten us?


Actually, in mine too. I wonder if references can be indicated as well.

Found this in the manual:

You can customize the look of different semantic elements in the source code. For example, mutable bindings are underlined by default and you can override this behavior by adding the following section to your settings.json:

  "editor.semanticTokenColorCustomizations": {
    "rules": {
      "*.mutable": {
        "fontStyle": "", // underline is the default

Interesting, but I can't find anything on what kinds of strings there are, like "parameter", "variable". The doc file only gives one example and gives no links, and searching for semanticTokenColorCustomizations in the repo, I find only that page.

This thread show only some examples and links to color themes, but not keywords.


Custom token types and modifiers

If necessary, extensions can declare new types and modifiers or create sub types of existing types through the semanticTokenTypes and semanticTokenModifiers contribution points in their extension's package.json

And here

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.