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

Antlers Formatters deletes code parts when formatting #80

Closed exophunk closed 8 months ago

exophunk commented 8 months ago

Describe the bug I've set up vscode-antlers-language-server as my default formatter for Antlers. I also have formatOnSave enabled. I keep running into issues with misformated code when doing something a bit more complicated, but the main issue is that the formatter sometimes removes large batches of code and I don't quite understand yet why.

Example 1:

The following: The formatter sometimes just deletes parts of antlers code:

{{ title.attributes.class(['border']) }}

when formatting it is changed to:

{{ (['border']) }}

the part title.attributes.class just gets deleted.

Example 2 When commenting out template parts that contain antlers tags, the formatter just wipes all code below, basically makes it impossible to comment out template parts while developing.

This

<div>
    <select wire:model.live="beneficiary">
        {{ beneficiaries }}
            <option wire:key="{{ value }}" value="{{ value }}">{{ trans:strings.checkout.beneficiaries.{value} }}</option>
        {{ /beneficiaries }}
    </select>
</div>

<div>... rest of template</div>

is formatted to this:

<div>
    {{#
        <select wire:model.live="beneficiary">
            {{ beneficiaries }}
                <option wire:key="{{ value }}" value="{{ value }}">{{ trans:strings.checkout.beneficiaries.{value} }}</option>
            {{ /beneficiaries }}
        </select>
    #}}

The following just disappears! (and everything below)

</div>

<div>... rest of template</div>

Everything in my template file below the commented part just gets removed completely. Or sometimes only parts of it, breaking the html.

Impacted Products

Versions and Other Plugins/Extensions Antlers Toolbox v2.6.11

Configurations:

{
    "settings": {
        "[html]": {
            "editor.defaultFormatter": "stillat-llc.vscode-antlers",
            "editor.formatOnSave": true,

        },
        "antlersLanguageServer.languageVersion": "runtime",
        "antlersLanguageServer.showGeneralSnippetCompletions": false,
        "antlersOverrideHtmlComments": true,
        "html.format.indentHandlebars": true,
        "html.format.maxPreserveNewLines": 2,
        "html.format.wrapLineLength": 160,
        "html.format.wrapAttributes": "preserve",
    },
}

doesn't really matter though, same happens when using default settings

To Reproduce Use one of the expressions above and format file with antlers formatter

Expected behavior Should not delete code parts and should be able to handle comments

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

JohnathonKoster commented 8 months ago

Thanks for the report (and for uploading the original file as an attachment) - I'll take a look at this this week and work on getting these issues resolved as soon as I can!

JohnathonKoster commented 8 months ago

Resolved in the following versions:

exophunk commented 8 months ago

wow that was fast! thank you very much for the fix! works perfectly