Skip to content

Format string literal syntax highlighting is broken for escapes and interpolations simultaneously #4138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Veetaha opened this issue Apr 25, 2020 · 9 comments

Comments

@Veetaha
Copy link
Contributor

Veetaha commented Apr 25, 2020

cc #4006, @ltentrup

image

As you can see, the string is bold starting from the escape sequence up until the first placeholder symbol.

This happens only inside of format strings as far as I can tell
image

@ltentrup
Copy link
Contributor

Where does the highlighting for the escape string come from? It is not implemented in https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/syntax_highlighting.rs where the logic for the format specifier is implemented.

@Veetaha
Copy link
Contributor Author

Veetaha commented Apr 25, 2020

Hmm, this is strange, if you take a look with the inspector you won't see where the bold styling comes from... Can't it be vscode bug? Can you reproduce it in your editor?
image

@ltentrup
Copy link
Contributor

I just checked with the latest nightly, there is no escape sequence highlighting on my machine:
Bildschirmfoto 2020-04-28 um 09 25 01
Maybe this is related to another extension or VSCode setting?

@ian-h-chamberlain
Copy link
Contributor

ian-h-chamberlain commented Jun 15, 2020

I have been experiencing I think the same issue, which I thought was caused by some interaction between rust-analyzer and another extension I have installed. However, I can reproduce when rust-analyzer is the only extension enabled as well.

Initial state while window loads and rust-analyzer still starting up looks like this
Screen Shot 2020-06-15 at 18 46 33

This is expected, I think, as the semantic highlight has not been initialized yet?

Then, once it loads and I type a bit, this happens:

recording

It seems like once semantic highlighting starts something changes. Strangely, all the output from the inspector window seems to be unchanged:

Escape before

escape_before

Escape after

escape_after

Format string before

format_before

Format string after

format_after


Let me know if there is additional info I can get you. This appears to be 100% reproducible on window reloads.

Name: rust-analyzer
Id: matklad.rust-analyzer
Description: An alternative rust language server to the RLS
Version: 0.3.206-nightly
Publisher: matklad
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer

VSCode
Version: 1.46.0
Commit: a5d1cc28bb5da32ec67e86cc50f84c67cc690321
Date: 2020-06-10T08:59:06.977Z (5 days ago)
Electron: 7.3.1
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Darwin x64 19.4.0

bors bot added a commit that referenced this issue Jun 17, 2020
4925: Syntax highlighting for escape sequences in strings r=matklad a=ltentrup

I have added a new semantic token type `ESCAPE_SEQUENCE` as the LSP specification does not seem to have an appropriate token type. This may actually be a regression for some users, as the TextMate Rust grammar has a scope `constant.character.escape.rust` which highlights escape sequences (which caused problems with semantic highlighting, see #4138).

Fixes #2604.

Co-authored-by: Leander Tentrup <[email protected]>
@ltentrup
Copy link
Contributor

Does this issue persist in the latest nightly? There is now support for highlighting escape sequences (although it has to be enabled manually)

@ian-h-chamberlain
Copy link
Contributor

@ltentrup yes, it works as expected for me now, thank you! I didn't have to enable anything specific, it seemed to activate alongside the rest of semantic syntax highlighting. Is that expected?

@ltentrup
Copy link
Contributor

No, I did not expect escape sequences to be highlighted as we introduced a custom/non-standard semantic token escapeSequence.
If you do not style escapeSequence manually in your settings.json it should just style as a string.

@ian-h-chamberlain
Copy link
Contributor

ian-h-chamberlain commented Jun 18, 2020

It looks like the escapeSequence allows the default semantic highlighting (looks like constant.character.escape.rust) to kick in, instead of just treating the token as as string?
Compare this inspector output to the one I posted above:
Screen Shot 2020-06-18 at 12 42 07

In any case it now looks like it did before, so I would consider this issue resolved. Thanks again!

@lnicola
Copy link
Member

lnicola commented Jan 26, 2021

Sounds like this was resolved, please shout if there's still something to do here.

@lnicola lnicola closed this as completed Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants