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

Refactor Syntax #39

Merged
merged 23 commits into from
Oct 28, 2024
Merged

Conversation

deathaxe
Copy link
Contributor

@deathaxe deathaxe commented Oct 19, 2024

Resolves #33

This PR...

  1. introduces common meta.template.twig applied scope accross Text/HTML/JS/CSS
  2. adjusts snippet selectors
  3. adds some helper key bindings
  4. applies syntax specific toggle comment rules to apply Twig comments by default but retain original syntax's block comment as variant 2.
  5. renames contexts to use hyphens as subword-separators
  6. reorders contexts following lessons learned from Go, Jinja and other template syntaxes
  7. apply meta.embedded to tags and source.twig to their content.
  8. fix various smaller highlighting bugs
  9. merges html specific rules into twig indentation rules

Note: This PR requires ST4152+, most likely due to CSS.

To support older releases we'd need to vendor CSS.

Refactor folder structure after the scheme of Jinja2 package.
This commit...

1. introduces common `meta.template.twig` applied scope accross Text/HTML/JS/CSS
2. adjusts snippet selectors
3. adds some helper key bindings
4. applies syntax specific toggle comment rules to apply Twig comments
   by default but retain original syntax's block comment as variant 2.
5. renames contexts to use hyphens as subword-separators
6. reorders contexts following lessons learned from Jinja and other template
   syntaxes
7. apply `meta.embedded` to tags and `source.twig` to their content.
8. fix various smaller highlighting bugs
@deathaxe deathaxe force-pushed the feat/refactor-syntax branch from a0ad157 to ca98457 Compare October 19, 2024 14:36
A formatting change and removal of some default operator/operand keys.
This commit enables to test embedded CSS, JS, JSON code in Twig templates.

Without it, all test assertions cause illegal syntax highlighting
in script or style tags.

Note: It drops some tests for leading `{{` and `{%` due to assertion punctuation
now requiring 2 chars, but those are most often redundant anyway.
- reorder style tag context
- add some backward compatibility fixes
Supported by Twig 3.15+
Adds snippets for individual tags so typing a tag name and hitting tab key
expands to an individual tag enclosed in `{% ... %}`:

   if| =>  {% if | %}
   embed| =>  {% embed | %}

Triggers of existing block snippets are prefixed with `b` to avoid ambiguities
with tag-snippets. Otherwise it would be unclear whether blocks or tags are
expanded and/or completion panel was displayed requiring arrow key navigation.

   bif|

   {% if conditon %}
      |
   {% endif %}

Reorganize snippets in individual sub-directories in case someone wants to
disable individual ones based on type.
@deathaxe deathaxe force-pushed the feat/refactor-syntax branch from ed7dd46 to 5020129 Compare October 20, 2024 13:07
Twig tags within quoted strings can contain same sort of quotes.

This requires another strategy of handling embedded code blocks
especially in inline event and style attributes.

Solution is borrowed from PHP.
@deathaxe deathaxe force-pushed the feat/refactor-syntax branch from af35fc3 to db2d435 Compare October 20, 2024 14:22
Instead of adding rules to pop on quotes to each context,
this commit just replaces relevant string contexts of JS/CSS
to make sure to pop contexts properly.

This reduces compiled syntax cache from 820kB to 610kB.
This commit fixes Twig statement tags and comments being scoped
meta.attribute-with-value by accident.
Add some info about changed snippets.

Snippets are basically aligned with Jinja2.
@willrowe
Copy link
Contributor

This looks great, I pulled down the branch, did some cursory testing, and it appears to fix a lot of the issues I was seeing. Thanks for putting in all the work to update the syntax @deathaxe!

@deathaxe
Copy link
Contributor Author

Feel free to post any issues you encounter.

@willrowe
Copy link
Contributor

  1. When adding curly braces {{}} inside of quotes like "{{}}", it doesn't add spaces like it does when not inside quotes: {{ }}.
  2. When pressing return in between an opening and closing statements it does not insert a new line and indent as expected.

This commit enables key bindings related to tag creation also
in strings and comments.

Before:

   <p class="my-{|}">  => <p class="my-{{|}}">

After
   <p class="my-{|}">  => <p class="my-{{ | }}">
@willrowe
Copy link
Contributor

I just pulled down the latest commits and both the issues I found are working now.

@deathaxe
Copy link
Contributor Author

@braver: I think this PR is ready for release.

Required channel changes are prepared at wbond/package_control_channel#8995

With a look at amount of changes it's probably worth a new major version.

@braver
Copy link
Collaborator

braver commented Oct 28, 2024

Looks good! I'll be using it on and off the coming days, perhaps I'll run into something, but this looks really solid. Let's 🚀

@braver braver merged commit aeb6874 into Sublime-Instincts:master Oct 28, 2024
4 checks passed
@deathaxe deathaxe deleted the feat/refactor-syntax branch October 28, 2024 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Work better with Tailwind classes and custom values
3 participants