Open matanlurey opened 5 months ago
It's not the cascade, its the embedded }
.
You can see it from:
void main() {
var s = "${foo([
"a",
{},
])}";
}
The same issue happens here, and it goes away if you change {},
to // {},
.
It probably only confuses the highlighter, which in VSCode is (I think) uses a separate grammar, and is not using the analyzer.
It probably only confuses the highlighter, which in VSCode is (I think) uses a separate grammar, and is not using the analyzer.
VS Code actually uses both! It uses the textmate grammar (from this repo) initially - VS Code itself parses that and applies it. This gives very fast (but not entirely accurate) highlighting. And then it asynchronously asks the server for "semantic tokens" that get laid over the top (and this is why you may see the colours change shortly after opening a file).
Ideally these implementations would be very close, but in practice the textmate grammar is way simpler and often leaves things uncoloured for the semantic tokens to pick up. Interpolated expressions is one place that it doesn't work too well, although your example looks particularly bad. My guess is that it's because it doesn't handle the }
(that is not the end of the interpolated expression) well.
I'll see if I can improve things.
Actually, I'm not really sure I understand what the issue is. Here's what I see for both semantic tokens (left) and textmate grammar (right).
There's definitely something a little weird about textmate grammar because some parts of the expressions are coloured but mostly it's just treated as a string (probably we should treat the whole thing as a string, because I don't know if we can parse the code in the expression reliably in a textmate grammar). The closing characters are coloured like the opening equivalents though.
The semantic tokens (left) looks similar to @matanlurey's... The ])}
are also coloured the same as their matching opening characters. There's some different in our themes (I'm using VS Code's Dark+ which seems to have more colours showing), but the string literal parts are red/brown and the dollar/braces/brackets are consistently white.
@matanlurey can you confirm what you're expected to see (and also what theme you're using in VS Code? It's not clear to me if your screenshot was directly from VS Code as it looked prettier than just a screenshot of the editor!).
The following code does successfully execute, and gets highlighting, but depending on the tool (VSCode, Dartpad, etc) the syntax highlighting is off.
Example in VSCode, the trailing
])};',
all look like they are in a string, but they are within${...}
blocks.Dartpad looks worse (even more of the expression is highlighted as a string):