Skip to content
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

Improve syntax highlighting for string interpolation #3318

Closed
maxwell8888 opened this issue May 3, 2021 · 2 comments
Closed

Improve syntax highlighting for string interpolation #3318

maxwell8888 opened this issue May 3, 2021 · 2 comments
Labels
in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server is enhancement
Milestone

Comments

@maxwell8888
Copy link

maxwell8888 commented May 3, 2021

Further to issue 305, currently, if additional string interpolation is used inside the expression, then only the inner most expression is highlighted, for example with "${(() => '1')()}" the entire expression is highlighted but if you add a nested string interpolation like "${(() => '1 ${2}')()}";, now only the 2 is highlighted. Instead all expressions should be highlighted.

Also, expression code should be highlighted in the same way as normal code. For example, currently with "${String.fromCharCode(36)}" the expression will be highlighted with a single colour. Instead the expression should be highlighted in the same way as String.fromCharCode(36), which uses different colours for the class, method, and integer.

It might also be more clear to highlight the $ and {}.

@maxwell8888 maxwell8888 changed the title Improve syntax highlighting nested string interpolation Improve syntax highlighting for string interpolation May 4, 2021
@DanTup DanTup added this to the v3.23.0 milestone May 7, 2021
@DanTup DanTup added in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server labels May 7, 2021
@DanTup
Copy link
Member

DanTup commented May 20, 2021

This appears to be caused by the underlying textmate grammar, as if I disable that things look consistent:

Screenshot 2021-05-20 at 10 01 32

With the grammar also enabled, we get:

Screenshot 2021-05-20 at 10 02 08

Fixing this may be tricky - if we remove strings entirely from the textmate grammar then they won't be coloured for the period between opening a file and getting semantic tokens, but otherwise semantic tokens don't seem to have a have a way to block the interpolated parts fro inheriting the string colouring.

@DanTup
Copy link
Member

DanTup commented May 20, 2021

I have a fix - though it requires changes in both the SDK and Dart-Code. The SDK changes are at https://dart-review.googlesource.com/c/sdk/+/200863/ which give us tokens for the interpolating parts of a string (that aren't already getting additional colouring) and the change here uses those tokens to reset the colouring (so it doesn't inherit the string colouring from the textmate grammar).

So you'll need both an updated Dart-Code and updated Dart/Flutter SDK before you see the fix so unless you're using a dev/master SDK you might not see the fix immediately with the next Dart-Code release. With the fixes, things look like this:

Screenshot 2021-05-20 at 11 49 43

@DanTup DanTup closed this as completed in 9ad72b5 May 20, 2021
dart-bot pushed a commit to dart-lang/sdk that referenced this issue May 20, 2021
This allows Dart-Code/Dart-Code#3318 to be fixed by giving clients something they can use to reset coloring and preventing inheriting from other highlighting they may apply.

Change-Id: I3f1ba2c15d64634b203064d1451fb4fef040eb60
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/200863
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server is enhancement
Projects
None yet
Development

No branches or pull requests

2 participants