onecentlin / laravel-blade-snippets-vscode

Laravel blade snippets and syntax highlight support for Visual Studio Code
MIT License
137 stars 38 forks source link

Formatting breaks object operator -> #150

Open sven-ahrens opened 2 years ago

sven-ahrens commented 2 years ago

Description

In my blade file I've multiple @checked directives that include a php variable accessing a method.

        <div>
            <label>
                <input
                    type="checkbox"
                    value="1"
                    name="myCheckbox"
                    @checked(collect($checkbox->getValues()->get('myCheckbox'))->contains('1'))
                {{ __('myCheckbox.title') }}
            </label>
        </div>

When I format this, it turns into:

        <div>
            <label>
                <input
                    type="checkbox"
                    value="1"
                    name="myCheckbox"
                    @checked(collect($checkbox-
                >getValues()->get('myCheckbox'))->contains('1'))
                {{ __('myCheckbox.title') }}
            </label>
        </div>

Expected behaviour

I'd assume that it does not break the object operator and keeps it on the same line.

So instead of this:

                    @checked(collect($checkbox-
                >getValues()->get('myCheckbox'))->contains('1'))

I'd expect this:

                    @checked(collect($checkbox->getValues()->get('myCheckbox'))->contains('1'))
onecentlin commented 2 years ago

@sven-ahrens Hi, can you check your format setting?

I have two blade formatter installed, either won't break the syntax

圖片

onecentlin commented 2 years ago

@sven-ahrens I noticed that your input tag does not close properly

sven-ahrens commented 2 years ago

@sven-ahrens I noticed that your input tag does not close properly

Hey, first of all: Thank you so much for replying.

You are right, my example is missing the closing tag but in my "real" code it doesn't. I checked that right now.

Bildschirmfoto 2022-03-04 um 17 02 23

and it turns into:

Bildschirmfoto 2022-03-04 um 17 02 51

Also I've selected your formatter:

Bildschirmfoto 2022-03-04 um 17 03 14

Bildschirmfoto 2022-03-04 um 17 03 24

Versions

sven-ahrens commented 2 years ago

I'm not sure if it breaks because of the force-expand-multiline but I've made an easier example outside of my project and this is leading to the same result:

<div>
    <label></label>
    <input type="radio" name="test" value="1" @checked($test->works()) />
</div>
<div>
    <label></label>
    <input
        type="radio"
        name="test"
        value="1"
        @checked($test-
    >works()) />
</div>
onecentlin commented 2 years ago

@sven-ahrens How about change force-expand-multiline to force-aligned. This may fit your needs.

sven-ahrens commented 2 years ago

@sven-ahrens How about change force-expand-multiline to force-aligned. This may fit your needs.

I'm coming from Vue background and I'm used to have them exactly like in my example.

I tried your version out and yes this works but it seems like it's a bug then, isnt it?

The formatter will break when having force-expand-multiline activated

onecentlin commented 2 years ago

@sven-ahrens Blade formatter is build based on HTML formatter. However, php syntax is not treat the same way as html. Since the new directive @check() comes out, it is not like simple key-value attributes that recognized by HTML formatter. I think that's why it treat php syntax -> the part > as close tag.