mblode / vscode-twig-language

VS Code extension with snippets, syntax highlighting, hover, and formatting for Twig.
https://marketplace.visualstudio.com/items?itemName=mblode.twig-language
MIT License
42 stars 7 forks source link

Block Short Tag Duplicating #30

Closed wolfmoritz closed 5 years ago

wolfmoritz commented 5 years ago

In one of my templates I have an empty block short tag as a placeholder, to be extended in other templates:

  {% block head '' %}

After formatting, this tag is duplicated causing compile errors:

            {% block head '' %}
        {% block head '' %}
mblode commented 5 years ago

Oh that's really interesting, I've never seen this issue! What code would I need to duplicate the issue?

wolfmoritz commented 5 years ago

Here is repro case that I tested using VS Code version 1.34.0 on a Mac, and Twig Language extension 0.8.3:

<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  <title>
    {% if block('htmlTitle') is defined %}{{ block('htmlTitle') ~ ' - ' }}{% endif %}
    Administration
  </title>
  <link rel="stylesheet" href="...link-to-file">

  <script>
    let config = {
      dateFormat: "{{ site.settings.dateFormat }}",
      weekStart: {{ site.settings.dateFormat == 'mm/dd/yyyy' ? '0' : '1' }},
      csrfTokenName: "{{ site.csrf.name }}",
      csrfTokenValue: "{{ site.csrf.value }}",
      {% block jsConfig '' %}
    };
  </script>

  {% block head '' %}
</head>

<body>
  {% include "@admin/includes/_alert.html" %}

  <section id="default" class="content-wrapper">
    <div class="sidebar">
      {% block sidebar '' %}
    </div>

    <main role="main" class="content">
      {% block content '' %}
    </main>
  </section>

  <script src="...link-to-file"></script>

  {% block foot '' %}
</body>

</html>

When formatted, the {% block head '' %} on line 24 is duplicated on the next line. In testing the issue it seems to be related to the <script></script> block above, which also includes some Twig tags.

mblode commented 5 years ago

This has been fixed in the latest update 👍