Skip to content

Remove $ as possible character in simple interpolated variable name #74

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

Merged
merged 3 commits into from
Jan 27, 2020

Conversation

kiendang
Copy link
Contributor

Fix #72

Before
Screen Shot 2020-01-11 at 1 10 59 PM

After
Screen Shot 2020-01-11 at 1 12 36 PM

// ^ punctuation.definition.string.begin.scala
// ^ punctuation.definition.template-expression.begin.scala
// ^^ punctuation.definition.template-expression.begin.scala
// ^^^^^^^^^^^^ punctuation.definition.template-expression.scala
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part should be parsed as an arbitrary Scala block. For example, it could contain definitions

val a = 4; foo(a)
s"$safeTagMarker${val a = 4; foo(a)}$safeTagMarker"

Both val a = 4; foo(a) should have the same highlighting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right I can see the foos have different highlighting here.
Screen Shot 2020-01-27 at 1 04 10 PM

The issue is val a = 4; foo(a) has scope punctuation.definition.template-expression.scala inside string interpolation and since ; foo(a) has no scope it was highlighted the same way as ${ and } (punctuation.definition.template-expression.begin.scala and punctuation.definition.template-expression.end.scala).

I just pushed another commit to fix this. Basically replace punctuation.definition.template-expression.scala with meta.embedded.line.scala (Inspiration from typescript and ruby tm highlighting). More details in the commit message which I'm just gonna paste here.

Add scopes meta.template.expression.scala and meta.embedded.line.scala
Eg. In s"${val a = 4; foo(a)}", ${val a = 4; foo(a)} will have meta.template.expression.scala while val a = 4; foo(a) will have meta.embedded.line.scala.
Earlier val a = 4; foo(a) was under punctuation.definition.template-expression. This makes things without a scope like ; foo(a) highlighted differently inside string interpolation (they will have the same highlighting as ${ and }) vs outside, which is not desirable.

Visual tests

Before
Screen Shot 2020-01-27 at 1 04 10 PM
After
Screen Shot 2020-01-27 at 12 40 36 PM

Before
Screen Shot 2020-01-27 at 11 57 27 AM
After
Screen Shot 2020-01-27 at 12 40 42 PM

Add scopes `meta.template.expression.scala` and `meta.embedded.line.scala`
Eg. In `s"${val a = 4; foo(a)}"`, `${val a = 4; foo(a)}` will have `meta.template.expression.scala` while `val a = 4; foo(a)` will have `meta.embedded.line.scala`.
Earlier `val a = 4; foo(a)` was under `punctuation.definition.template-expression`. This makes things without a scope like `; foo(a)` highlighted differently inside string interpolation (they will have the same highlighting as `${` and `}`) vs outside, which is not desireable.
@nicolasstucki nicolasstucki merged commit 10e15a5 into scala:master Jan 27, 2020
@nicolasstucki
Copy link
Contributor

Thank you @kiendang

@kiendang kiendang deleted the dollar-sign branch January 27, 2020 07:01
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

Successfully merging this pull request may close these issues.

Wrong highlighting in string interpolators
2 participants