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

Fix meta.embedded vs. meta.interpolation #34

Merged
merged 5 commits into from
Dec 17, 2024

Conversation

deathaxe
Copy link
Contributor

@deathaxe deathaxe commented Dec 17, 2024

This PR...

fixes #33

  1. adds support for {{ ... }} interpolation in attribute values, quoted strings and CDATA content tags, including inline styles or code of possible <style> tags.
  2. scopes {{ ... }} meta.embedded.expression to distinguish from control flow statements.
  3. adds meta.embedded.statement to control flow statements such as @if, @for, etc.
  4. scopes whole component content meta.template.ngx to align with Jinja2, Twig, Vue and others.

Note: We could also scope {{...}} meta.interpolation as those actually inject expression evaluation results into output text. However it is not easy in all template languages to make that distinction. Hence in favor of consistent scoping meta.embedded.expression is used. It also allows simpler snippet/completion selectors targeting both, statements and interpolation via meta.template.ngx meta.embedded. Jinja2, Twig, Svelte already use that schema as well.

This commit adds `.expression` sub-scope name to distinguish embedded
interpolation expressions from control flow statements.
This commit adds new `ng-string-interpolations` context, which in addition to
`ng-string-interpolations` to clear `string` scope in quoted strings.

This ensures interpolated expressions are
1. treated as normal source instead of applying special string rules
2. correctly highlighted avoiding unmatched tokens looking like strings.

An inherited special purpose CSS syntax is added to support Mustache tags
in inline styles.
This commit overrides HTML's default `style-css-content` to use CSS (for Ngx)
syntax between `<style>` tags, enabling interpolation support.

Note: Maybe not so relevant in templates, but in case someone wants to use it.
This commit scopes all control flow statements
`meta.embedded.statement source.ngx.embedded.html`.
to also apply proper `source.ngx` to angular expressions.
This commit scopes whole document `meta.template`.

Various template syntaxes make use of it to be able to use simpler snippet or
completion selectors across all supported languages (e.g.: CSS/JS/HTML).
@princemaple
Copy link
Owner

👍 Can't find any problem in my relatively large projects.

@princemaple princemaple merged commit 8945ce0 into princemaple:master Dec 17, 2024
1 check passed
@deathaxe deathaxe deleted the fix/interpolations branch December 18, 2024 08:45
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.

Interpolation within quoted strings or attribute values is not highlighted
2 participants