skip to Main Content

For example, here I am expecting sum and FILENAME to be in different colors than the rest of the string literal:

example screenshot

I am using VSCode with rust-analyzer v0.4.1395 (Pre-release).

Seems like Markdown also has this problem:

println!("this is a formatted string with a {variable}, and an expression: {3+5}"); 

edit:

  1. An example for my expectation can be seen in @Finomnis ‘s answer.
  2. As noted by people in the comments, expressions such as {3+5} are not supported in formatted strings in Rust.

3

Answers


  1. This requires semantic information, because not every string literal is a format string, and thus cannot be done by syntactic highlighting.

    rust-analyzer handles this though, with semantic highlighting.

    Besides, full expressions like 3+5 are not supported in format strings.

    Login or Signup to reply.
  2. I’m running VSCode 1.74.2 and rust-analyzer v0.3.1394, and it works without a problem:

    enter image description here

    With rust-analyzer 0.4.1395 (PreRelease), it looks the same to me.

    Note that while rust-analyzer is still loading (spinning circle in the bottom bar), or if rust-analyzer encountered an error (displayed red in the bottom), only the VSCode internal Rust highlighting is enabled, which can not highlight strings syntactically:

    enter image description here

    Login or Signup to reply.
  3. It seems like it’s theme dependent:
    Dark+ (default dark):
    default dark+ theme

    Noctis Obscuro:
    enter image description here

    Edit: it’s a theme setting: vscode editor-semantic-highlighting
    settings.json:

    "editor.semanticTokenColorCustomizations": {
        "[Noctis*]": {
            "enabled": true
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search