You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I love the way string interpolation is highlighted, it makes my day, but with all the JSON I use (from Firebase), I end up with a lot of maps, which don't play well with the interpolation highlighter.
See gif:
This is obviously minor. Point me in the right direction and I might be able to take a swing at it myself.
I did have a go at fixing this but was unable to come up with a regex that would work reliably (see #105 (comment)):
Since JS regex (AFAIK) doesn't have support for counting braces to figure out which closing brace actually matches the expression (consider ${something('with a } in a string'){) I don't think I can properly fix this (though if anyone has ideas, I'm all ears!).
Considering Dart doesn't care what kind of crazy things you do inside of an interpolated string, would it make sense to reduce the regex to just seek out a ${ with a closing }? The analyzer will catch any issues inside of the expression, or if it's not closed properly.
Edit: Oh no, I see the problem. I forget how daunting regex can be sometimes.
Yeah, the problem is making sure that the correct } is detecting. I did think it'd be possible (it's just Dart inside Dart!) but because you're actually inside quotes, it's not the same as just parsing Dart, since quotes will be escaped. I did spend some time on it but couldn't make it work :(
Maybe in future VS Code will let us use dynamic highlight info and then we can swap from the regexes to the three provided by the Analyzer.
Okay, so Dart allows a string inside of the ${ } to use the same quote symbol as the outer string without issue. It seems to me the only character the regex needs to be watchful for are the brackets. The change would at least patch this issue, but I agree, one day the syntax highlighting needs to be re-written.
The change would require "variable.parameter.dart" being removed from Capture Group 3, since any arbitrary statement can be used inside of string interpolation.
Thanks; I'll take a look at this when next working on it :)
Have you checked it with crud like this?
List names = ['John', 'Sophena', 'Henrietta'];
print("${ ((names) {returnnames[(newmath.Random()).nextInt(names.length)]; })(names)} is the most valueable member of our team");
The above example still fails to highlight correctly, for the reason you listed, regex's inability to tell which is the closing bracket. But the change doesn't fail any differently than before.
I think we can consider this fixed with #310. I think there's still room for improvement, but I'm not sure we'll ever get all the way with the regex; we really need Code to implement microsoft/vscode#1967 (go vote for support! :-))
Any update on this? For me, basic nesting like String test = "${(() => 'one ${"two"}')()}"; only highlights the inner most expression. You mentioned the need for microsoft/vscode#1967 which seems to have been implemented now.
@maxwell8888 could you file a new issue about that? With LSP semantic tokens, I would expect (or at least like) for expressions to be coloured reasonably inside strings. The previous limitations were around the textmate grammar and LSP Semantic Tokens hands this off to the server where we don't need to rely on regex to identify these. Thanks!
@DanTup As well as handling nested string interpolation, I'd also like to request the expression to be highlighted with multiple colours in the same way as normal code, whereas at the moment the entire expression is just highlighted with a single colour. Should I include this in the ticket or create a separate one? Thanks
@maxwell8888 I'm not sure how that differs from the earlier comment, though I think one issue for colouring interpolated expressions better is probably sufficient. Thanks!
Activity
DanTup commentedon May 19, 2017
I did have a go at fixing this but was unable to come up with a regex that would work reliably (see #105 (comment)):
DanTup commentedon May 19, 2017
The relevant code if anyone wants to have a go is here:
Dart-Code/syntaxes/dart.json
Line 292 in 252e732
Skylled commentedon May 19, 2017
Considering Dart doesn't care what kind of crazy things you do inside of an interpolated string, would it make sense to reduce the regex to just seek out a
${with a closing}? The analyzer will catch any issues inside of the expression, or if it's not closed properly.Edit: Oh no, I see the problem. I forget how daunting regex can be sometimes.
DanTup commentedon May 20, 2017
Yeah, the problem is making sure that the correct
}is detecting. I did think it'd be possible (it's just Dart inside Dart!) but because you're actually inside quotes, it's not the same as just parsing Dart, since quotes will be escaped. I did spend some time on it but couldn't make it work :(Maybe in future VS Code will let us use dynamic highlight info and then we can swap from the regexes to the three provided by the Analyzer.
Skylled commentedon May 21, 2017
Okay, so Dart allows a string inside of the
${ }to use the same quote symbol as the outer string without issue. It seems to me the only character the regex needs to be watchful for are the brackets. The change would at least patch this issue, but I agree, one day the syntax highlighting needs to be re-written.The change would require
"variable.parameter.dart"being removed from Capture Group 3, since any arbitrary statement can be used inside of string interpolation.DanTup commentedon May 21, 2017
Thanks; I'll take a look at this when next working on it :)
Have you checked it with crud like this?
:D
Skylled commentedon May 21, 2017
The above example still fails to highlight correctly, for the reason you listed, regex's inability to tell which is the closing bracket. But the change doesn't fail any differently than before.
The above examples after the change.
DanTup commentedon May 25, 2017
I think we can consider this fixed with #310. I think there's still room for improvement, but I'm not sure we'll ever get all the way with the regex; we really need Code to implement microsoft/vscode#1967 (go vote for support! :-))
maxwell8888 commentedon May 3, 2021
Any update on this? For me, basic nesting like
String test = "${(() => 'one ${"two"}')()}";only highlights the inner most expression. You mentioned the need for microsoft/vscode#1967 which seems to have been implemented now.DanTup commentedon May 3, 2021
@maxwell8888 could you file a new issue about that? With LSP semantic tokens, I would expect (or at least like) for expressions to be coloured reasonably inside strings. The previous limitations were around the textmate grammar and LSP Semantic Tokens hands this off to the server where we don't need to rely on regex to identify these. Thanks!
maxwell8888 commentedon May 3, 2021
@DanTup As well as handling nested string interpolation, I'd also like to request the expression to be highlighted with multiple colours in the same way as normal code, whereas at the moment the entire expression is just highlighted with a single colour. Should I include this in the ticket or create a separate one? Thanks
DanTup commentedon May 3, 2021
@maxwell8888 I'm not sure how that differs from the earlier comment, though I think one issue for colouring interpolated expressions better is probably sufficient. Thanks!