dart-lang / dart-syntax-highlight

Tools and documentation for how Dart code is formatted
BSD 3-Clause "New" or "Revised" License
22 stars 11 forks source link

Fix handling of closing braces + use meta.embedded.* for interpolated expressions in string #65

Closed DanTup closed 5 months ago

DanTup commented 5 months ago

Previously we would treat the first } in an interpolation expression as the end of the expression. So in:

var a = " ${ {} }";

The interpolation scope would end too soon. Additionally, VS Code's bracket matching used for colouring uses these scopes to know what's a string and what is new code inside a string, so without using meta.embedded the colours would be incorrect. Ideally I would have liked to handle that without changing the scope, but I've so far been unable to make it work with custom scopes. I've filed https://github.com/microsoft/vscode/issues/210053 but since other languages are using scope names like meta.embedded I think we should go ahead with it too (and we were already mapping to meta.embedded for semantic tokens).

Before/after with this change below:

Screenshot 2024-04-10 150556

I've split this into two commits. The first adds additional tests but keeps the grammar the same. The second commit has the fix, along with the changes to goldens for easier comparison of the impact of the changes.

DanTup commented 5 months ago

@devoncarew @jwren @parlough I'm not sure who has notifications or is best reviewing here - should I generally ping anyone for PRs here or will someone suitable pick them up anyway? Tnx!