Stillat / vscode-antlers-language-server

Provides rich language features for Statamic's Antlers templating language, including code completions, syntax highlighting, and more.
https://antlers.dev
MIT License
36 stars 3 forks source link

Code is being copy/pasted on save with formatOnSave set to true #76

Closed lauritsen closed 1 year ago

lauritsen commented 1 year ago

Describe the bug Code is being copied from a script tag and pasted inside an if clause.

Impacted Products Which Antlers Toolbox products does this bug apply to?

Versions and Other Plugins/Extensions

Antlers Toolbox v2.6.7 Prettier - Code formatter v10.1.0 (issue persists when I disable prettier)

settings.json

  "[html]": {
    "editor.defaultFormatter": "stillat-llc.vscode-antlers",
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
        "source.fixAll.eslint": true
    },
    "editor.quickSuggestions": {
        "strings": true
    },
  }

To Reproduce Create a new antlers file e.g. _test.antlers.html with the contents below

<script type="application/json">
    {{ if something }}
    {{ /if }}
</script>

{{ if somethingElse }}
    <script></script>
{{ /if }} 

Saving the file reformats, but also duplicates code resulting in

<script type="application/json">
    {{ if something }}
    {{ /if }}
</script>
{{ if somethingElse }}
    {{ if something }}
    {{ /if }}
    <script></script>
{{ /if }}

where it for some reason copies the content of the first <script> tag and pastes it inside the {{ somethingElse }} if statement.

If I try to use Alt K + F to format, I get an error saying Antlers Toolbox cannot format HTML (Statamic Antlers)

image

Expected behavior That it only formats the file.

If submitting a formatting bug, please include the template contents below as well as an attachment

_test.antlers.txt

Please rename to .html as I could not upload an html file here.

JohnathonKoster commented 1 year ago

Code duplication in <script> tags has been resolved in the following releases:

lauritsen commented 1 year ago

Hi @JohnathonKoster Thanks for the fix! I do experience some other funny behavior after the update. In my simple test file, when saving it the if statement within the script tag get replaced by a random indentifier e.g.

<script type="application/json">
    < agyfprw4kffub4a >

        <
        /agyfprw4kffub4a>
</script>
{{ if somethingElse }}
    <script></script>
{{ /if }}

In my regular file, where I first saw the original bug, it now indents the contents and the closing tag of the script on every format leading to excessive indentation.

JohnathonKoster commented 1 year ago

I'm not unable to reproduce either issue with the latest prettier or formatter build (reformatting the same input over 100 times) 🤔

Would you be able to be able to share you prettier configuration, as well as the original file that is experiencing the excessive indentation bug (if you want to keep it private, you can email it to john@stillat.com).

Thanks!

lauritsen commented 11 months ago

@JohnathonKoster sorry for the radio silence... It happens to me in this file: https://github.com/studio1902/statamic-peak-seo/blob/c29efae7c2d3e5efdcb0e4a05a57d2dfa6414296/resources/views/snippets/_seo.antlers.html Lines 81-99, 107-121, 167-175 keeps getting indented on each saving of the file.