Skip to content
This repository has been archived by the owner. It is now read-only.

Prevent string styling from bleeding through interpolations #47

Merged
merged 2 commits into from Jul 21, 2018

Conversation

Projects
None yet
2 participants
@maxbrunsfeld
Copy link
Contributor

maxbrunsfeld commented Jul 16, 2018

Description of the Change

Currently, interpolated code inside of strings is highlighted as a string. Not the green color on the word three below:

interpolation-styling-before

This PR explicitly resets the font color when a scope with the source class appears inside of a string. This works both with the TextMate highlighting and, on Atom master, with Tree-sitter highlighting as well:

interpolation-styling-after

Alternate Designs

We could somehow cause the string scope to actually end at the start of the interpolation and begin again after the interpolation. I think this would be more difficult than what I've done here, with both TextMate and Tree-sitter highlighting.

Benefits

String interpolations are easier to read.

Possible Drawbacks

In some languages, interpolations might not be assigned the source class. It seems reasonable that we could change the grammars to always provide that class though.

Applicable Issues

atom/language-ruby#147

/cc @simurai is @syntax-fg the best variable to use for this purpose?

@simurai

This comment has been minimized.

Copy link
Member

simurai commented Jul 17, 2018

/cc @simurai is @syntax-fg the best variable to use for this purpose?

@mono-1 could also be used. It's exactly the same as @syntax-fg, but maybe a bit more consistent since the "mono" variables are used in other places of the syntax highlighting.

Anyways, feel free to merge it either way. 😄 Same for atom/one-dark-syntax#112.

In some languages, interpolations might not be assigned the source class.

The TextMate naming_conventions lists: string.interpolated. Could that be used? Although not sure how many themes/languages support it. For example this theme doesn't either.

@maxbrunsfeld

This comment has been minimized.

Copy link
Contributor Author

maxbrunsfeld commented Jul 19, 2018

The TextMate naming_conventions lists: string.interpolated

Yeah, that would make sense. Unfortunately, the existing grammars don't seem to use those scopes. But this suggestion did prompt me to double check what scopes they all do use, and I realized that they don't all use the source scope here either. Ruby and JavaScript do, but Python and TypeScript don't. They do however all use the meta.embedded scope. So I think I'll update the PR to target that scope.

@simurai

This comment has been minimized.

Copy link
Member

simurai commented Jul 20, 2018

They do however all use the meta.embedded scope.

Ha.. interesting. Just in case, we can always style certain languages separately if they don't follow a convention that most others use.

Target string interpolations using 'embedded' scope
Also, refer to the base font color as @mono-1

@maxbrunsfeld maxbrunsfeld merged commit 2333852 into master Jul 21, 2018

@maxbrunsfeld maxbrunsfeld deleted the mb-string-interpolations branch Jul 21, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.