For example, here I am expecting sum
and FILENAME
to be in different colors than the rest of the string literal:
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:
- An example for my expectation can be seen in @Finomnis ‘s answer.
- As noted by people in the comments, expressions such as
{3+5}
are not supported in formatted strings in Rust.
3
Answers
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.I’m running VSCode 1.74.2 and rust-analyzer v0.3.1394, and it works without a problem:
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:
It seems like it’s theme dependent:
Dark+ (default dark):
Noctis Obscuro:
Edit: it’s a theme setting: vscode editor-semantic-highlighting
settings.json: